首批通过分布式安全可靠测评,为关键业务系统打造
使用 oatcli 初始化 OBServer 服务器
更新时间:2025-04-01 11:58:38
oatcli 是管理 OAT 资源的命令行工具,支持使用命令行添加服务器、安装 OceanBase 产品等。
前提条件
- 您已准备 OBServer 服务器并且已完成相关配置。详细信息,请参见 准备服务器 和 服务器配置。
- 您已安装 OAT。详细信息,请参见 部署 OAT。
- 您拥有 OAT 服务器的
root用户权限。
操作步骤
连接到安装 OAT 的服务器。
示例如下:
使用
ssh连接到安装 OAT 的服务器。C:\Users\user001>ssh admin@xxx.xxx.xxx.xxx admin@xxx.xxx.xxx.xxx's password:使用下面命令进入到 OAT 容器。
说明
执行下面命令,需要
root权限。docker exec -it oat bash示例如下:
[admin@xxx /home/admin] $sudo docker exec -it oat bash返回结果:
[root@xxx oat]#(可选)可以使用以下命令查看 oatcli 的使用方法。
oatcli --help更多 oatcli 命令信息,请参见 oatcli。
示例如下:
[root@xxx oat]# oatcli --help返回结果:
Usage: oatcli [OPTIONS] COMMAND [ARGS]... Command line tool for manage OAT resources ╭─ Options ───────────────────────────────────────────────────────────────────────────────╮ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy it or │ │ customize the installation. │ │ --help Show this message and exit. │ ╰─────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ──────────────────────────────────────────────────────────────────────────────╮ │ config Config OAT API Server address, username and password │ │ create Create resource in OAT │ │ dagrun Operate dagrun and task status in OAT │ │ delete Delete resource in OAT │ │ describe Get resource detail info in OAT │ │ get Get resource info in OAT │ ╰─────────────────────────────────────────────────────────────────────────────────────────╯设置 OAT API 地址、用户名和密码来调用 OAT API。
oatcli config set [OPTIONS]选项说明:
-s, --api-server TEXT:api_server,例如:127.0.0.1:7000。-u, --username TEXT:用户名。-p, --password TEXT:密码。--help:显示此消息并退出。
示例如下:
[root@xxx oat]# oatcli config set -sxxx.xxx.xxx.1:7000 -uadmin -p******返回结果:
11:14:16 [INFO] update {'api_server': 'xxx.xxx.xxx.1:7000', 'username': 'admin', 'password': '******'} to /root/.oatcli/config.json创建 机房。
为服务器创建机房信息,方法如下:
oatcli create idc [OPTIONS] NAME REGION参数说明:
NAME:机房名称 [必需]。REGION:机房所在地域 [必需]。
选项说明:
--help:显示此消息并退出。
示例如下:
创建 机房 的名称为
hz0,地域为hangzhou。[root@xxx oat]# oatcli create idc hz0 hangzhou返回结果:
11:20:05 [DEBUG] Starting new HTTP connection (1): xxx.xxx.xxx.1:7000 11:20:05 [DEBUG] http://xxx.xxx.xxx.1:7000 "POST /api/v2/idcs HTTP/1.1" 201 175 ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ {'id': 2, 'name': 'hz0', 'region': 'hangzhou'} │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯创建 凭据。
为服务器连接创建 SSH 凭证,方法如下:
oatcli create credential [OPTIONS] NAME AUTH_TYPE:{password|pubkey|external}参数说明:
NAME:凭证标识名称 [必需]。AUTH_TYPE:{password|pubkey|external}:授权类型 [必需]。password:密码认证。pubkey:公钥认证。external:已配置免密。
选项说明:
-u, --username TEXT:[默认值:root]。-p, --password TEXT:密码。-k, --key-file PATH:SSH 私钥文件。--help:显示此消息并退出。
示例如下:
创建 凭据 的名称为
root_148,用户类型为root用户,授权类型为密码认证。[root@xxx oat]# oatcli create credential -uroot -p****** root_148 password返回结果:
11:39:17 [DEBUG] Starting new HTTP connection (1): xxx.xxx.xxx.1:7000 11:39:17 [DEBUG] http://xxx.xxx.xxx.1:7000 "POST /api/v2/credentials HTTP/1.1" 200 309 ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ { │ │ 'id': 1, │ │ 'servers': [], │ │ 'name': 'root_148', │ │ 'authType': 'password', │ │ 'username': 'root', │ │ 'createTime': '2023-06-19T11:39:17.315921+08:00', │ │ 'updateTime': '2023-06-19T11:39:17.315969+08:00' │ │ } │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯添加 OBServer 服务器(添加并初始化服务器)。
oatcli create server [OPTIONS] IPS... INIT_TAG:{observer|obproduct|both}选项说明:
-i, --idc TEXT:机房名称:地域,必须已经存在 [必需]。-c, --credential-name TEXT:凭证名称,必须已经存在 [必需]。--add-only | --no-add-only:自定义选项,服务器是否初始化配置 [默认值:no-add-only]。--add-only:仅添加服务器,不执行操作系统配置操作。--no-add-only:执行操作系统配置操作。
--ssh-port INTEGER:SSH 端口 [默认值:22]。--docker-root-dir TEXT:[默认路径:/docker]。--admin-uid-gid TEXT:[默认值:500:500]。--admin-password TEXT:密码。--help:显示此消息并退出。
参数说明:
IPS...:服务器 IP [必需]。INIT_TAG:{observer|obproduct|both}:服务器用途 [必需]。observer:安装 OBServer。obproduct:安装 OceanBase 产品服务。both:安装 OBServer 和 OceanBase 产品服务。
示例如下:
添加 OBServer 服务器,使用的 凭据 为
root_148,使用的 机房名称:地域 为hz0:hangzhou,设置 服务器用途 为observer。[root@xxx oat]# oatcli create server -ihz0:hangzhou -croot_148 xxx.xxx.xxx.2 observer返回结果:
13:56:05 [DEBUG] Starting new HTTP connection (1): xxx.xxx.xxx.1:7000 13:56:06 [DEBUG] http://xxx.xxx.xxx.1:7000 "GET /api/v2/credentials?name=root_148 HTTP/1.1" 200 389 13:56:06 [DEBUG] Starting new HTTP connection (1): xxx.xxx.xxx.1:7000 13:56:06 [DEBUG] http://xxx.xxx.xxx.1:7000 "GET /api/v2/idcs?name=hz0®ion=hangzhou HTTP/1.1" 200 255 13:56:06 [DEBUG] Starting new HTTP connection (1): xxx.xxx.xxx.1:7000 13:56:06 [DEBUG] http://xxx.xxx.xxx.1:7000 "POST /api/v2/servers/batchCreate HTTP/1.1" 200 788 ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ { │ │ 'contents': [ │ │ { │ │ 'id': 2, │ │ 'idcInfo': {'id': 2, 'name': 'hz0', 'region': 'hangzhou'}, │ │ 'ip': 'xxx.xxx.xxx.2', │ │ 'sshPort': 22, │ │ 'checkStatus': 'unknown', │ │ 'operateStatus': 'init', │ │ 'description': '', │ │ 'isOio': False, │ │ 'platform': {'system': '', 'node': '', 'release': '', 'version': '', 'machine': ''}, │ │ 'hardware': {'cpu': 0, 'memory': 0, 'disk': 0}, │ │ 'service': {'product': [], 'component': [], 'observer': []}, │ │ 'runtimeInfo': {'dockerRootDir': '/docker', 'adminUidGid': '500:500', 'initTag': ['observer']}, │ │ 'networkInfo': [], │ │ 'createTime': '2023-06-19T13:56:06.839271+08:00', │ │ 'updateTime': '2023-06-19T13:56:06.859580+08:00', │ │ 'relateDagrun': 5, │ │ 'credential': 1 │ │ } │ │ ], │ │ 'page': {'totalElements': 1, 'totalPages': 1, 'number': 1, 'size': 100} │ │ } │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯查看服务器是否添加完成。
查看服务器详细信息和相关的 dagrun 信息。
oatcli describe server [OPTIONS] IP参数说明:
IP:具体服务器 IP [必需]。选项说明:
--help:显示此消息并退出。示例如下:
[root@xxx oat]# oatcli describe server xxx.xxx.xxx.2返回结果:
14:41:01 [DEBUG] Starting new HTTP connection (1): xxx.xxx.xxx.1:7000 14:41:01 [DEBUG] http://xxx.xxx.xxx.1:7000 "GET /api/v2/servers?ip=xxx.xxx.xxx.2 HTTP/1.1" 200 1085 14:41:01 [DEBUG] Starting new HTTP connection (1): xxx.xxx.xxx.1:7000 14:41:01 [DEBUG] http://xxx.xxx.xxx.1:7000 "GET /api/v2/servers/2 HTTP/1.1" 200 998 ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ { │ │ 'id': 2, │ │ 'idcInfo': {'id': 2, 'name': 'hz0', 'region': 'hangzhou'}, │ │ 'ip': 'xxx.xxx.xxx.2', │ │ 'sshPort': 22, │ │ 'checkStatus': 'unknown', │ │ 'operateStatus': 'idle', │ │ 'description': '', │ │ 'isOio': False, │ │ 'platform': { │ │ 'system': 'Linux', │ │ 'node': 'h07g04228.sqa.eu95', │ │ 'release': '3.10.0-327.ali2010.rc7.alios7.x86_64', │ │ 'version': '#1 SMP Thu Jun 29 21:45:21 CST 2017', │ │ 'machine': 'x86_64' │ │ }, │ │ 'hardware': {'cpu': 32, 'memory': 125, 'disk': ''}, │ │ 'service': {'observer': [], 'product': [], 'component': [], 'tool': []}, │ │ 'runtimeInfo': {'dockerRootDir': '/docker', 'adminUidGid': '500:500', 'initTag': ['observer']}, │ │ 'networkInfo': [ │ │ {'nic': 'lo', 'ipWithMask': '127.0.0.1/8'}, │ │ {'nic': 'bond0', 'ipWithMask': 'xxx.xxx.xxx.2/26'}, │ │ {'nic': 'bond0', 'ipWithMask': 'xxx.xxx.xxx.3/26'}, │ │ {'nic': 'docker0', 'ipWithMask': '172.17.0.1/16'} │ │ ], │ │ 'createTime': '2023-06-19T13:56:06.839271+08:00', │ │ 'updateTime': '2023-06-19T14:35:31+08:00', │ │ 'relateDagrun': 5, │ │ 'credential': 1 │ │ } │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ 14:41:01 [DEBUG] Starting new HTTP connection (1): xxx.xxx.xxx.1:7000 14:41:02 [DEBUG] http://xxx.xxx.xxx.1:7000 "GET /api/v2/dagruns/5 HTTP/1.1" 200 2727 14:41:02 [INFO] relate dagrun info: ┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ id ┃ innerState ┃ executeTime ┃ startTime ┃ ┡━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ check_ssh │ success │ 2023-06-19T05:56:06.842182Z │ 2023-06-19T05:56:07.970263Z │ │ create_admin_user │ success │ 2023-06-19T05:56:06.842182Z │ 2023-06-19T05:56:09.060737Z │ │ config_docker │ success │ 2023-06-19T05:56:06.842182Z │ 2023-06-19T05:56:10.319578Z │ │ config_deps │ success │ 2023-06-19T05:56:06.842182Z │ 2023-06-19T05:56:10.319575Z │ │ config_os │ success │ 2023-06-19T05:56:06.842182Z │ 2023-06-19T05:56:10.319600Z │ │ config_chrony │ success │ 2023-06-19T05:56:06.842182Z │ 2023-06-19T05:56:10.319587Z │ │ precheck │ success │ 2023-06-19T05:56:06.842182Z │ 2023-06-19T05:56:23.563900Z │ │ update_server │ success │ 2023-06-19T05:56:06.842182Z │ 2023-06-19T06:35:31.197149Z │ └───────────────────┴────────────┴─────────────────────────────┴─────────────────────────────┘在 OAT 中获取资源信息。
oatcli get [OPTIONS] COMMAND [ARGS]...选项说明:
--help:显示此消息并退出。
命令说明:
component:获取组件信息。credential:获取凭证信息。idc:获取机房信息。image:获取镜像信息。product:获取产品信息。server:获取服务器信息。
示例如下:
获取服务器列表信息。
[root@xxx oat]# oatcli get server返回结果:
14:35:50 [DEBUG] Starting new HTTP connection (1): xxx.xxx.xxx.1:7000 14:35:50 [DEBUG] http://xxx.xxx.xxx.1:7000 "GET /api/v2/servers HTTP/1.1" 200 1085 ┏━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ id ┃ ip ┃ sshPort ┃ idcInfo ┃ description ┃ operateStatus ┃ ┡━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ 2 │ xxx.xxx.xxx.2 │ 22 │ {'id': 2, 'name': 'hz0', 'region': 'hangzhou'} │ │ idle │ └────┴───────────────┴─────────┴────────────────────────────────────────────────┴─────────────┴───────────────┘
后续操作
服务器初始化成功后,您可以根据自己的需求部署 OceanBase 集群: