Initialize an OBServer node by using oatcli

2025-01-26 08:21:59  Updated

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

  1. Connect to the OAT server.

    For example, you can run the following ssh command to connect to the OAT server:

    C:\Users\user001>ssh admin@xxx.xxx.xxx.xxx
    admin@xxx.xxx.xxx.xxx's password:
    
  2. Run the following command to go to the OAT container:

    Note

    To run the following command, you must have the root user permissions.

    docker exec -it oat bash
    

    Here is an example:

    [admin@xxx /home/admin]
    $sudo docker exec -it oat bash
    

    The return result is as follows:

    [root@xxx oat]#
    
  3. (Optional) Run the following command to view how to use oat-cli:

    oatcli --help
    

    For more information about oatcli commands, see oatcli.

    Here is an example:

    [root@xxx oat]# oatcli --help
    

    The 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                                                  │
    ╰─────────────────────────────────────────────────────────────────────────────────────────╯
    
  4. 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.json
    
  5. Create an IDC.

    Run the following command to create the IDC information for the OBServer node:

    oatcli create idc [OPTIONS] NAME REGION
    

    where

    • NAME specifies the IDC name. This parameter is required.
    • REGION specifies 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 hz0 in the hangzhou region.

    [root@xxx oat]# oatcli create idc hz0 hangzhou
    

    The 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'}                                                                           │
    ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
    
  6. 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

    • NAME specifies 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 login.

    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_148 for the root user with password authentication enabled.

    [root@xxx oat]# oatcli create credential -uroot -p****** root_148 password
    

    The 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'                                                                     │
    │ }                                                                                                                        │
    ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
    
  7. 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_148 in the hz0 IDC of the hangzhou region for deploying an OBServer node only.

    [root@xxx oat]# oatcli create server -ihz0:hangzhou -croot_148 xxx.xxx.xxx.2 observer
    

    The 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&region=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}                                                                          │
    │ }                                                                                                                                                    │
    ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
    
  8. Check whether the OBServer node is added.

    View the OBServer node details and related dagrun information.

    oatcli describe server [OPTIONS] IP
    

    where

    IP specifies 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.2
    

    The 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 │
    └───────────────────┴────────────┴─────────────────────────────┴─────────────────────────────┘
    
  9. 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 server
    

    The 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:

References

Contact Us