oatcli is a CLI tool for managing OceanBase Admin Toolkit (OAT) resources. oatcli allows you to add servers and install OceanBase products by using commands.
Prerequisites
- You have prepared and configured OBServer nodes. For more information, see Prepare servers and Configure a server.
- You have installed OAT. For more information, see Deploy OAT.
- You have the root user permissions on the OAT server.
Procedure
Connect to the OAT server.
For example, you can run the following
sshcommand to connect to the OAT server:C:\Users\user001>ssh admin@xxx.xxx.xxx.xxx admin@xxx.xxx.xxx.xxx's password:Run the following command to go to the OAT container:
Note
To run the following command, you must have the
rootuser permissions.docker exec -it oat bashHere is an example:
[admin@xxx /home/admin] $sudo docker exec -it oat bashThe return result is as follows:
[root@xxx oat]#(Optional) Run the following command to view how to use oat-cli:
oatcli --helpFor more information about oatcli commands, see oatcli.
Here is an example:
[root@xxx oat]# oatcli --helpThe return result is as follows:
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 │ ╰─────────────────────────────────────────────────────────────────────────────────────────╯Set the address, username, and password for calling the OAT API.
oatcli config set [OPTIONS]The options are described as follows:
-s, --api-server TEXT: the IP address of the API server, such as 127.0.0.1:7000.-u, --username TEXT: the username.-p, --password TEXT: the password.--help: shows the help message and exits.
Here is an example:
[root@xxx oat]# oatcli config set -sxxx.xxx.xxx.1:7000 -uadmin -p******The return result is as follows:
11:14:16 [INFO] update {'api_server': 'xxx.xxx.xxx.1:7000', 'username': 'admin', 'password': '******'} to /root/.oatcli/config.jsonCreate an IDC.
Run the following command to create the IDC information for the OBServer node:
oatcli create idc [OPTIONS] NAME REGIONwhere
NAMEspecifies the IDC name. This parameter is required.REGIONspecifies the region of the IDC. This parameter is required.
The options are described as follows:
--help: shows the help message and exits.
Here is an example:
Create an IDC named
hz0in thehangzhouregion.[root@xxx oat]# oatcli create idc hz0 hangzhouThe return result is as follows:
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'} │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯Create credentials.
Run the following command to create SSH credentials for the server connection:
oatcli create credential [OPTIONS] NAME AUTH_TYPE:{password|pubkey|external}where
NAMEspecifies the name of the credential. This parameter is required.AUTH_TYPE:{password|pubkey|external}specifies the authorization type. This parameter is required.password: the password for authentication.pubkey: the public key for authentication.external: specifies to enable password-free logon.
The options are described as follows:
-u, --username TEXT: the username. The default value is root.-p, --password TEXT: the password.-k, --key-file PATH: the SSH private key file.--help: shows the help message and exits.
Here is an example:
Create a credential named
root_148for the root user with password authentication enabled.[root@xxx oat]# oatcli create credential -uroot -p****** root_148 passwordThe return result is as follows:
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' │ │ } │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯Add and initialize a server for adding an OBServer node.
oatcli create server [OPTIONS] IPS... INIT_TAG:{observer|obproduct|both}The options are described as follows:
-i, --idc TEXT: the IDC name and region. The IDC must already exist. This field is required.-c, --credential-name TEXT: the name of the credential. The credential must already exist. This field is required.--add-only | --no-add-only: specifies whether to initialize the server. The default value is no-add-only. Valid values include:--add-only: specifies to only add the server and not to configure the operating system.--no-add-only: specifies to configure the operating system.
--ssh-port INTEGER: the SSH port. The default value is 22.--docker-root-dir TEXT: the docker root directory. The default path is/docker.--admin-uid-gid TEXT: the UID and GID of the admin user. The default value is 500:500.--admin-password TEXT: the admin password.--help: shows the help message and exits.
The parameters are described as follows:
IPS...: the IP address of the server. This parameter is required.INIT_TAG:{observer|obproduct|both}: the purpose of the server. This parameter is required. Valid values include:observer: installs OBServer.obproduct: installs OceanBase services other than OBServer.both: installs both OBServer and other OceanBase services.
Here is an example:
Add a server with the credential named
root_148in thehz0IDC of thehangzhouregion for deploying an OBServer node only.[root@xxx oat]# oatcli create server -ihz0:hangzhou -croot_148 xxx.xxx.xxx.2 observerThe return result is as follows:
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} │ │ } │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯Check whether the OBServer node is added.
View the OBServer node details and related dagrun information.
oatcli describe server [OPTIONS] IPwhere
IPspecifies the IP address of the OBServer node. This parameter is required.The options are described as follows:
--help: shows the help message and exits.Here is an example:
[root@xxx oat]# oatcli describe server xxx.xxx.xxx.2The return result is as follows:
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 │ └───────────────────┴────────────┴─────────────────────────────┴─────────────────────────────┘Obtain resource information in OAT.
oatcli get [OPTIONS] COMMAND [ARGS]...The options are described as follows:
--help: shows the help message and exits.
The parameters are described as follows:
component: queries the component information.credential: queries the credential information.idc: queries the IDC information.image: queries the image information.product: queries the product information.server: queries the OBServer node information.
Here is an example:
Obtain the list of OBServer nodes.
[root@xxx oat]# oatcli get serverThe return result is as follows:
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 │ └────┴───────────────┴─────────┴────────────────────────────────────────────────┴─────────────┴───────────────┘
What to do next
After the OBServer node is initialized, you can deploy the OceanBase cluster by using the following methods:
- Deploy a standalone OceanBase database by using the CLI
- Deploy a two-replica OceanBase cluster with an arbitration member by using the CLI
- Deploy a single-replica OceanBase cluster by using the CLI
- Deploy a three-replica OceanBase cluster by using the CLI