首批通过分布式安全可靠测评,为关键业务系统打造
使用 obshell 扩容 OceanBase 集群
更新时间:2026-04-10 11:58:35
obshell 扩容 OceanBase 数据库支持两种方式:
通过调用 API 扩容
通过 obshell 命令扩容
本文将以一个 3 副本的 OceanBase 集群为例,介绍如何通过 obshell 扩容 OceanBase 集群。
前提条件
OceanBase 集群已被 obshell 运维管理,详细的判断方法及接管操作可参见 接管非 obshell 部署集群。
OceanBase 集群的所有 OBServer 节点和 obshell 都正常运行。
部署模式
本文中四台机器的使用情况如下(obshell 使用默认端口 2886):
| 角色 | 机器 | 备注 |
|---|---|---|
| OBServer 节点 | 10.10.10.1 | OceanBase 数据库 zone1 |
| OBServer 节点 | 10.10.10.2 | OceanBase 数据库 zone2 |
| OBServer 节点 | 10.10.10.3 | OceanBase 数据库 zone3 |
| 用于扩容的 OBServer 节点 | 10.10.10.4 | 将被扩容到 OceanBase 数据库 zone1 |
通过 API 扩容
说明
obshell 会对被调用的 API 进行安全校验。因此,您在每次调用 API 之前都需先参考 API 混合加密 一文对请求进行加密,并在 curl 命令中配置加密后的请求头部(${request_headers})和请求体(${request_body})。
步骤 1:启动 obshell
在待扩容到集群的节点(10.10.10.4)上启动 obshell,详情请参见 启动 obshell。
[admin@test004 ~]$ /home/admin/oceanbase/bin/obshell agent start --ip 10.10.10.4 -P 2886
步骤 2:调用扩容接口
调用集群内的任一 obshell 的 /api/v1/ob/scale_out 接口发起扩容。
命令行中调用对应 API 接口的说明可参见 扩容。该接口会创建一个异步运维任务,查看任务进度的方法可参见 获取任务的详细信息。等待任务完成,则扩容完成。
[admin@test001 ~]$ curl -H "Content-Type: application/json" -H 'X-OCS-Header:${request_headers}' -X POST -d '${request_body}' http://10.10.10.1:2886/api/v1/ob/scale_out
通过 obshell-sdk-python 请求对应 API 方法的介绍可参见 扩容。
···
client = ClientSet("10.10.10.1", 2886, PasswordAuth("****"))
configs = {"redoDir":"/data/workspace/redo", "dataDir":"/data/workspace/data",
"datafile_size":"24G", "cpu_count":"16", "memory_limit":"16G",
"system_memory":"4G", "log_disk_size":"40G"}
client.v1.scale_out_sync("10.10.10.4", 2886, "zone1", configs) ## 调用 /api/v1/ob/scale_out
···
通过 obshell-sdk-go 请求对应 API 方法的介绍可参见 扩容。
···
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
configs := map[string]string {
"redoDir":"/data/workspace/redo", "dataDir":"/data/workspace/data",
"datafile_size":"24G", "cpu_count":"16", "memory_limit":"16G",
"system_memory":"4G", "log_disk_size":"40G"}
req := client.V1().NewScaleOutRequest("10.10.10.4", 2886, "zone1", configs)
dag, err := client.V1().ScaleOutSyncWithRequest(req) // 调用 /api/v1/ob/scale_out
···
步骤 3:验证扩容是否成功
使用 root 用户登录 OceanBase 数据库的 sys 租户,执行如下命令查看集群中的所有 OBServer 节点信息。
obclient [oceanbase]> select * from oceanbase.dba_ob_servers;输出如下:
+------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+-------------------+ | SVR_IP | SVR_PORT | ID | ZONE | SQL_PORT | WITH_ROOTSERVER | STATUS | START_SERVICE_TIME | STOP_TIME | BLOCK_MIGRATE_IN_TIME | CREATE_TIME | MODIFY_TIME | BUILD_VERSION | LAST_OFFLINE_TIME | +------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+-------------------+ | 10.10.10.1 | 2882 | 1 | zone1 | 2881 | YES | ACTIVE | 2024-04-09 17:47:47.849965 | NULL | NULL | 2024-04-09 17:47:42.054759 | 2024-04-09 17:47:48.850012 | 4.3.0.1_100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9(Mar 22 2024 13:19:48) | NULL | | 10.10.10.2 | 2882 | 2 | zone2 | 2881 | NO | ACTIVE | 2024-04-09 17:47:47.749100 | NULL | NULL | 2024-04-09 17:47:42.173519 | 2024-04-09 17:47:48.850012 | 4.3.0.1_100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9(Mar 22 2024 13:19:48) | NULL | | 10.10.10.3 | 2882 | 3 | zone3 | 2881 | NO | ACTIVE | 2024-04-09 17:47:47.490511 | NULL | NULL | 2024-04-09 17:47:42.567437 | 2024-04-09 17:47:48.850012 | 4.3.0.1_100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9(Mar 22 2024 13:19:48) | NULL | | 10.10.10.4 | 2882 | 4 | zone1 | 2881 | NO | ACTIVE | 2024-04-10 10:37:47.530894 | NULL | NULL | 2024-04-09 10:27:32.222980 | 2024-04-09 17:47:48.850012 | 4.3.0.1_100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9(Mar 22 2024 13:19:48) | NULL | +------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+-------------------+执行如下命令查看 obshell 管理的 OBServer 节点。
obclient [oceanbase]> select * from ocs.all_agent;输出如下:
+------------+------+---------------+----------------------+-------+--------------+-------+------------+----------+--------------------------+------------------------------------------------------------------------------------------------------+ | ip | port | identity | version | os | architecture | zone | mysql_port | rpc_port | home_path | public_key | +------------+------+---------------+----------------------+-------+--------------+-------+------------+----------+--------------------------+------------------------------------------------------------------------------------------------------+ | 10.10.10.1 | 2886 | CLUSTER AGENT | 4.2.3.0-102024031414 | linux | x86_64 | zone1 | 2881 | 2882 | /home/admin/oceanbase-ce | MEgCQQCfqaND/dAbH/cJhOuTP8gRUBZh1nqrNtFwB9Plw6YwWiSintZPiC9pN/FKlBeR/Klt2jvu8oqZe+S3p/xq+ckPAgMBAAE= | | 10.10.10.2 | 2886 | CLUSTER AGENT | 4.2.3.0-102024031414 | linux | x86_64 | zone2 | 2881 | 2882 | /home/admin/oceanbase-ce | MEgCQQCfqaND/dAbH/cJhOuTP8gRUBZh1nqrNtFwB9Plw6YwWiSintZPiC9pN/FKlBeR/Klt2jvu8oqZe+S3p/xq+ckPAgMBAAE= | | 10.10.10.3 | 2886 | CLUSTER AGENT | 4.2.3.0-102024031414 | linux | x86_64 | zone3 | 2881 | 2882 | /home/admin/oceanbase-ce | MEgCQQCfqaND/dAbH/cJhOuTP8gRUBZh1nqrNtFwB9Plw6YwWiSintZPiC9pN/FKlBeR/Klt2jvu8oqZe+S3p/xq+ckPAgMBAAE= | | 10.10.10.4 | 2886 | CLUSTER AGENT | 4.2.3.0-102024031414 | linux | x86_64 | zone1 | 2881 | 2882 | /home/admin/oceanbase-ce | MEgCQQCfqaND/dAbH/cJhOuTP8gRUBZh1nqrNtFwB9Plw6YwWiSintZPiC9pN/FKlBeR/Klt2jvu8oqZe+S3p/xq+ckPAgMBAAE= | +------------+------+---------------+----------------------+-------+--------------+-------+------------+----------+--------------------------+------------------------------------------------------------------------------------------------------+
如果以上两条命令都能看到新扩容的 OBServer 节点的信息,则说明扩容成功。
步骤 4:租户内资源扩容
OceanBase 集群扩容成功后,租户内的资源扩容详见 租户内资源扩容和缩容概述。
通过 obshell 命令扩容
步骤 1:启动 obshell
在待扩容到集群的节点(10.10.10.4)上启动 obshell,详情请参见 启动 obshell。
[admin@test004 ~]$ /home/admin/oceanbase/bin/obshell agent start --ip 10.10.10.4 -P 2886
步骤 2:调用扩容命令执行扩容
通过命令行扩容时,命令需要在待扩容到集群的节点上发起。在待扩容到集群的节点(10.10.10.4)上执行 obshell cluster scale-out 命令。命令介绍请详见 obshell cluster scale-out。
[admin@test004 ~]$ /home/admin/oceanbase/bin/obshell cluster scale-out -s '10.10.10.1:2886' -z 'zone1' -o 'memory_limit=16G,system_memory=8G,log_disk_size=24G,datafile_size=24G' --rp *****
步骤 3:验证扩容成功
使用 root 用户登录 OceanBase 数据库的 sys 租户,执行如下命令查看集群中的所有 OBServer 节点信息。
obclient [oceanbase]> select * from oceanbase.dba_ob_servers;输出如下:
+------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+-------------------+ | SVR_IP | SVR_PORT | ID | ZONE | SQL_PORT | WITH_ROOTSERVER | STATUS | START_SERVICE_TIME | STOP_TIME | BLOCK_MIGRATE_IN_TIME | CREATE_TIME | MODIFY_TIME | BUILD_VERSION | LAST_OFFLINE_TIME | +------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+-------------------+ | 10.10.10.1 | 2882 | 1 | zone1 | 2881 | YES | ACTIVE | 2024-04-09 17:47:47.849965 | NULL | NULL | 2024-04-09 17:47:42.054759 | 2024-04-09 17:47:48.850012 | 4.3.0.1_100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9(Mar 22 2024 13:19:48) | NULL | | 10.10.10.2 | 2882 | 2 | zone2 | 2881 | NO | ACTIVE | 2024-04-09 17:47:47.749100 | NULL | NULL | 2024-04-09 17:47:42.173519 | 2024-04-09 17:47:48.850012 | 4.3.0.1_100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9(Mar 22 2024 13:19:48) | NULL | | 10.10.10.3 | 2882 | 3 | zone3 | 2881 | NO | ACTIVE | 2024-04-09 17:47:47.490511 | NULL | NULL | 2024-04-09 17:47:42.567437 | 2024-04-09 17:47:48.850012 | 4.3.0.1_100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9(Mar 22 2024 13:19:48) | NULL | | 10.10.10.4 | 2882 | 4 | zone1 | 2881 | NO | ACTIVE | 2024-04-10 10:37:47.530894 | NULL | NULL | 2024-04-09 10:27:32.222980 | 2024-04-09 17:47:48.850012 | 4.3.0.1_100000242024032211-0193a343bc60b4699ec47792c3fc4ce166a182f9(Mar 22 2024 13:19:48) | NULL | +------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+-------------------+执行如下命令查看 obshell 管理的 OBServer 节点。
obclient [oceanbase]> select * from ocs.all_agent;输出如下:
+------------+------+---------------+----------------------+-------+--------------+-------+------------+----------+--------------------------+------------------------------------------------------------------------------------------------------+ | ip | port | identity | version | os | architecture | zone | mysql_port | rpc_port | home_path | public_key | +------------+------+---------------+----------------------+-------+--------------+-------+------------+----------+--------------------------+------------------------------------------------------------------------------------------------------+ | 10.10.10.1 | 2886 | CLUSTER AGENT | 4.2.3.0-102024031414 | linux | x86_64 | zone1 | 2881 | 2882 | /home/admin/oceanbase-ce | MEgCQQCfqaND/dAbH/cJhOuTP8gRUBZh1nqrNtFwB9Plw6YwWiSintZPiC9pN/FKlBeR/Klt2jvu8oqZe+S3p/xq+ckPAgMBAAE= | | 10.10.10.2 | 2886 | CLUSTER AGENT | 4.2.3.0-102024031414 | linux | x86_64 | zone2 | 2881 | 2882 | /home/admin/oceanbase-ce | MEgCQQCfqaND/dAbH/cJhOuTP8gRUBZh1nqrNtFwB9Plw6YwWiSintZPiC9pN/FKlBeR/Klt2jvu8oqZe+S3p/xq+ckPAgMBAAE= | | 10.10.10.3 | 2886 | CLUSTER AGENT | 4.2.3.0-102024031414 | linux | x86_64 | zone3 | 2881 | 2882 | /home/admin/oceanbase-ce | MEgCQQCfqaND/dAbH/cJhOuTP8gRUBZh1nqrNtFwB9Plw6YwWiSintZPiC9pN/FKlBeR/Klt2jvu8oqZe+S3p/xq+ckPAgMBAAE= | | 10.10.10.4 | 2886 | CLUSTER AGENT | 4.2.3.0-102024031414 | linux | x86_64 | zone1 | 2881 | 2882 | /home/admin/oceanbase-ce | MEgCQQCfqaND/dAbH/cJhOuTP8gRUBZh1nqrNtFwB9Plw6YwWiSintZPiC9pN/FKlBeR/Klt2jvu8oqZe+S3p/xq+ckPAgMBAAE= | +------------+------+---------------+----------------------+-------+--------------+-------+------------+----------+--------------------------+------------------------------------------------------------------------------------------------------+
如果以上两条命令都能看到新扩容的 OBServer 节点的信息,则说明扩容成功。
步骤 4:租户内资源的扩容
OceanBase 集群扩容成功后,租户内的资源扩容详见 租户内资源扩容和缩容概述。