作者:贲绍华
爱可生研发中心工程师,负责项目的需求与维护工作。其他身份:柯基铲屎官。
本文来源:原创投稿
*爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。
一、引言:
关于OBproxy的功能与介绍就不再详细说明了,从3.1.3开始,OB提供了config server的源码作为tool在开源仓库内。
令社区版也能使用一些OCP上才有的功能。这样就能方便的通过OBserver的自动更新configURL来实现root service的动态刷新了(之前需要重启proxy进程才能刷新root service list配置,且不支持代理多集群)。
二、前期准备
- golang 1.17或以上版本(用于编译运行Config server)
- 部署一套OB数据库集群(本文使用版本为:oceanbase-ce 3.1.4)
- oceanbase-obproxy-ce-3.2.3.5-2.el7.x86_64.rpm
三、部署Config server
3.1 下载Oceanbase源码
git clone https://github.com/oceanbase/oceanbase.git
进入oceanbase/tools/ob-configserver目录,这里就是我们需要的东西。
3.2 编辑./etc/config.yaml配置文件
需要修改的部分有server配置、VIP配置、数据源配置:
- server.address: web服务运行后绑定的IP与端口
- vip.address: VIP地址,注:如果为单节点,此处应填写OBproxy与OBserver可以访问到的IP地址(127的话如果不在同一台主机是不行的)
- storage.connection_url: 这里使用mysql作为数据源进行存储,数据表会自动进行创建,但库如果不存在会导致启动失败
## server config
server:
address: "0.0.0.0:8080"
run_dir: run
## vip config, configserver will generate url with vip address and port and return it to the client
## if you don't hava a vip, use the server address and port is ok, but do not use some random value that can't be connected
vip:
address: "127.0.0.1"
port: 8080
## storage config
storage:
## database type, support sqlite3 or mysql
database_type: mysql
# database_type: sqlite3
## database connection config, should match database_type above
connection_url: "user:password@tcp(127.0.0.1:3306)/oceanbase?parseTime=true"
# connection_url: "/tmp/data.db?cache=shared&_fk=1"
# connection_url: "file:ent?mode=memory&cache=shared&_fk=1"
3.3 编译二进制文件:
# 默认的build方法编译的是debug版本,如果需要release版本请使用:make build-release
root@ubuntu: make build
Build with debug flags
GO111MODULE=on GOPROXY=https://mirrors.aliyun.com/goproxy/,direct go build -p 2 -race -ldflags '-X "github.com/oceanbase/configserver/config.Version=1.0" -X "github.com/oceanbase/configserver/config.BuildTimestamp=2022-12-21 06:07:53" -X "github.com/oceanbase/configserver/config.GitBranch=master" -X "github.com/oceanbase/configserver/config.GitHash=873c59f5fe834d87fc0252f4522281f3e4e6ceea" -X "github.com/oceanbase/configserver/config.Mode=debug" -X "github.com/oceanbase/configserver/config.CurProcess=ob-configserver"' -o bin/ob-configserver cmd/main.go
3.4 启动config server
root@ubuntu: nohup ./bin/ob-configserver -c ./etc/config.yaml &
启动后检查log日志或数据库ob_clusters表是否已完成初始化,如果有相关信息则表示服务启动成功了
四、为OB server集群注册Config server
4.1 登录OB server,初始化proxyro账号
$ obclient -h172.20.134.2 -uroot@sys -P2881 -p -c -A oceanbase
Enter password:
# 单引号内为账号密码,请自行修改
obclient> CREATE USER proxyro IDENTIFIED BY '123456';
Query OK, 0 rows affected
obclient> GRANT SELECT ON *.* TO proxyro;5
Query OK, 0 rows affected
obclient> SHOW GRANTS FOR proxyro;
+----------------------------------+
| Grants for proxyro@% |
+----------------------------------+
| GRANT SELECT ON *.* TO 'proxyro' |
+----------------------------------+
1 row in set (0.067 sec)
4.2 配置ConfigURL
# 集群名需要调整为OB server的集群名称
obclient [oceanbase]> ALTER SYSTEM SET obconfig_url = 'http://192.168.2.42:8088/services?Action=ObRootServiceInfo&ObCluster=obcluster';
Query OK, 0 rows affected (0.078 sec)
4.3 刷新config server配置
使用手动POST API接口的形式注册比较麻烦,在OB server侧,会主动更新config server内的配置信息,触发方式如下,当配置了config URL之后:
1.默认情况下每10分钟会进行一次上报
2.当root service list发生变更时会触发上报(新增、删除、切换leader等)
# 注:双引号内调整为当前角色为follower的root service进行切换(如果使用leader执行如下语句并不会触发更新上报)
obclient [oceanbase]> ALTER SYSTEM SWITCH ROOTSERVICE LEADER server '172.20.134.2:2882';
Query OK, 0 rows affected (0.004 sec)
4.4 检查是否上报成功
进入MySQL内检查集群数据是否已写入ob_clusters表,如果是则表示注册完成
五、部署OBproxy
5.1 创建admin用户与用户组(在非admin用户下运行进程可能会出现一些意料之外的问题)
# 创建admin用户组
sh-4.2# groupadd --force admin
# 检查admin用户是否存在
sh-4.2# id admin
id: admin: no such user
# 如果不存在,则创建并加入admin用户组
sh-4.2# useradd -M -g admin admin
sh-4.2# id admin
uid=5701(admin) gid=5701(admin) groups=5701(admin)
5.2 安装RPM包
sh-4.2# rpm -ivh --force oceanbase-obproxy-ce-3.2.3.5-2.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:obproxy-ce-3.2.3.5-2.el7 ################################# [100%] 下载完成后执行
5.3 启动proxy进程
必须要指定的参数如下:
- obproxy_config_server_url (configURL参数,缺少的话会导致无法连接OBserver)
- observer_sys_password(OBserver内的proxyro账号的密码,用于proxy与OBserver之间通信使用,启动时缺少的话可以进入proxy内重新修改,但不指定的话会连接时提示密码错误)
bash-4.2$ cd admin/obproxy-3.2.3.5/
bash-4.2$ su admin
bash-4.2$ ./bin/obproxy -p 2883 -n mycluster -o "prometheus_sync_interval=1s,obproxy_config_server_url=http://172.20.134.1:8088/services?Action=GetObProxyConfig&ObproxyClusterName=mycluster,prometheus_listen_port=2884,enable_metadb_used=false,skip_proxy_sys_private_check=true,log_dir_size_threshold=10G,proxy_mem_limited=2G,enable_proxy_scramble=true,enable_strict_kernel_release=false,obproxy_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b,observer_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b"
./bin/obproxy -p 2883 -n mycluster -c obcluster -o prometheus_sync_interval=1s,obproxy_config_server_url=http://172.20.134.1:8088/services?Action=GetObProxyConfig&ObproxyClusterName=mycluster,prometheus_listen_port=2884,enable_metadb_used=false,skip_proxy_sys_private_check=true,log_dir_size_threshold=10G,proxy_mem_limited=2G,enable_proxy_scramble=true,enable_strict_kernel_release=false,obproxy_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b,observer_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b
listen port: 2883
appname: mycluster
cluster_name: obcluster
optstr: prometheus_sync_interval=1s,obproxy_config_server_url=http://172.20.134.1:8088/services?Action=GetObProxyConfig&ObproxyClusterName=mycluster,prometheus_listen_port=2884,enable_metadb_used=false,skip_proxy_sys_private_check=true,log_dir_size_threshold=10G,proxy_mem_limited=2G,enable_proxy_scramble=true,enable_strict_kernel_release=false,obproxy_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b,observer_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b
5.4 检查参数是否正确
observer_sys_password密码是 sha1 后的值,而不是原始值。例如:proxyro 用户设置的密码是 123456,则需要设置 observer_sys_password 的值是 7c4a8d09ca3762af61e59520943dc26494f8941b
# config URL是否已设置
bash-4.2$ strings ./etc/obproxy_config.bin |grep "obproxy_config_server_url"
obproxy_config_server_url=http://172.20.134.1:8088/services?Action=GetObProxyConfig&ObproxyClusterName=mycluster
# proxyro用户密码是否已设置
bash-4.2$ strings ./etc/obproxy_config.bin |grep "observer_sys_password"
observer_sys_password1=
observer_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b
六、连接测试
bash-4.2$ obclient -h172.20.134.3 -P2883 -uroot@sys#obcluster -p -c -A oceanbase
Enter password:
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 1
Server version: 5.6.25 OceanBase 3.1.4 (r10000092022071511-b4bfa011ceaef428782dcb65ae89190c40b78c2f) (Built Jul 15 2022 11:45:14)
Copyright (c) 2000, 2022, OceanBase and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [oceanbase]> SELECT SYSDATE();
+---------------------+
| SYSDATE() |
+---------------------+
| 2022-12-28 14:31:04 |
+---------------------+
1 row in set (0.003 sec)
obclient [oceanbase]> exit
Bye
七、其他
7.1 连接时提示密码错误
- 检查proxy配置参数中observer_sys_password的值是否正确
- 检查OBserver内是否存在proxyro账号,存在的话账号的密码是否正确,权限是否正确
7.2 连接时提示找不到集群,日志显示:curl easy perform failed
3.2.3.5版本proxy的obproxy_config_server_url参数内不能使用单引号,否则会出现该错误