---
title: "使用 oatcli 初始化 OBServer 服务器 - OceanBase 数据库 V4.6.0 | OceanBase 文档中心"
description: 使用 oatcli 初始化 OBServer 服务器 oatcli 是管理 OAT 资源的命令行工具，支持使用命令行添加服务器、安装 OceanBase 产品等。 前提条件 您已准备 OBServer 服务器并且已完成相关配置。详细信息，请参见 准备服务器 和 服务器配置 。 您已安装 OAT。详细信息，请参见 部署…
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*P8CuR4UJ_FkAAAAAAAAAAAAADiGDAQ/original) OceanBase 数据库分布式版 - V 4.6.0

# 使用 oatcli 初始化 OBServer 服务器

更新时间：2026-07-05 12:37:38

[编辑](https://github.com/oceanbase/oceanbase-doc/edit/V4.6.0/zh-CN/400.deploy/300.deploy-oceanbase-enterprise-edition/400.deploy-through-the-command-line/100.configure-a-deployment-environment-command-line/100.initializing-the-observer-server-using-oatcli.md)  

oatcli 是管理 OAT 资源的命令行工具，支持使用命令行添加服务器、安装 OceanBase 产品等。

## 前提条件

- 您已准备 OBServer 服务器并且已完成相关配置。详细信息，请参见 [准备服务器](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000005682296) 和 [服务器配置](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000005682297)。
 - 您已安装 OAT。详细信息，请参见 [部署 OAT](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000005682299)。
 - 您拥有 OAT 服务器的 `root` 用户权限。

## 操作步骤

1. 连接到安装 OAT 的服务器。

   示例如下：

   使用 `ssh` 连接到安装 OAT 的服务器。

   ```shell
   C:\Users\user001>ssh admin@xxx.xxx.xxx.xxx
   admin@xxx.xxx.xxx.xxx's password:

   ```
 2. 使用下面命令进入到 OAT 容器。

   #### 说明

   执行下面命令，需要 `root` 权限。

   ```shell
   docker exec -it oat bash

   ```

   示例如下：

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

   ```

   返回结果：

   ```shell
   [root@xxx oat]#

   ```
 3. （可选）可以使用以下命令查看 oatcli 的使用方法。

   ```shell
   oatcli --help

   ```

   更多 oatcli 命令信息，请参见 [oatcli](https://www.oceanbase.com/docs/enterprise-oat-doc-cn-10000000002024800)。

   示例如下：

   ```shell
   [root@xxx oat]# oatcli --help

   ```

   返回结果：

   ```shell
   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. 设置 OAT API 地址、用户名和密码来调用 OAT API。

   ```shell
   oatcli config set [OPTIONS]

   ```

   选项说明：

      - `-s, --api-server TEXT`：api_server，例如：127.0.0.1:7000。
      - `-u, --username TEXT`：用户名。
      - `-p, --password TEXT`：密码。
      - `--help`：显示此消息并退出。

   示例如下：

   ```shell
   [root@xxx oat]# oatcli config set -sxxx.xxx.xxx.1:7000 -uadmin -p******

   ```

   返回结果：

   ```shell
   11:14:16 [INFO] update {'api_server': 'xxx.xxx.xxx.1:7000', 'username': 'admin', 'password': '******'} to /root/.oatcli/config.json

   ```
 5. 创建 **机房**。

   为服务器创建机房信息，方法如下：

   ```shell
   oatcli create idc [OPTIONS] NAME REGION

   ```

   参数说明：

      - `NAME`：机房名称 [必需]。
      - `REGION`：机房所在地域 [必需]。

   选项说明：

      - `--help`：显示此消息并退出。

   示例如下：

   创建 **机房** 的名称为 `hz0`，地域为 `hangzhou`。

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

   ```

   返回结果：

   ```shell
   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. 创建 **凭据**。

   为服务器连接创建 SSH 凭证，方法如下：

   ```shell
   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` 用户，授权类型为密码认证。

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

   ```

   返回结果：

   ```shell
   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. 添加 OBServer 服务器（添加并初始化服务器）。

   ```shell
   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`。

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

   ```

   返回结果：

   ```shell
   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. 查看服务器是否添加完成。

   查看服务器详细信息和相关的 dagrun 信息。

   ```shell
   oatcli describe server [OPTIONS] IP

   ```

   参数说明：

   `IP`：具体服务器 IP [必需]。

   选项说明：

   `--help`：显示此消息并退出。

   示例如下：

   ```shell
   [root@xxx oat]# oatcli describe server xxx.xxx.xxx.2

   ```

   返回结果：

   ```shell
   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. 在 OAT 中获取资源信息。

   ```shell
   oatcli get [OPTIONS] COMMAND [ARGS]...

   ```

   选项说明：

   命令说明：

      - `component`：获取组件信息。
      - `credential`：获取凭证信息。
      - `idc`：获取机房信息。
      - `image`：获取镜像信息。
      - `product`：获取产品信息。
      - `server`：获取服务器信息。

   示例如下：

   获取服务器列表信息。

   ```shell
   [root@xxx oat]# oatcli get server

   ```

   返回结果：

   ```shell
   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 集群：

- [使用命令行部署两副本加仲裁服务的 OceanBase 集群](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000005682847)
 - [使用命令行部署单副本 OceanBase 集群](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000005682849)
 - [使用命令行部署三副本 OceanBase 集群](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000005682848)

## 相关文档

- [准备服务器](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000005682296)
 - [部署 OAT](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000005682299)
 - [oatcli](https://www.oceanbase.com/docs/enterprise-oat-doc-cn-10000000002024800)

 上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
