简介
obproxy 属于OceanBase的代理,生产环境中 OceanBase 数据库的数据 会以 多副本的形式 存放在各个 OBServer 节点上,obproxy 接收用户发出的 SQL 请求,并将 SQL 请求转发至最佳目标 OBServer 节点,最后将执行结果返回给用户,该工具一般部署在observer所在的服务器上。
查看obproxy信息(查看进程)
可以看出当前只有一台 obproxy, 端口号为2883,目录在 /opt/myoceanbase/obproxy
[root@rac1 ~]# ps -ef | grep obproxy root 7780 1 0 May16 ? 00:44:14 bash /opt/myoceanbase/obproxy/obproxyd.sh /opt/myoceanbase/obproxy 10.0.0.197 2883 daemon root 7798 1 4 May16 ? 10:21:01 /opt/myoceanbase/obproxy/bin/obproxy --listen_port 2883 root 9646 23753 0 22:49 pts/5 00:00:00 grep --color=auto obproxy [root@rac1 ~]#
安装目录
通过查看 obproxy 进程运行状态得出 obproxy 安装目录是 /opt/myoceanbase/obproxy
进入安装目录
可以看到在安装目录下 存在 obproxy 自身的一些文件和目录信息: 日志目录log, 进程id目录run, 配置目录etc, 守护进程 obproxyd.sh
[root@rac1 ~]# cd /opt/myoceanbase/obproxy [root@rac1 obproxy]# ll total 8 drwxr-xr-x 2 root root 21 May 16 15:50 bin drwxr-xr-x 2 root root 6 May 16 15:51 control-config drwxr-xr-x 2 root root 87 May 16 15:52 etc drwxr-xr-x 2 root root 6 May 16 15:50 lib drwxr-xr-x 2 root root 4096 May 24 20:55 log -rw-r--r-- 1 root root 910 May 16 15:52 obproxyd.sh drwxr-xr-x 2 root root 77 May 16 15:52 run drwxr-xr-x 2 root root 6 May 16 15:51 sharding-config [root@rac1 obproxy]# [root@rac1 obproxy]# [root@rac1 obproxy]# [root@rac1 obproxy]# cd log/ [root@rac1 log]# ll total 1070184 -rw-r--r-- 1 root root 0 May 16 15:51 obproxy_client.log -rw-r--r-- 1 root root 0 May 16 15:51 obproxy_config.log -rw-r--r-- 1 root root 216074 May 25 20:44 obproxy_diagnosis.log -rw-r--r-- 1 root root 12666499 May 26 22:53 obproxy_digest.log -rw-r--r-- 1 root root 5788538 May 26 22:49 obproxy_error.log -rw-r--r-- 1 root root 0 May 16 15:51 obproxy_limit.log -rw-r--r-- 1 root root 133943000 May 26 22:53 obproxy.log -rw-r--r-- 1 root root 268435584 May 21 21:00 obproxy.log.20240521210000 -rw-r--r-- 1 root root 268435619 May 24 04:54 obproxy.log.20240524045423 -rw-r--r-- 1 root root 268435458 May 24 20:55 obproxy.log.20240524205514 -rw-r--r-- 1 root root 11980562 May 26 22:53 obproxy.log.wf -rw-r--r-- 1 root root 24386318 May 21 21:00 obproxy.log.wf.20240521210000 -rw-r--r-- 1 root root 17694250 May 24 04:54 obproxy.log.wf.20240524045423 -rw-r--r-- 1 root root 13785772 May 24 20:55 obproxy.log.wf.20240524205514 -rw-r--r-- 1 root root 0 May 16 15:51 obproxy_pool.log -rw-r--r-- 1 root root 0 May 16 15:51 obproxy_pool_stat.log -rw-r--r-- 1 root root 4657094 May 26 22:53 obproxy_slow.log -rw-r--r-- 1 root root 15866350 May 26 22:52 obproxy_stat.log -rw-r--r-- 1 root root 455937 May 26 16:44 obproxy_trace.log -rw-r--r-- 1 root root 32840682 May 26 22:52 obproxy_xflush.log [root@rac1 log]# [root@rac1 log]# cd .. [root@rac1 obproxy]# cd run/ [root@rac1 run]# ll total 8 -rw-r--r-- 1 root root 5 May 16 15:52 obproxy-10.0.0.197-2883.pid -rw-r--r-- 1 root root 5 May 16 15:52 obproxyd-10.0.0.197-2883.pid [root@rac1 run]#
obproxyd.sh
该文件位于 obproxy 安装目录下,负责启停 obproxy,并检查obproxy运行状态,当obproxy 挂掉,obproxyd.sh 会负责将其拉起来,属于 obproxy 的守护进程
日志
obproxy 日志 保存 obproxy 的运行信息,根据实际需求查看相关日志,也可以通过obproxy日志查询慢SQL的基础信息
[root@rac1 log]# ll total 1071660 -rw-r--r-- 1 root root 0 May 16 15:51 obproxy_client.log -rw-r--r-- 1 root root 0 May 16 15:51 obproxy_config.log -rw-r--r-- 1 root root 216074 May 25 20:44 obproxy_diagnosis.log -rw-r--r-- 1 root root 12672412 May 26 23:07 obproxy_digest.log -rw-r--r-- 1 root root 5788538 May 26 22:49 obproxy_error.log -rw-r--r-- 1 root root 0 May 16 15:51 obproxy_limit.log -rw-r--r-- 1 root root 134784335 May 26 23:07 obproxy.log -rw-r--r-- 1 root root 268435584 May 21 21:00 obproxy.log.20240521210000 -rw-r--r-- 1 root root 268435619 May 24 04:54 obproxy.log.20240524045423 -rw-r--r-- 1 root root 268435458 May 24 20:55 obproxy.log.20240524205514 -rw-r--r-- 1 root root 12032012 May 26 23:07 obproxy.log.wf -rw-r--r-- 1 root root 24386318 May 21 21:00 obproxy.log.wf.20240521210000 -rw-r--r-- 1 root root 17694250 May 24 04:54 obproxy.log.wf.20240524045423 -rw-r--r-- 1 root root 13785772 May 24 20:55 obproxy.log.wf.20240524205514 -rw-r--r-- 1 root root 0 May 16 15:51 obproxy_pool.log -rw-r--r-- 1 root root 0 May 16 15:51 obproxy_pool_stat.log -rw-r--r-- 1 root root 4661234 May 26 23:07 obproxy_slow.log -rw-r--r-- 1 root root 15894775 May 26 23:06 obproxy_stat.log -rw-r--r-- 1 root root 455937 May 26 16:44 obproxy_trace.log -rw-r--r-- 1 root root 32868123 May 26 23:07 obproxy_xflush.log [root@rac1 log]# [root@rac1 log]# [root@rac1 log]# [root@rac1 log]# pwd /opt/myoceanbase/obproxy/log [root@rac1 log]# grep -i 'slow query' obproxy.log.20240521210000
使用 obproxy 登录 OB
[root@rac1 log]# obclient -h10.0.0.197 -P2883 -uroot@sys#myoceanbase -p'aaAA11__' -Doceanbase -A -c; Welcome to the OceanBase. Commands end with ; or \g. Your OceanBase connection id is 526837 Server version: OceanBase_CE 4.2.1.0 (r100000102023092807-7b0f43693565654bb1d7343f728bc2013dfff959) (Built Sep 28 2023 07:25:28)Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.obclient [oceanbase]>
注意:使用 obproxy 登录OB时,用户名填写方式 必须为 用户名@租户名#集群名,登陆端口使用 obproxy 端口
查看 obproxy 参数
查看全部参数
obclient [oceanbase]> show proxyconfig
查看某个参数(日志清理间隔)
可以看到 当前 日志文件清理任务 的 间隔时间 为1分钟,取值范围为 5秒 至 30天
obclient [oceanbase]> show proxyconfig like 'log_cleanup_interval'; +----------------------+-------+--------------------------------------------------------------------------+-------------+---------------+ | name | value | info | need_reboot | visible_level | +----------------------+-------+--------------------------------------------------------------------------+-------------+---------------+ | log_cleanup_interval | 1m | log file clean up task schedule interval, set 1 day or longer, [5s, 30d] | false | USER | +----------------------+-------+--------------------------------------------------------------------------+-------------+---------------+ 1 row in set (0.002 sec)
修改某个 obproxy 参数(日志清理间隔)
修改日志文件清理任务 的 间隔时间 为1分钟
obclient [oceanbase]> alter proxyconfig set log_cleanup_interval = '2m'; Query OK, 0 rows affected (0.017 sec)obclient [oceanbase]> obclient [oceanbase]> show proxyconfig like 'log_cleanup_interval'; +----------------------+-------+--------------------------------------------------------------------------+-------------+---------------+ | name | value | info | need_reboot | visible_level | +----------------------+-------+--------------------------------------------------------------------------+-------------+---------------+ | log_cleanup_interval | 2m | log file clean up task schedule interval, set 1 day or longer, [5s, 30d] | false | USER | +----------------------+-------+--------------------------------------------------------------------------+-------------+---------------+ 1 row in set (0.008 sec)obclient [oceanbase]>
obproxy重启
使用obd重启
可以使用 -s 指定 特定节点 的obproxy 重启
[admin@server070 oceanbase-ce]$ obd cluster restart demo -c obproxy-ce -s 127.0.0.1 Get local repositories and plugins ok Load cluster param plugin ok Open ssh connection ok Cluster status check ok Check before start obproxy ok Stop obproxy ok Start obproxy ok obproxy program health check ok Connect to obproxy ok +---------------------------------------------+ | obproxy | +-----------+------+-----------------+--------+ | ip | port | prometheus_port | status | +-----------+------+-----------------+--------+ | 127.0.0.1 | 2883 | 2884 | active | +-----------+------+-----------------+--------+ obclient -h127.0.0.1 -P2883 -uroot -Doceanbase -Asucceed Trace ID: ec2765e0-ece1-11ee-934b-000c2910d46f If you want to view detailed obd logs, please run: obd display-trace ec2765e0-ece1-11ee-934b-000c2910d46f [admin@server070 oceanbase-ce]$ [admin@server070 oceanbase-ce]$ [admin@server070 oceanbase-ce]$
手动重启
将 obporxy-ce进程 和 obproxyd守护进程 杀掉
[admin@server070 ~]$ ps -ef|grep obproxy |grep -v grep admin 15091 1 0 17:02 pts/0 00:00:01 bash /home/admin/obproxy-ce/obproxyd.sh /home/admin/obproxy-ce 127.0.0.1 2883 daemon admin 15110 1 1 17:02 ? 00:00:39 /home/admin/obproxy-ce/bin/obproxy --listen_port 2883 [admin@server070 ~]$ [admin@server070 ~]$ [admin@server070 ~]$ [admin@server070 ~]$ [admin@server070 ~]$ kill 15091 [admin@server070 ~]$ [admin@server070 ~]$ [admin@server070 ~]$ [admin@server070 ~]$ kill 15110 [admin@server070 ~]$ [admin@server070 ~]$
启动 obproxy 节点
[admin@server070 ~]$ cd /home/admin/obproxy-ce/ [admin@server070 obproxy-ce]$ ./bin/obproxy [admin@server070 obproxy-ce]$ [admin@server070 obproxy-ce]$ chmod 733 obproxyd.sh [admin@server070 obproxy-ce]$ [admin@server070 obproxy-ce]$ [admin@server070 obproxy-ce]$ [admin@server070 obproxy-ce]$ sh obproxyd.sh /home/admin/obproxy-ce 127.0.0.1 2883 [admin@server070 obproxy-ce]$ [admin@server070 obproxy-ce]$ [admin@server070 obproxy-ce]$ ps -ef | grep obproxy | grep -v grep admin 27105 1 2 17:37 ? 00:00:01 ./bin/obproxy [admin@server070 obproxy-ce]$ ps -ef | grep obproxy admin 27105 1 2 17:37 ? 00:00:02 ./bin/obproxy admin 27451 15200 0 17:39 pts/0 00:00:00 grep --color=auto obproxy [admin@server070 obproxy-ce]$ [admin@server070 obproxy-ce]$
验证启动成功
通过 obproxy 可以登录集群
[admin@server070 oceanbase-ce]$ obclient -h127.0.0.1 -P2883 -uroot@obmysql -Doceanbase -c -A -paaAA11__ Welcome to the OceanBase. Commands end with ; or \g. Your OceanBase connection id is 1 Server version: OceanBase_CE 4.2.2.0 (r100000192024011915-fac02c6690de9ff9f9f96c0bdf86ffe39ae0d7e7) (Built Jan 19 2024 15:14:05)Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.obclient [oceanbase]> obclient [oceanbase]>