写点什么

一文带你掌握 OceanBase 社区版部署细节及原理

发布于: 7 小时前

作者:庆涛。 DBA,熟悉 Oracle / MySQL / SQLServer / OceanBase , 现主要从事 OceanBase 产品和解决方案推广工作。


个人公众号:OceanBase 技术闲谈


OceanBase 在 2021 年 6 月 1 日发布了社区版后(官网:https://open.oceanbase.com/),立即有很多网友开始下载使用。部分朋友反馈在安装部署上不是很顺利,本文主要是提供一种简易的社区版安装方法,帮助大家快速了解有关原理以及具体操作步骤。


在社区版发布之前,在 OceanBase 1.0 版本发布之后,OceanBase 软件从来只有一个版本(一个 rpm 包)。不管此前你从哪个渠道获取,不管是什么形态(可执行文件、rpm 包、docker 镜像),它跟蚂蚁内部所使用的 OceanBase 都是一个代码分支(功能一样)。区别只是具体的软件版本不一样(如 1.4.7,2.2.3,2.2.5,2.2.7 等)。在社区版发布之后,才有了社区版和企业版区分,二者功能上的确有区别,功能对比具体可以看官网 :https://open.oceanbase.com/

但是 OceanBase 最核心的基本能力都一样,包括:多副本 Paxos 协议强同步、SQL 引擎(兼容 MySQL)、分布式事务、水平扩展。所以就部署方法而言,社区版和企业版的部署方法都是一样的。以前总结的 OceanBase 部署经验同样适用于社区版。


参考:(https://mp.weixin.qq.com/s/uoHUd40VzIn5M_I_SbESoA


OceanBase 部署的方法比 Oracle RAC 简单许多,新手觉得难的主要原因在于还不太了解 OB 的步骤原理。当机器资源和环境都初始化正确后,命令行环境里运行 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 infowill 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 -pEnter 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 -uroot@sys -P2881 -p123456 -c -A oceanbaseWelcome 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 /data
su - adminecho "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/admin/oceanbase/lib/" >> ~/.bash_profile. ~/.bash_profile
mkdir -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 INFO
su - 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 allowed
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 |+----------------------------+----------------------------+--------+-----------------------+------------+-------------+----------+-----------+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 allowed
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: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 oceanbase

MySQL [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 -p
MySQL [(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 oceanbase
MySQL [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 INFO
cd /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 grepadmin    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 INFOadmin    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 INFOadmin    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 nametcp        0      0 0.0.0.0:3881            0.0.0.0:*               LISTEN      21775/observertcp        0      0 0.0.0.0:3882            0.0.0.0:*               LISTEN      21775/observertcp        0      0 0.0.0.0:4881            0.0.0.0:*               LISTEN      22371/observertcp        0      0 0.0.0.0:4882            0.0.0.0:*               LISTEN      22371/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      21194/observertcp        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 之前至少得先确保熟悉原理和性能调优方法,可以看看本公众号的一些文章总结。(公众号搜索:OceanBase 技术闲谈)。


如果您有任何疑问,可以通过以下方式与我们进行交流:

微信群:扫码添加小助手,将拉你进群哟~


钉钉群:33254054


厚脸皮地来求个 star

我们想让 Github (https://github.com/oceanbase/oceanbase)上优质的开源项目被更多人看到。

文档都是我们精心整理。如果有帮助的话求个 star (◕ᴗ◕✿),鼓励鼓励我们哟!


也欢迎大家给我们提 issue,运营小姐姐在此跪谢️️ ❥(^_-):

https://github.com/oceanbase/oceanbase


欢迎大家一起参与社区贡献,指南请参考看这里 :

https://open.oceanbase.com/docs/community/oceanbase-database/V3.1.0/how-to-contribute


社区答疑:https://open.oceanbase.com/answer


发布于: 7 小时前阅读数: 6
用户头像

OceanBase 社区版 2020.05.06 加入

github:https://github.com/oceanbase/oceanbase 欢迎大家

评论

发布
暂无评论
一文带你掌握 OceanBase 社区版部署细节及原理