oatcli is a command-line tool for managing OAT resources. You can use it to add servers and install OceanBase products.
Prerequisites
- You have prepared an OBServer node and completed the relevant configuration. For more information, see Prepare the servers and Configure the servers.
- You have installed OAT. For more information, see Deploy OAT.
- You have the
rootuser permissions on the OAT server.
Procedure
Connect to the server where OAT is installed.
Here is an example:
Use the
sshcommand to connect to the server where OAT is installed.C:\Users\user001>ssh admin@xxx.xxx.xxx.xxx admin@xxx.xxx.xxx.xxx's password:Enter the OAT container.
Note
To run the following command, you need to obtain the
rootprivileges.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 the usage of oat-cli.
oatcli --helpHere 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 OAT API address, username, and password to call the OAT API.
oatcli config set [OPTIONS]The options are described as follows:
-s, --api-server TEXT: the API server address, for example, 127.0.0.1:7000.-u, --username TEXT: the username.-p, --password TEXT: the password.--help: display this message and exit.
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 a DC.
Create the DC information for a server as follows:
oatcli create idc [OPTIONS] NAME REGIONThe parameters are described as follows:
NAME: the name of the DC [mandatory].REGION: the region where the DC is located [mandatory].
The options are described as follows:
--help: display this message and exit.
Here is an example:
Create a DC 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 a credential.
Create an SSH credential for connecting to a server as follows:
oatcli create credential [OPTIONS] NAME AUTH_TYPE:{password|pubkey|external}The parameters are described as follows:
NAME: the name of the credential [mandatory].AUTH_TYPE:{password|pubkey|external}: the authentication type [mandatory].password: password authentication.pubkey: public key authentication.external: password-free authentication has been configured.
The options are described as follows:
-u, --username TEXT: [default value: root].-p, --password TEXT: the password.-k, --key-file PATH: the path of the private SSH key file.--help: display this message and exit.
Here is an example:
Create a credential named
root_148, whose user type isroot, and whose authentication type is password authentication.[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 an OBServer server (add and initialize the server).
oatcli create server [OPTIONS] IPS... INIT_TAG:{observer|obproduct|both}The options are described as follows:
-i, --idc TEXT: the name of the DC:region, which must already exist [mandatory].-c, --credential-name TEXT: the name of the credential, which must already exist [mandatory].--add-only | --no-add-only: a custom option indicating whether to initialize the server configuration [default value: --no-add-only].--add-only: add the server without performing operating system configuration.--no-add-only: perform operating system configuration.
--ssh-port INTEGER: the SSH port [default value: 22].--docker-root-dir TEXT: [default path: /docker].--admin-uid-gid TEXT: [default value: 500:500].--admin-password TEXT: the password.--help: display this message and exit.
The parameters are described as follows:
IPS...: the IP addresses of the server [mandatory].INIT_TAG:{observer|obproduct|both}: the purpose of the server [mandatory].observer: install OBServer.obproduct: install OceanBase product services.both: install OBServer and OceanBase product services.
Here is an example:
Add an OBServer server, using the credential
root_148and the DC name:regionhz0:hangzhou, and set the purpose of the server toobserver.[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 server has been added.
View the details of the server and the related dagrun information.
oatcli describe server [OPTIONS] IPThe parameters are described as follows:
IP: the IP address of the server [mandatory].The options are described as follows:
--help: display this message and exit.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: display this message and exit.
The commands are described as follows:
component: get component information.credential: get credential information.idc: get DC information.image: get image information.product: get product information.server: get server information.
Here is an example:
Obtain the server list information.
[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 │ └────┴───────────────┴─────────┴────────────────────────────────────────────────┴─────────────┴───────────────┘
Next steps
After the server is initialized, you can deploy an OceanBase cluster according to your business requirements:
- Deploy an OceanBase cluster with two replicas and arbitration by using the CLI
- Deploy an OceanBase cluster with one replica by using the CLI
- Deploy an OceanBase cluster with three replicas by using the CLI