OceanBase在2021年6月1日公布了社区版(官网:open.oceanbase.com)。立即有很多网友开始下载使用。部分朋友在安装部署上不是很顺利,本文主要是提供一种社区版安装方法,让大家了解这个步骤和原理。
内容包括:
OB软件版本说明。
OB社区版单副本部署。
OB社区版单副本扩容到三副本方法。
OB社区版obproxy部署。
OB社区版三副本部署。
在社区版发布之前,在OceanBase 1.0版本发布之后,OceanBase软件从来只有一个版本(一个rpm包)。不管此前你从哪个渠道获取的,不管是什么形态(可执行文件、rpm包、docker镜像),它跟蚂蚁内部用OceanBase都是一个代码分支(功能都是一样的)。区别只是那个具体的软件版本不一样(如1.4.7,2.2.3,2.2.5,2.2.7等)。在社区版发布之后,才有社区版和企业版区分,二者功能上确有区别,企业版多了更多高级功能(具体请看官网 open.oceanbase.com )。
但是OceanBase最核心的基本能力都一样,包括:多副本Paxos协议强同步、SQL引擎(兼容MySQL)、分布式事务、水平扩展。所以就部署方法而言,社区版和企业版的部署方法都是一样的。以前总结的OceanBase部署经验同样适用于社区版。
OceanBase部署的方法比ORACLE RAC简单多了,新手觉得难只是因为没有搞清楚这里面的步骤原理。当机器资源和环境都初始化正确的时候,命令行下5分钟就可以重新部署一个OceanBase集群。很多人喜欢自动化脚本部署,觉得省事。但弊端也很明显。不管成功还是失败,你都很难知道原理或原因。除非你研究自动化部署脚本的程序 。所以我建议先手动部署成功后再用自动化部署程序。企业版的交付是有图形化产品辅助部署的。同样建议先了解原理。
下面的方法主要是供初学者能把社区版跑起来,会省略一些OS内核参数、数据库内核参数的配置过程的。所以这个方法装好的OB不适合立即跑性能测试。
首先是下载社区版。
这里不考虑源码编译安装了。按官网方法下载。
yum install -y yum-utilsyum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo# 创建一个目录用于下载mkdir rpmcat > rpm_list <<EOFoceanbase-ce-3.1.0-1.el7.x86_64.rpmoceanbase-ce-libs-3.1.0-1.el7.x86_64.rpmobproxy-3.1.0-1.el7.x86_64.rpmEOFwget -B https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/ -i rpm_list -P rpm
先不要安装rpm包。
第二机器配置。
OceanBase机器里关键资源是内存。就目前而言,4C8G的环境将OB跑起来是没问题的。如果条件允许,尽可能用更大资源的机器。比如说我用的16C64G的阿里云ECS。机器资源多一点,我可以多起几个OB进程,在单机上模拟搭建一个集群。
机器磁盘也单独说一下。这关系到OB的数据文件、日志文件的存储。这个路径比较多确实有点难记。初学时简单点,机器搞一块独立的裸盘即可(/dev/sdb)。磁盘的空间稍微大于内存的4倍吧。
第三是操作系统配置。
为缩减篇幅,不说OS内核参数设置了,那些是关乎性能的。这里目标降低为跑起来。
将物理盘格式化为文件系统 data
[root@obpilot ~]# fdisk dev/vdb[root@obpilot ~]# mkfs -t ext4 dev/vdb1[root@obpilot ~]# mkdir -p data
[root@obpilot ~]# mount -t ext4 dev/vdb1 data
官网OBD安装的OB会运行在root用户下。这个习惯不好。生产的OB默认运行在admin用户下,这里也这么做。要换成其他用户也可以,先按admin用户安装好熟悉一下特点再考虑换其他用户。
[root@obpilot ~]# useradd admin[root@obpilot ~]# rpm -ivh rpm/*准备中... ################################# [100%]正在升级/安装... 1:oceanbase-ce-libs-3.1.0-1.el7 ################################# [ 33%] 2:oceanbase-ce-3.1.0-1.el7 ################################# [ 67%] 3:obproxy-3.1.0-1.el7 ################################# [100%]
查看一下具体安装目录。
[root@obpilot ~]# rpm -ql oceanbase-ce-3.1.0-1.el7.x86_64/home/admin/oceanbase/home/admin/oceanbase/bin/home/admin/oceanbase/bin/import_time_zone_info.py/home/admin/oceanbase/bin/observer/home/admin/oceanbase/etc/home/admin/oceanbase/etc/timezone_V1.log[root@obpilot ~]# rpm -ql obproxy-3.1.0-1.el7/home/admin/obproxy-3.1.0/bin/home/admin/obproxy-3.1.0/bin/obproxy/home/admin/obproxy-3.1.0/bin/obproxyd.sh[root@obpilot ~]#
第四启动OB进程。
在 admin用户下启动,在oceanbase主目录启动,严格按照下面步骤执行命令。
[admin@obpilot oceanbase]$ su - admin
[admin@obpilot oceanbase]$ mkdir -p data/
observer01
/store/{sort_dir,sstable,clog,ilog,slog}
[admin@obpilot oceanbase]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/admin/oceanbase/lib/[admin@obpilot oceanbase]$ cd data/observer01 && home/admin/oceanbase/bin/observer -r
172.20.249.39
:2882:2881 -o __min_full_resource_pool_memory=268435456,memory_limit=
8G
,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone1 -p 2881 -P 2882 -c 1 -d data/
observer01
/store -i
eth0
-l INFO
上面黄色底色的都是要根据实际环境修改的
1. -d 是指定存放 OB节点的数据文件和日志文件的目录。这个目录下必须存在几个子目录。如果你重装了,把 -d 的目录清空重新创建。
2. -r 是指定OB节点的信息。上面是单节点。后面再看三节点的示例。
3. -o 是指定OB进程启动参数,如果你熟悉OB参数,可以在这里调整。这里的 memory_limit=8G,表示启动一个8G的OB进程。如果你机器实际内存比这个大,可以改大它。内存越大的话,你甚至可以去掉这些内存相关的参数。data_size是数据文件大小,确保可以分配出来并且分配后剩余空间比例不低于10%以及是内存 2 倍以上。
4. -i 是网卡名,跟 -r 后面的IP要对应上。
5. 启动目录改到 /data/observer01下,这样相关的运行日志会在这个目录下。后面还要启动多个节点,每个节点的observer进程运行日志是分开存放的。
启动后能看到observer进程,监听端口(2881和2882),那这一步就成功了。
rs list: 172.20.249.39:2882:2881optstr: __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10zone: zone1mysql port: 2881rpc port: 2882cluster id: 1data_dir: data/observer01/storedevname: eth0log level: INFO[2021-06-26 17:27:34.052449]
ERROR
[LIB] pidfile_test (utility.cpp:1153) [9005][0][Y0-0000000000000000] [lt=0] fid file doesn't exist(pidfile="run/observer.pid") BACKTRACE:0x90a107e 0x90008fb 0x24c152f 0x251bb2d 0x90a6215 0x24be1a8 0x7f1a0a400495 0x24bd4e9[admin@obpilot oceanbase]$ ps -ef|grep observeradmin 9006 1 73 17:27 ? 00:00:04 bin/observer -r 172.20.249.39:2882:2881 -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone1 -p 2881 -P 2882 -c 1 -d data/observer01/store -i eth0 -l INFOadmin 9577 8043 0 17:27 pts/2 00:00:00 grep --color=auto observer[admin@obpilot oceanbase]$ netstat -ntlp(Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.)Active Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -tcp 0 0 0.0.0.0:2881 0.0.0.0:* LISTEN 9006/bin/observertcp 0 0 0.0.0.0:2882 0.0.0.0:* LISTEN 9006/bin/observer[admin@obpilot oceanbase]$
说明:
如果你不是第一次启动,再次启动的时候会看到提示“ERROR [LIB] pidfile_test (utility.cpp:1153) [9005][0][Y0-0000000000000000] [lt=0] fid file doesn't exist(pidfile="run/observer.pid")”。这个报错没有实质性影响,这个信息日志级别应该用 WARN 而不是 ERROR 。希望社区版能有人把这个级别改了。
仅仅是进程启动了,并不代表OB部署成功了。
第五步,集群bootstrap。
不用奇怪我说集群。三副本是集群,单副本也是集群。单副本不一定是单节点。
进程第一次启动后,用mysql客户端登录(mysql版本5.5/5.6/5.7) ,root密码为空。用 obclient 也可以(需要安装 yum -y install obclient)。
[admin@obpilot oceanbase]$ mysql -h127.1 -uroot -P2881 -p -c -AEnter password:Welcome to the MariaDB monitor. Commands end with ; or \g.Your MySQL connection id is 3221225473Server version: 5.7.25 OceanBase 3.1.0 (r-) (Built May 30 2021 11:21:29)Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MySQL [(none)]>MySQL [(none)]>
set session ob_query_timeout=1000000000; alter system bootstrap ZONE 'zone1' SERVER '
172.20.249.39
:2882' ;
Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (15.67 sec)MySQL [(none)]> alter user root identified by '
123456
';Query OK, 0 rows affected (0.02 sec)MySQL [(none)]> Bye[admin@obpilot oceanbase]$ mysql -h127.1 -u
root@sys
-P2881 -p123456 -c -A
oceanbase
Welcome to the MariaDB monitor. Commands end with ; or \g.Your MySQL connection id is 3221487636Server version: 5.7.25 OceanBase 3.1.0 (r-) (Built May 30 2021 11:21:29)Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MySQL [oceanbase]>
show databases;
+--------------------+| Database |+--------------------+|
oceanbase
|| information_schema || mysql || SYS || LBACSYS || ORAAUDITOR || test |+--------------------+7 rows in set (0.00 sec)MySQL [oceanbase]>
bootstrap 是学OB的第一道门槛。迈不过去就永远部署不了OB。bootstrap 原理比较复杂,刚开始根据原理或日志去找原因不是个好主意。bootstrap失败的原因通常很简单。如内存资源不够、目录权限不对、日志盘空间不够等等、多节点时间不同步(超过5ms)、多节点网络延时很大(超过50ms)。这一块有单独的文章总结,可以参考《OceanBase 2.2 安装部署问题解答》。
bootstrap 成功后,用用户名 root@sys 登录后,查看数据库,可以看到多出几个database:oceanbase 。
看到 oceanbase 这个数据库,那就是真正成功了。
第六步,建租户(实例)。
租户就是实例,是逻辑实例,没有单独的进程。OceanBase在企业自己机房部署后,可以给开发提供类似云数据库的服务。Database As A Service。实例按需分配,立即分配(1分钟不到),实例资源后期可以在线调整,多退少补。OceanBase改变的是传统数据库的运维形态,DBA更像是一个资源管家,更专注于服务业务。
这一步很简单,但是很多人也会在这里碰到资源不足问题。在分配租户之前,首先得知道集群有多少资源可用。
MySQL [oceanbase]> select a.zone,concat(a.svr_ip,':',a.svr_port) observer, cpu_total, (cpu_total-cpu_assigned) cpu_free, round(mem_total/1024/1024/1024) mem_total_gb, round((mem_total-mem_assigned)/1024/1024/1024) mem_free_gb, usec_to_time(b.last_offline_time) last_offline_time, usec_to_time(b.start_service_time) start_service_time, b.status, b.build_version , usec_to_time(a.stop_time) stop_timefrom __all_virtual_server_stat a join __all_server b on (a.svr_ip=b.svr_ip and a.svr_port=b.svr_port)order by a.zone, a.svr_ip;+-------+--------------------+-----------+----------+--------------+-------------+----------------------------+----------------------------+--------+-------------------------------+----------------------------+| zone | observer | cpu_total | cpu_free | mem_total_gb | mem_free_gb | last_offline_time | start_service_time | status | build_version | stop_time |+-------+--------------------+-----------+----------+--------------+-------------+----------------------------+----------------------------+--------+-------------------------------+----------------------------+| zone1 | 172.20.249.39:2882 | 14 | 11.5 | 4 | 3 | 1970-01-01 08:00:00.000000 | 2021-06-26 17:29:25.599983 | active | 3.1.0_-(May 30 2021 11:21:29) | 1970-01-01 08:00:00.000000 |+-------+--------------------+-----------+----------+--------------+-------------+----------------------------+----------------------------+--------+-------------------------------+----------------------------+1 row in set (0.00 sec)MySQL [oceanbase]> select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb, t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_namefrom __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id) join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`) left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id)order by t1.`resource_pool_id`, t2.`unit_config_id`, t3.unit_id; -> ;+--------------------+------------------+---------+---------+------------+------------+---------+-------+--------------------+-----------+-------------+| resource_pool_name | unit_config_name | max_cpu | min_cpu | max_mem_gb | min_mem_gb | unit_id | zone | observer | tenant_id | tenant_name |+--------------------+------------------+---------+---------+------------+------------+---------+-------+--------------------+-----------+-------------+| sys_pool | sys_unit_config | 5 | 2.5 | 1 | 1 | 1 | zone1 | 172.20.249.39:2882 | 1 | sys |+--------------------+------------------+---------+---------+------------+------------+---------+-------+--------------------+-----------+-------------+1 row in set (0.00 sec)
第一个sql 是查集群各个节点的剩余资源(cpu和内存,空间不管)。第二个sql是查询集群里当前资源使用细节。这里有几点解释:
1. observer 启动参数里指定了cpu_count=16,表示告诉(欺骗)observer进程主机有16个cpu,实际上observer进程只拿了14个cpu,留了2个给os。生产环境实打实的。
2. observer 启动进程里指定了memory_limit=8G,表示告诉(不是欺骗)observer进程可用8G内存,ob内部system_memory拿去了4G,还剩下4G.所以这里的memory_total是4G,然后内部租户 sys_pool用了1G,留给租户的就是3G。
细心的朋友如果计算一下cpu的分配,总cpu是14个,sys租户用了2.5,剩余是11.5.实际上实际可用的cpu不是11.5,而是9个。这个是因为 sys_unit_config的min_cpu值跟max_cpu不一样(在企业版本里,min_memory跟max_memory也不一样)。而很多人根据第一个sql计算觉得资源够,实际分配的时候不够往往就是这个原因。
所以,个人习惯,首先把这个不协调的设置改对。真希望社区版能有人把这个代码逻辑改过来。
MySQL [oceanbase]> alter resource unit sys_unit_config min_cpu=5,min_memory='1G';
Query OK, 0 rows affected (0.01 sec)
MySQL [oceanbase]> select a.zone,concat(a.svr_ip,':',a.svr_port) observer, cpu_total, (cpu_total-cpu_assigned) cpu_free, round(mem_total/1024/1024/1024) mem_total_gb, round((mem_total-mem_assigned)/1024/1024/1024) mem_free_gb, usec_to_time(b.last_offline_time) last_offline_time, usec_to_time(b.start_service_time) start_service_time, b.status, b.build_version , usec_to_time(a.stop_time) stop_time from __all_virtual_server_stat a join __all_server b on (a.svr_ip=b.svr_ip and a.svr_port=b.svr_port) order by a.zone, a.svr_ip;
+-------+--------------------+-----------+----------+--------------+-------------+----------------------------+----------------------------+--------+-------------------------------+----------------------------+| zone | observer | cpu_total | cpu_free | mem_total_gb | mem_free_gb | last_offline_time | start_service_time | status | build_version | stop_time |+-------+--------------------+-----------+----------+--------------+-------------+----------------------------+----------------------------+--------+-------------------------------+----------------------------+| zone1 | 172.20.249.39:2882 | 14 | 9 | 4 | 3 | 1970-01-01 08:00:00.000000 | 2021-06-26 17:29:25.599983 | active | 3.1.0_-(May 30 2021 11:21:29) | 1970-01-01 08:00:00.000000 |+-------+--------------------+-----------+----------+--------------+-------------+----------------------------+----------------------------+--------+-------------------------------+----------------------------+1 row in set (0.01 sec)
现在可以愉快的创建租户(实例)了。
MySQL [oceanbase]> CREATE resource unit my_unit_config max_cpu=4, min_cpu=4, max_memory='1G', min_memory='1G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='1024G';Query OK, 0 rows affected (0.01 sec)MySQL [oceanbase]> CREATE resource pool pool_mysql_01 unit = 'my_unit_config', unit_num = 1;Query OK, 0 rows affected (0.01 sec)MySQL [oceanbase]> CREATE tenant mysql01 resource_pool_list=('pool_mysql_01'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';Query OK, 0 rows affected (0.48 sec)MySQL [oceanbase]>MySQL [oceanbase]> CREATE resource pool pool_mysql_02 unit = 'my_unit_config', unit_num = 1;Query OK, 0 rows affected (0.00 sec)MySQL [oceanbase]>MySQL [oceanbase]> CREATE tenant mysql02 resource_pool_list=('pool_mysql_02'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';Query OK, 0 rows affected (0.46 sec)
我这里创建了2个租户。4C1G的mysql租户,就看看功能就行。不适合大量建表和导入数据,以及性能测试。
MySQL [oceanbase]> select * from __all_tenant;+----------------------------+----------------------------+-----------+-------------+-------------+-----------+--------------+--------+----------------+-----------------------+-----------+-----------------------+---------------+---------------------+-------------------+------------------------+-----------------------------+-----------------------+--------------------+------------------+----------------------+---------------+| gmt_create | gmt_modified | tenant_id | tenant_name | replica_num | zone_list | primary_zone | locked | collation_type | info | read_only | rewrite_merge_version | locality | logonly_replica_num | previous_locality | storage_format_version | storage_format_work_version | default_tablegroup_id | compatibility_mode | drop_tenant_time | status | in_recyclebin |+----------------------------+----------------------------+-----------+-------------+-------------+-----------+--------------+--------+----------------+-----------------------+-----------+-----------------------+---------------+---------------------+-------------------+------------------------+-----------------------------+-----------------------+--------------------+------------------+----------------------+---------------+| 2021-06-26 17:29:24.242717 | 2021-06-26 17:29:24.242717 | 1 | sys | -1 | zone1 | zone1 | 0 | 0 | system tenant | 0 | 0 | FULL{1}@zone1 | 0 | | 0 | 0 | -1 | 0 | -1 | TENANT_STATUS_NORMAL | 0 || 2021-06-26 19:20:13.030153 | 2021-06-26 19:20:13.030153 | 1001 | mysql01 | -1 | zone1 | RANDOM | 0 | 0 | mysql tenant/instance | 0 | 0 | FULL{1}@zone1 | 0 | | 0 | 0 | -1 | 0 | -1 | TENANT_STATUS_NORMAL | 0 || 2021-06-26 19:20:58.340233 | 2021-06-26 19:20:58.340233 | 1003 | mysql02 | -1 | zone1 | RANDOM | 0 | 0 | mysql tenant/instance | 0 | 0 | FULL{1}@zone1 | 0 | | 0 | 0 | -1 | 0 | -1 | TENANT_STATUS_NORMAL | 0 |+----------------------------+----------------------------+-----------+-------------+-------------+-----------+--------------+--------+----------------+-----------------------+-----------+-----------------------+---------------+---------------------+-------------------+------------------------+-----------------------------+-----------------------+--------------------+------------------+----------------------+---------------+3 rows in set (0.00 sec)select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb, t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_namefrom __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id) join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`) left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id)order by t1.`resource_pool_id`, t2.`unit_config_id`, t3.unit_id;+--------------------+------------------+---------+---------+------------+------------+---------+-------+--------------------+-----------+-------------+| resource_pool_name | unit_config_name | max_cpu | min_cpu | max_mem_gb | min_mem_gb | unit_id | zone | observer | tenant_id | tenant_name |+--------------------+------------------+---------+---------+------------+------------+---------+-------+--------------------+-----------+-------------+| sys_pool | sys_unit_config | 5 | 5 | 1 | 1 | 1 | zone1 | 172.20.249.39:2882 | 1 | sys || pool_mysql_01 | my_unit_config | 4 | 4 | 1 | 1 | 1001 | zone1 | 172.20.249.39:2882 | 1001 | mysql01 || pool_mysql_02 | my_unit_config | 4 | 4 | 1 | 1 | 1002 | zone1 | 172.20.249.39:2882 | 1003 | mysql02 |+--------------------+------------------+---------+---------+------------+------------+---------+-------+--------------------+-----------+-------------+3 rows in set (0.00 sec)
在往后就是OB的使用了。还有obproxy的部署、租户的连接。这些跟企业版也是一样的。有问题的朋友可以查看以前的文章。这里不再赘述了。
特别介绍:单副本扩容到三副本。
这里再介绍一下从单节点扩容到三节点,能看懂了表示就理解了OceanBase集群扩容原理。
chown -R admin.admin datasu - adminecho "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/admin/oceanbase/lib/" >> ~/.bash_profile. ~/.bash_profilemkdir -p data/
observer02
/store/{sort_dir,sstable,clog,ilog,slog}cd data/
observer02
/ && home/admin/oceanbase/bin/observer -r 172.20.249.39:2882:2881 -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone2 -p 3881 -P 3882 -c 1 -d data/
observer02
/store -i eth0 -l INFOsu - adminmkdir -p data/
observer03
/store/{sort_dir,sstable,clog,ilog,slog}cd data/
observer03
/ && home/admin/oceanbase/bin/observer -r 172.20.249.39:2882:2881 -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone3 -p 4881 -P 4882 -c 1 -d data/
observer03
/store -i eth0 -l INFO[admin@obpilot observer03]$ ps -ef|grep observer |grep -v grepadmin 26533 1 50 19:46 ? 00:02:57 home/admin/oceanbase/bin/observer -r 172.20.249.39:2882:2881 -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone1 -p 2881 -P 2882 -c 1 -d data/observer01/store -i eth0 -l INFOadmin 27316 1 59 19:50 ? 00:01:01 home/admin/oceanbase/bin/observer -r 172.20.249.39:2882:2881 -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone2 -p 3881 -P 3882 -c 1 -d data/observer02/store -i eth0 -l INFOadmin 27955 1 72 19:52 ? 00:00:11 home/admin/oceanbase/bin/observer -r 172.20.249.39:2882:2881 -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone3 -p 4881 -P 4882 -c 1 -d data/observer03/store -i eth0 -l INFO[admin@obpilot observer03]$ netstat -ntlp(Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.)Active Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:3881 0.0.0.0:* LISTEN 27316/observertcp 0 0 0.0.0.0:3882 0.0.0.0:* LISTEN 27316/observertcp 0 0 0.0.0.0:4881 0.0.0.0:* LISTEN 27955/observertcp 0 0 0.0.0.0:4882 0.0.0.0:* LISTEN 27955/observertcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -tcp 0 0 0.0.0.0:2881 0.0.0.0:* LISTEN 26533/observertcp 0 0 0.0.0.0:2882 0.0.0.0:* LISTEN 26533/observer[admin@obpilot observer03]
说明:
1. -r 参数依然是第一个节点的端口(2881和2882),因为这里是集群扩容,不是新增2个集群。所以 -r 参数会决定了这个进程启动后跟哪个集群进行通信。
2. -p 和 -P 参数要不一样。每个进程监听2个端口,不能冲突。
3. 不同节点的启动目录要不一样,这样每个目录下会生成相应的log目录,里面有运行日志。
进程启动了,还要在集群里把这两个节点加进集群。
MySQL [oceanbase]> select * from __all_zone where name in ('region','status','zone_type');+----------------------------+----------------------------+-------+-----------+-------+----------------+| gmt_create | gmt_modified | zone | name | value | info |+----------------------------+----------------------------+-------+-----------+-------+----------------+| 2021-06-26 20:01:31.466919 | 2021-06-26 20:01:31.466919 | zone1 | region | 0 | default_region || 2021-06-26 20:01:31.465863 | 2021-06-26 20:01:31.465863 | zone1 | status | 2 | ACTIVE || 2021-06-26 20:01:31.466919 | 2021-06-26 20:01:31.466919 | zone1 | zone_type | 0 | ReadWrite |+----------------------------+----------------------------+-------+-----------+-------+----------------+3 rows in set (0.00 sec)MySQL [oceanbase]> alter system add zone 'zone2' region 'default_region';Query OK, 0 rows affected (0.01 sec)MySQL [oceanbase]> alter system add zone 'zone3' region 'default_region';Query OK, 0 rows affected (0.00 sec)MySQL [oceanbase]> alter system start zone 'zone2';Query OK, 0 rows affected (0.00 sec)MySQL [oceanbase]> alter system start zone 'zone3';Query OK, 0 rows affected (0.00 sec)MySQL [oceanbase]> select * from __all_zone where name in ('region','status','zone_type');+----------------------------+----------------------------+-------+-----------+-------+----------------+| gmt_create | gmt_modified | zone | name | value | info |+----------------------------+----------------------------+-------+-----------+-------+----------------+| 2021-06-26 20:01:31.466919 | 2021-06-26 20:01:31.466919 | zone1 | region | 0 | default_region || 2021-06-26 20:01:31.465863 | 2021-06-26 20:01:31.465863 | zone1 | status | 2 | ACTIVE || 2021-06-26 20:01:31.466919 | 2021-06-26 20:01:31.466919 | zone1 | zone_type | 0 | ReadWrite || 2021-06-26 20:07:15.488710 | 2021-06-26 20:07:15.488710 | zone2 | region | 0 | default_region || 2021-06-26 20:07:15.488508 | 2021-06-26 20:08:31.962846 | zone2 | status | 2 | ACTIVE || 2021-06-26 20:07:15.489765 | 2021-06-26 20:07:15.489765 | zone2 | zone_type | 0 | LOCAL || 2021-06-26 20:07:20.821128 | 2021-06-26 20:07:20.821128 | zone3 | region | 0 | default_region || 2021-06-26 20:07:20.820098 | 2021-06-26 20:08:34.522818 | zone3 | status | 2 | ACTIVE || 2021-06-26 20:07:20.821128 | 2021-06-26 20:07:20.821128 | zone3 | zone_type | 0 | LOCAL |+----------------------------+----------------------------+-------+-----------+-------+----------------+9 rows in set (0.00 sec)
MySQL [oceanbase]> alter system add server '172.20.249.39:3882' zone 'zone2';
Query OK, 0 rows affected (0.01 sec)
MySQL [oceanbase]> alter system add server '172.20.249.39:4882' zone 'zone3';
Query OK, 0 rows affected (0.01 sec)
select a.zone,concat(a.svr_ip,':',a.svr_port) observer, cpu_total, (cpu_total-cpu_assigned) cpu_free, round(mem_total/1024/1024/1024) mem_total_gb, round((mem_total-mem_assigned)/1024/1024/1024) mem_free_gb, usec_to_time(b.last_offline_time) last_offline_time, usec_to_time(b.start_service_time) start_service_time, b.status, b.build_version , usec_to_time(a.stop_time) stop_timefrom __all_virtual_server_stat a join __all_server b on (a.svr_ip=b.svr_ip and a.svr_port=b.svr_port)order by a.zone, a.svr_ip;+-------+--------------------+-----------+----------+--------------+-------------+----------------------------+----------------------------+--------+-------------------------------+----------------------------+| zone | observer | cpu_total | cpu_free | mem_total_gb | mem_free_gb | last_offline_time | start_service_time | status | build_version | stop_time |+-------+--------------------+-----------+----------+--------------+-------------+----------------------------+----------------------------+--------+-------------------------------+----------------------------+| zone1 | 172.20.249.39:2882 | 14 | 1 | 4 | 1 | 1970-01-01 08:00:00.000000 | 2021-06-26 20:01:32.824604 | active | 3.1.0_-(May 30 2021 11:21:29) | 1970-01-01 08:00:00.000000 || zone2 | 172.20.249.39:3882 | 14 | 14 | 4 | 4 | 1970-01-01 08:00:00.000000 | 2021-06-26 20:01:35.617217 | active | 3.1.0_-(May 30 2021 11:21:29) | 1970-01-01 08:00:00.000000 || zone3 | 172.20.249.39:4882 | 14 | 14 | 4 | 4 | 1970-01-01 08:00:00.000000 | 2021-06-26 20:09:21.226741 | active | 3.1.0_-(May 30 2021 11:21:29) | 1970-01-01 08:00:00.000000 |+-------+--------------------+-----------+----------+--------------+-------------+----------------------------+----------------------------+--------+-------------------------------+----------------------------+3 rows in set (0.00 sec)MySQL [oceanbase]> CREATE resource pool pool_mysql_01b unit = 'my_unit_config', unit_num = 1, zone_list=('zone2','zone3');Query OK, 0 rows affected (0.01 sec)MySQL [oceanbase]> CREATE resource pool pool_mysql_02b unit = 'my_unit_config', unit_num = 1, zone_list=('zone2','zone3');Query OK, 0 rows affected (0.01 sec)MySQL [oceanbase]> alter tenant mysql01 resource_pool_list=('pool_mysql_01','pool_mysql_01b');Query OK, 0 rows affected (0.03 sec)MySQL [oceanbase]> alter tenant mysql01 locality='FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3';ERROR 4179 (HY000): violate locality principal not allowedMySQL [oceanbase]> alter tenant mysql01 primary_zone='zone1';Query OK, 0 rows affected (0.02 sec)MySQL [oceanbase]> alter tenant mysql01 locality='FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3';ERROR 4179 (HY000): violate locality principal not allowedMySQL [oceanbase]> alter tenant mysql01 locality='FULL{1}@zone1, FULL{1}@zone2';Query OK, 0 rows affected (0.02 sec)MySQL [oceanbase]> alter tenant mysql01 locality='FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3';ERROR 4179 (HY000): alter tenant locality when previous operation is in progress not allowedMySQL [oceanbase]> select gmt_create,gmt_modified,job_id,job_type,job_status,return_code,progress,tenant_id from __all_rootservice_job;+----------------------------+----------------------------+--------+-----------------------+------------+-------------+----------+-----------+| gmt_create | gmt_modified | job_id | job_type | job_status | return_code | progress | tenant_id |+----------------------------+----------------------------+--------+-----------------------+------------+-------------+----------+-----------+| 2021-06-26 20:12:54.409071 | 2021-06-26 20:13:25.724652 | 1 | ALTER_TENANT_LOCALITY | SUCCESS | 0 | 100 | 1001 |+----------------------------+----------------------------+--------+-----------------------+------------+-------------+----------+-----------+1 row in set (0.01 sec)MySQL [oceanbase]> CREATE resource pool sys_poolb unit = 'sys_unit_config', unit_num = 1, zone_list=('zone2','zone3');Query OK, 0 rows affected (0.01 sec)MySQL [oceanbase]> alter tenant sys resource_pool_list=('sys_pool','sys_poolb');Query OK, 0 rows affected (0.02 sec)MySQL [oceanbase]> alter tenant sys locality='FULL{1}@zone1, FULL{1}@zone2';Query OK, 0 rows affected (0.02 sec)MySQL [oceanbase]> alter tenant sys locality='FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3';ERROR 4179 (HY000): alter tenant locality when previous operation is in progress not allowedMySQL [oceanbase]> select gmt_create,gmt_modified,job_id,job_type,job_status,return_code,progress,tenant_id from __all_rootservice_job;+----------------------------+----------------------------+--------+-----------------------+------------+-------------+----------+-----------+| gmt_create | gmt_modified | job_id | job_type | job_status | return_code | progress | tenant_id |+----------------------------+----------------------------+--------+-----------------------+------------+-------------+----------+-----------+| 2021-06-26 20:12:54.409071 | 2021-06-26 20:13:25.724652 | 1 | ALTER_TENANT_LOCALITY | SUCCESS | 0 | 100 | 1001 || 2021-06-26 20:15:16.628450 | 2021-06-26 20:15:48.679600 | 2 | ALTER_TENANT_LOCALITY | SUCCESS | 0 | 100 | 1001 || 2021-06-26 20:19:37.365538 | 2021-06-26 20:19:37.365538 | 5 | ALTER_TENANT_LOCALITY | INPROGRESS | NULL | 0 | 1 |+----------------------------+----------------------------+--------+-----------------------+------------+-------------+----------+-----------+5 rows in set (0.00 sec)-- 等若干分钟MySQL [oceanbase]> alter tenant sys locality='FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3';Query OK, 0 rows affected (0.03 sec)MySQL [oceanbase]> alter tenant mysql02 resource_pool_list=('pool_mysql_02','pool_mysql_02b');Query OK, 0 rows affected (0.05 sec)MySQL [oceanbase]> alter tenant mysql02 locality='FULL{1}@zone1, FULL{1}@zone2';Query OK, 0 rows affected (0.02 sec)-- 等若干分钟MySQL [oceanbase]> alter tenant mysql02 locality='FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3';Query OK, 0 rows affected (0.01 sec)-- 等若干分钟MySQL [oceanbase]> select gmt_create,gmt_modified,job_id,job_type,job_status,return_code,progress,tenant_id from __all_rootservice_job;+----------------------------+----------------------------+--------+-----------------------+------------+-------------+----------+-----------+| gmt_create | gmt_modified | job_id | job_type | job_status | return_code | progress | tenant_id |+----------------------------+----------------------------+--------+-----------------------+------------+-------------+----------+-----------+| 2021-06-26 20:12:54.409071 | 2021-06-26 20:13:25.724652 | 1 | ALTER_TENANT_LOCALITY | SUCCESS | 0 | 100 | 1001 || 2021-06-26 20:15:16.628450 | 2021-06-26 20:15:48.679600 | 2 | ALTER_TENANT_LOCALITY | SUCCESS | 0 | 100 | 1001 || 2021-06-26 20:19:37.365538 | 2021-06-26 20:23:15.879598 | 5 | ALTER_TENANT_LOCALITY | SUCCESS | 0 | 100 | 1 || 2021-06-26 20:23:24.097481 | 2021-06-26 20:23:40.449128 | 6 | ALTER_TENANT_LOCALITY | SUCCESS | 0 | 100 | 1002 || 2021-06-26 20:23:42.709761 | 2021-06-26 20:26:18.419506 | 7 | ALTER_TENANT_LOCALITY | SUCCESS | 0 | 100 | 1 || 2021-06-26 20:24:13.183605 | 2021-06-26 20:26:33.958669 | 8 | ALTER_TENANT_LOCALITY | SUCCESS | 0 | 100 | 1002 |+----------------------------+----------------------------+--------+-----------------------+------------+-------------+----------+-----------+8 rows in set (0.01 sec)
这里面信息量非常大,简单说明一下:
1. 先add zone ,要逐个加,然后是逐个 start zone 。
2. 再add server,要指定 节点监听端口和zone,这个跟节点启动进程参数要对应。如果报错,说明没对上。
3. 再给各个租户补充资源池里资源单元。create resource pool 可以指定 zone_list。然后 alter tenant resource_pool_list 指定资源池。一个租户在每个zone只能有一个资源池,但是在不同zone可以有多个资源池。
4. 修改租户的locality属性。做之前,先设置明确的primary_zone(不要random)。修改locality必须缓慢的从一个zone到两个zone,这期间后台会做数据补副本操作,根据实际数据量需要点时间。结束了才能做两个zone到三个zone的扩容。
OB的扩容命令就是这么简单。
最后检查一下扩容结果。
select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb, t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_namefrom __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id) join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`) left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id)order by t4.tenant_id, t1.`resource_pool_id`, t2.`unit_config_id`, t3.unit_id;+--------------------+------------------+---------+---------+------------+------------+---------+-------+--------------------+-----------+-------------+| resource_pool_name | unit_config_name | max_cpu | min_cpu | max_mem_gb | min_mem_gb | unit_id | zone | observer | tenant_id | tenant_name |+--------------------+------------------+---------+---------+------------+------------+---------+-------+--------------------+-----------+-------------+| sys_pool | sys_unit_config | 5 | 5 | 1 | 1 | 1 | zone1 | 172.20.249.39:2882 | 1 | sys || sys_poolb | sys_unit_config | 5 | 5 | 1 | 1 | 1007 | zone2 | 172.20.249.39:3882 | 1 | sys || sys_poolb | sys_unit_config | 5 | 5 | 1 | 1 | 1008 | zone3 | 172.20.249.39:4882 | 1 | sys || pool_mysql_01 | my_unit_config | 4 | 4 | 1 | 1 | 1001 | zone1 | 172.20.249.39:2882 | 1001 | mysql01 || pool_mysql_01b | my_unit_config | 4 | 4 | 1 | 1 | 1003 | zone2 | 172.20.249.39:3882 | 1001 | mysql01 || pool_mysql_01b | my_unit_config | 4 | 4 | 1 | 1 | 1004 | zone3 | 172.20.249.39:4882 | 1001 | mysql01 || pool_mysql_02 | my_unit_config | 4 | 4 | 1 | 1 | 1002 | zone1 | 172.20.249.39:2882 | 1002 | mysql02 || pool_mysql_02b | my_unit_config | 4 | 4 | 1 | 1 | 1005 | zone2 | 172.20.249.39:3882 | 1002 | mysql02 || pool_mysql_02b | my_unit_config | 4 | 4 | 1 | 1 | 1006 | zone3 | 172.20.249.39:4882 | 1002 | mysql02 |+--------------------+------------------+---------+---------+------------+------------+---------+-------+--------------------+-----------+-------------+9 rows in set (0.00 sec)
特别介绍:obproxy部署。
obproxy的部署方法跟早期文章里写的方法有点变化了。
首先,obproxy跟OB集群通信是使用sys租户内的一个内部账户proxyro。这个账户需要创建。
[admin@obpilot obproxy]$ mysql -h127.1 -uroot@sys -P2881 -p123456 -c -A oceanbaseMySQL [oceanbase]> create user proxyro identified by 'proxyro123456';Query OK, 0 rows affected (0.01 sec)MySQL [oceanbase]> grant select on oceanbase.* to proxyro;Query OK, 0 rows affected (0.02 sec)
然后开始启动obproxy。
mkdir -p data/obproxy cd data/obproxy && home/admin/obproxy-3.1.0/bin/obproxy -p2883 -c obcluster -r "
172.20.249.39:2881
;
172.20.249.39:3881
;
172.20.249.39:4881
" -o "enable_cluster_checkout=false,enable_strict_kernel_release=false,enable_metadb_used=false"mysql -h127.1 -uroot@proxysys -P2883 -pMySQL [(none)]> alter proxyconfig set
obproxy_sys_password
='proxysys123456';Query OK, 0 rows affected (0.00 sec)MySQL [(none)]> alter proxyconfig set
observer_sys_password
='proxyro123456';Query OK, 0 rows affected (0.00 sec)MySQL [(none)]> show proxyconfig like '%sys_password%';+-----------------------+------------------------------------------+--------------------------------+-------------+---------------+| name | value | info | need_reboot | visible_level |+-----------------------+------------------------------------------+--------------------------------+-------------+---------------+| observer_sys_password | dcb332deaee8b0030c3fd21a8e9f2813984339ea | password for observer sys user | false | SYS || obproxy_sys_password | 3a8d187554571d6be2b27749187dcb8ca6285ede | password for obproxy sys user | false | SYS |+-----------------------+------------------------------------------+--------------------------------+-------------+---------------+2 rows in set (0.00 sec)[admin@obpilot obproxy]$ mysql -h127.1 -uroot@sys#obcluster -P2883 -p123456 -c -A oceanbaseMySQL [oceanbase]> show full processlist;+------------+---------+--------+---------------------+-----------+---------+------+--------+-----------------------+---------------+------+--------------+| Id | User | Tenant | Host | db | Command | Time | State | Info | Ip | Port | Proxy_sessid |+------------+---------+--------+---------------------+-----------+---------+------+--------+-----------------------+---------------+------+--------------+| 3221633341 | root | sys | 172.20.249.39:41650 | oceanbase | Query | 0 | ACTIVE | show full processlist | 172.20.249.39 | 2881 | 2 || 3221749764 | proxyro | sys | 172.20.249.39:32942 | oceanbase | Sleep | 6 | SLEEP | NULL | 172.20.249.39 | 3881 | 3 |+------------+---------+--------+---------------------+-----------+---------+------+--------+-----------------------+---------------+------+--------------+2 rows in set (0.01 sec)
说明:
1. -r 是指定OB集群的rootservice_list 地址,因为OB已经扩容为三副本里,所以这里会有三个地址(ip:port,port使用连接端口)。
2. 给obproxy指定一个启动目录 data/obproxy。这个可以改。如果启动多个obproxy进程,就设置多个目录。同样,obproxy运行在admin用户下。多个obproxy就要设置不同的监听端口。默认是2883.
3. obproxy启动后,默认用 root@proxysys 登录,密码为空。需要改密码(通过proxy参数obproxy_sys_password指定)。
4. obproxy启动后,还需要修改proxyro的密码(通过proxy参数observer_sys_password指定),设置为跟OB集群里创建的proxyro密码一致才能链接那个OB集群。
测试一下这个obproxy。
[admin@obpilot obproxy]$ mysql -h127.1 -uroot@sys#obcluster -P2883 -p123456 -c -A oceanbaseWelcome to the MariaDB monitor. Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.6.25 OceanBase 3.1.0 (r-) (Built May 30 2021 11:21:29)Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MySQL [oceanbase]> select * from __all_server;+----------------------------+----------------------------+---------------+----------+----+-------+------------+-----------------+--------+-----------------------+-------------------------------+-----------+--------------------+--------------+----------------+-------------------+| gmt_create | gmt_modified | svr_ip | svr_port | id | zone | inner_port | with_rootserver | status | block_migrate_in_time | build_version | stop_time | start_service_time | first_sessid | with_partition | last_offline_time |+----------------------------+----------------------------+---------------+----------+----+-------+------------+-----------------+--------+-----------------------+-------------------------------+-----------+--------------------+--------------+----------------+-------------------+| 2021-06-26 20:01:24.753198 | 2021-06-26 20:01:33.821660 | 172.20.249.39 | 2882 | 1 | zone1 | 2881 | 1 | active | 0 | 3.1.0_-(May 30 2021 11:21:29) | 0 | 1624708892824604 | 0 | 1 | 0 || 2021-06-26 20:09:02.347295 | 2021-06-26 20:12:54.900390 | 172.20.249.39 | 3882 | 2 | zone2 | 3881 | 0 | active | 0 | 3.1.0_-(May 30 2021 11:21:29) | 0 | 1624708895617217 | 0 | 1 | 0 || 2021-06-26 20:09:10.246956 | 2021-06-26 20:15:17.112561 | 172.20.249.39 | 4882 | 3 | zone3 | 4881 | 0 | active | 0 | 3.1.0_-(May 30 2021 11:21:29) | 0 | 1624709361226741 | 0 | 1 | 0 |+----------------------------+----------------------------+---------------+----------+----+-------+------------+-----------------+--------+-----------------------+-------------------------------+-----------+--------------------+--------------+----------------+-------------------+3 rows in set (0.02 sec)MySQL [oceanbase]> show full processlist;+------------+---------+--------+---------------------+-----------+---------+------+--------+-----------------------+---------------+------+--------------+| Id | User | Tenant | Host | db | Command | Time | State | Info | Ip | Port | Proxy_sessid |+------------+---------+--------+---------------------+-----------+---------+------+--------+-----------------------+---------------+------+--------------+| 3222011908 | root | sys | 172.20.249.39:60006 | oceanbase | Sleep | 19 | SLEEP | NULL | 172.20.249.39 | 4881 | 4 || 3221749764 | proxyro | sys | 172.20.249.39:32942 | oceanbase | Sleep | 6 | SLEEP | NULL | 172.20.249.39 | 3881 | 3 || 3221649264 | root | sys | 172.20.249.39:41704 | oceanbase | Query | 0 | ACTIVE | show full processlist | 172.20.249.39 | 2881 | 4 |+------------+---------+--------+---------------------+-----------+---------+------+--------+-----------------------+---------------+------+--------------+3 rows in set (0.01 sec)MySQL [oceanbase]>
至此,obproxy安装成功。
特别介绍:OB三副本集群直接部署方法。
上面可能会有人误解为OB安装需要从单副本开始,再扩容到三副本。这里再提供一下三副本的直接部署方法。
首先彻底清理掉已安装的OB和OBPROXY。
kill -9 `pidof observer` `pidof obproxy`sleep 3/bin/rm -rf data/observer{01,02,03} data/obproxy
开始启动三个OB节点进程。
mkdir -p data/{observer01,observer02,observer03,obproxy}mkdir -p data/observer{01,02,03}/store/{sort_dir,sstable,clog,ilog,slog}cd data/observer01/ && home/admin/oceanbase/bin/observer -r "172.20.249.39:2882:2881;172.20.249.39:3882:3881;172.20.249.39:4882:4881" -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone1 -p 2881 -P 2882 -c 1 -d data/observer01/store -i eth0 -l INFOcd data/observer02/ && home/admin/oceanbase/bin/observer -r "172.20.249.39:2882:2881;172.20.249.39:3882:3881;172.20.249.39:4882:4881" -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone2 -p 3881 -P 3882 -c 1 -d data/observer02/store -i eth0 -l INFO
cd /data/observer03/ && /home/admin/oceanbase/bin/observer -r "172.20.249.39:2882:2881;172.20.249.39:3882:3881;172.20.249.39:4882:4881" -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone3 -p 4881 -P 4882 -c 1 -d /data/observer03/store -i eth0 -l INFO
一样的,检查三个进程都监听成功。
[admin@obpilot observer03]$ ps -ef|grep observer |grep -v grep
admin 21194 1 89 13:51 ? 00:04:20 /home/admin/oceanbase/bin/observer -r 172.20.249.39:2882:2881;172.20.249.39:3882:3881;172.20.249.39:4882:4881 -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone1 -p 2881 -P 2882 -c 1 -d /data/observer01/store -i eth0 -l INFO
admin 21775 1 82 13:52 ? 00:03:47 /home/admin/oceanbase/bin/observer -r 172.20.249.39:2882:2881;172.20.249.39:3882:3881;172.20.249.39:4882:4881 -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone2 -p 3881 -P 3882 -c 1 -d /data/observer02/store -i eth0 -l INFO
admin 22371 1 86 13:52 ? 00:03:32 /home/admin/oceanbase/bin/observer -r 172.20.249.39:2882:2881;172.20.249.39:3882:3881;172.20.249.39:4882:4881 -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,sys_bkgd_migration_retry_num=3,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=50G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone3 -p 4881 -P 4882 -c 1 -d /data/observer03/store -i eth0 -l INFO
[admin@obpilot observer03]$ netstat -ntlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3881 0.0.0.0:* LISTEN 21775/observer
tcp 0 0 0.0.0.0:3882 0.0.0.0:* LISTEN 21775/observer
tcp 0 0 0.0.0.0:4881 0.0.0.0:* LISTEN 22371/observer
tcp 0 0 0.0.0.0:4882 0.0.0.0:* LISTEN 22371/observer
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:2881 0.0.0.0:* LISTEN 21194/observer
tcp 0 0 0.0.0.0:2882 0.0.0.0:* LISTEN 21194/observer
[admin@obpilot observer03]$
修改几个账户密码
mysql -h172.20.249.39 -uroot -P2881 -p -c -A
set session ob_query_timeout=1000000000; alter system bootstrap ZONE 'zone1' SERVER '172.20.249.39:2882' , ZONE 'zone2' SERVER '172.20.249.39:3882' , ZONE 'zone3' SERVER '172.20.249.39:4882';
alter user root identified by '123456';
create user proxyro identified by 'proxyro123456';
安装obproxy的方法同上。obproxy启动时指定 rootservice_list写死这个地址不是很灵活。在企业版里,OB会把rootservice_list地址通过OCP API保存到元数据库里。
最后说一些常见问题解答。
1. observer.log 比较难懂,找你看得懂的ERROR日志。或者根据错误号到官网查看说明。总会找到有用的线索。看得懂源码的朋友例外。
2. 部署是一定能成功的,不成功就是某一个细节没做好。看上面步骤细节并不多。此外机器内存一定要8G以上。
3. 不管是官网部署的还是上面方法部署的OB,就是看看功能。内存大的可以跑性能看看,但不要以此为结论。毕竟用好OB之前至少得先确保熟悉原理和性能调优方法。可以看看本公众号的一些文章总结。
自研很辛苦,开源要勇气,数据库学问很深,多测试多提意见多鼓励。相信OB社区版会发展的更好!
有问题欢迎进 OB 钉钉群讨论。钉钉群号:32725302 33254054