Files
oceanbase/docs/docs-cn/2.quickstart/4.deploy-the-oceanbase-database-by-using-obd.md
2022-02-10 14:51:49 +08:00

235 lines
7.2 KiB
Markdown

使用 OBD 部署 OceanBase 数据库
============================================
本文介绍如何使用 OBD 部署 OceanBase 数据库。
名词解释
-------------------------
* 中控机器
存储 OceanBase 数据库安装包和集群配置信息的机器。
* 目标机器
安装 OceanBase 数据库的机器。
前提条件
-------------------------
在连接 OceanBase 数据库之前,请您确认以下信息:
* 您已经在中控机器安装了 OBD。详细信息,参考 [安装 OBD](../2.quickstart/3.use-obd-to-obtain-the-oceanbase-database.md)。
* 您已经在目标机器安装了 OceanBase 数据库。
* 您已经在中控机器安装了 OceanBase 数据库的客户端 OBClient。详细信息,参考 [OBClient 文档](https://github.com/oceanbase/obclient/blob/master/README.md)。
修改配置文件
---------------------------
1. 从 GitHub 上下载对应的配置文件模板。
如果您采用本地安装,即中控机器和目标机器是同一台机器,请下载 [本地安装配置文件](https://github.com/oceanbase/obdeploy/blob/master/example/mini-single-example.yaml)。
如果您采用单机安装,即中控机器和目标机器不是同一台机器,且目标机器只有一台,请下载 [单机安装配置文件](https://github.com/oceanbase/obdeploy/blob/master/example/mini-local-example.yaml)。
如果您采用分布式安装,即中控机器和目标机器不是同一台机器,且目标机器有多台,请下载 [分布式安装配置文件](https://github.com/oceanbase/obdeploy/blob/master/example/mini-distributed-example.yaml)。
**注意**
此处以本地安装为例,介绍如何修改配置文件。您必须按照您的安装方式选择对应的配置文件模板。
2. 在配置文件顶部添加用户密码信息。
```yaml
user:
username: <您的账号名>
password: <您的登录密码>
key_file: <您的私钥路径>
```
其中,`username` 为登录到目标机器的用户名,确保您的用户名有 observer 进程工作目录 `home_path` 的权限。
**注意**
通常情况下,您只能使用登录密码或者私钥登录中的一种方式目标机器。
3. 修改配置文件中的 IP 地址。
```yaml
oceanbase-ce:
servers:
- name: z1
# Please don't use hostname, only IP can be supported
ip: 11.166.80.01
```
4. 修改配置文件中的 `devname` 变量和 `home_path`。
```yaml
oceanbase-ce:
global:
home_path: <your_observer_work_path>
# Please set devname as the network adaptor's name whose ip is in the setting of severs.
# if set severs as "127.0.0.1", please set devname as "lo"
# if current ip is 192.168.1.10, and the ip's network adaptor's name is "eth0", please use "eth0"
devname: bond0
```
**注意**
您需要拥有 `home_path` 目录的权限。
启动 OceanBase 数据库
-------------------------------------
1. 运行以下命令部署集群:
```bash
obd cluster deploy <deploy_name> -c <deploy_config_path>
```
其中,`deploy_name` 为集群名称。一个集群只能有一个名称,且集群名称不能重复。
2. 运行以下命令启动集群:
```bash
obd cluster start <deploy_name>
```
3. 运行以下命令查看集群状态:
```bash
obd cluster display <deploy_name>
```
连接 OceanBase 数据库
-------------------------------------
按照以下步骤连接 OceanBase 数据库:
1. 安装 OceanBase 数据库客户端 OBClient:
如您的机器已添加 OceanBase 官方 YUM 源作为软件源,使用以下命令直接安装:
```unknow
sudo yum install -y obclient
```
否则您需要在机器上准备好离线安装包,并执行以下命令安装:
```unknow
sudo yum install -y libobclient-2.0.0-2.el7.x86_64.rpm
sudo yum install -y obclient-2.0.0-2.el7.x86_64.rpm
```
**注意**
您必须首先下载 OBClient 的依赖包 LibOBClient。示例中的安装包可能不是最新版本,建议您下载最新的安装包。详细信息,参考 [下载中心](https://open.oceanbase.com/softwareCenter/community)。
2. 运行以下命令,使用 OBClient 客户端连接 OceanBase 数据库:
```unknow
obclient -h<your_ip> -P<observer_mysql_port> -uroot
```
其中,`your_ip` 为您 OceanBase 实例所在的机器 IP 地址。`observer` 默认使用端口 `2881` 连接 OBClient。如果您对端口做了更改,此处使用您实际的端口号。
返回以下信息:
```unknow
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 3221546072
Server version: 5.7.25 OceanBase 3.1.0 (r1-) (Built Apr 7 2021 08:14:49)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
```
(可选)验证集群
-----------------------------
连接 OceanBase 数据库,运行以下命令验证集群:
```sql
MySQL [oceanbase]> USE oceanbase;
MySQL [oceanbase]> SELECT * FROM __all_server;
```
返回以下结果:
```sql
+----------------------------+----------------------------+---------------+----------+----+-------+------------+-----------------+--------+-----------------------+--------------------------------+-----------+--------------------+--------------+----------------+-------------------+
| gmt_create | gmt_modified | svr_ip | svr_port | id | zone | inner_port | with_rootserver | status | block_migrate_in_time | build_version | stop_time | start_service_time | first_sessid | with_partition | last_offline_time |
+----------------------------+----------------------------+---------------+----------+----+-------+------------+-----------------+--------+-----------------------+--------------------------------+-----------+--------------------+--------------+----------------+-------------------+
| 2021-04-21 10:59:04.967158 | 2021-04-21 10:59:20.344774 | 11.166.80.01 | 2882 | 1 | zone1 | 2881 | 1 | active | 0 | 3.1.0_1-(Apr 7 2021 08:14:49) | 0 | 1618973957346877 | 0 | 1 | 0 |
| 2021-04-21 10:59:04.956632 | 2021-04-21 10:59:20.223340 | 11.166.80.02 | 2882 | 2 | zone2 | 2881 | 0 | active | 0 | 3.1.0_1-(Apr 7 2021 08:14:49) | 0 | 1618973958225270 | 0 | 1 | 0 |
| 2021-04-21 10:59:03.956853 | 2021-04-21 10:59:22.415147 | 11.166.81.103 | 2882 | 3 | zone3 | 2881 | 0 | active | 0 | 3.1.0_1-(Apr 7 2021 08:14:49) | 0 | 1618973958416271 | 0 | 1 | 0 |
+----------------------------+----------------------------+---------------+----------+----+-------+------------+-----------------+--------+-----------------------+--------------------------------+-----------+--------------------+--------------+----------------+-------------------+
3 rows in set (0.00 sec)
```
以上返回结果说明集群部署成功。