Docker 部署

为方便用户快速体验,SequoiaDB 巨杉数据库提供基于 Docker 的镜像。本文介绍如何在 Docker 环境下部署 SequoiaDB 分布式集群环境。

集群规划

用户可以在五个容器中部署一个多节点高可用 SequoiaDB 集群。

主机名IP分区组部署软件
Coord 协调节点172.17.0.2:11810SYSCoordSequoiaDB 3.2.1
Catalog编目节点172.17.0.2:11800SYSCatalogGroupSequoiaDB 3.2.1
Data1数据节点1172.17.0.3:11820group1SequoiaDB 3.2.1
Data2数据节点2172.17.0.4:11820group1SequoiaDB 3.2.1
Data3数据节点3172.17.0.5:11820group1SequoiaDB 3.2.1
Data1数据节点2172.17.0.4:11830group2SequoiaDB 3.2.1
Data2数据节点3172.17.0.5:11830group2SequoiaDB 3.2.1
Data3数据节点1172.17.0.3:11830group2SequoiaDB 3.2.1
Data1数据节点3172.17.0.5:11840group3SequoiaDB 3.2.1
Data2数据节点1172.17.0.3:11840group3SequoiaDB 3.2.1
Data3数据节点2172.17.0.4:11840group3SequoiaDB 3.2.1
MySQL实例172.17.0.6:3306-SequoiaSQL-MySQL 3.2.1

集群包含一个协调节点与编目节点,三个三副本数据节点,与一个 MySQL 实例节点。

样例环境

Docker 环境Mac Docker 2.0.0.3
容器操作系统版本Ubuntu 18
数据库版本SequoiaDB 3.2.1
集群部署一个运行协调和编目节点,三个运行数据节点,一个运行 MySQL 实例

Docker 在 Linux/Windows/MacOS 平台安装方法可参考官方文档。

对于 Linux 环境可参考本样例安装 Docker 环境。

  1. $ apt-get install -y docker.io

拉取镜像

  1. $ docker pull sequoiadb/sequoiadb
  2. $ docker pull sequoiadb/sequoiasql-mysql

启动四个 SequoiaDB 容器

  1. $ docker run -it -d --name coord_catalog sequoiadb/sequoiadb:latest
  2. $ docker run -it -d --name sdb_data1 sequoiadb/sequoiadb:latest
  3. $ docker run -it -d --name sdb_data2 sequoiadb/sequoiadb:latest
  4. $ docker run -it -d --name sdb_data3 sequoiadb/sequoiadb:latest

查看四个容器的容器 ID

  1. $ docker ps -a | awk '{print $NF}';

运行结果:

  1. NAMES
  2. sdb_data3
  3. sdb_data2
  4. sdb_data1
  5. coord_catalog

查看四个容器的容器对应的 IP 地址

  1. $ docker inspect coord_catalog | grep IPAddress |awk 'NR==2 {print $0}'
  2. $ docker inspect sdb_data1 | grep IPAddress |awk 'NR==2 {print $0}'
  3. $ docker inspect sdb_data2 | grep IPAddress |awk 'NR==2 {print $0}'
  4. $ docker inspect sdb_data3 | grep IPAddress |awk 'NR==2 {print $0}'

四条命令的输出结果分别为各个容器自身的 IP 地址:

  1. "IPAddress": "172.17.0.2",
  2. "IPAddress": "172.17.0.3",
  3. "IPAddress": "172.17.0.4",
  4. "IPAddress": "172.17.0.5",

部署 SequoiaDB 集群

根据集群规划以及各个容器的 IP 地址,在对应参数填入各自的地址与端口号。

  1. $ docker exec coord_catalog "/init.sh" \
  2. --coord='172.17.0.2:11810' \
  3. --catalog='172.17.0.2:11800' \
  4. --data='group1=172.17.0.3:11820,172.17.0.4:11820,172.17.0.5:11820;group2=172.17.0.4:11830,172.17.0.5:11830,172.17.0.3:11830;group3=172.17.0.5:11840,172.17.0.3:11840,172.17.0.4:11840'

该命令输出结果为:

  1. Begin generating SequoiaDB conf file
  2. Finish generating SequoiaDB conf file
  3. Restarting sdbcm process, it will take 10 seconds
  4. Deploy...
  5. Execute command: /opt/sequoiadb/tools/deploy/../../bin/sdb -f /opt/sequoiadb/tools/deploy/quickDeploy.js -e ''
  6. ************ Deploy SequoiaDB ************************
  7. Create catalog: 172.17.0.2:11800
  8. Create coord: 172.17.0.2:11810
  9. Create data: 172.17.0.3:11820
  10. Create data: 172.17.0.4:11820
  11. Create data: 172.17.0.5:11820
  12. Create data: 172.17.0.4:11830
  13. Create data: 172.17.0.5:11830
  14. Create data: 172.17.0.3:11830
  15. Create data: 172.17.0.5:11840
  16. Create data: 172.17.0.3:11840
  17. Create data: 172.17.0.4:11840

启动一个 MySQL 实例容器

  1. $ docker run -it -d -p 3306:3306 --name mysql sequoiadb/sequoiasql-mysql:latest

查看启动容器的 ID

  1. $ docker ps -a | awk '{print $NF}';

输出结果为包括 MySQL 实例在内的所有容器名:

  1. NAMES
  2. mysql
  3. sdb_data3
  4. sdb_data2
  5. sdb_data1
  6. coord_catalog

查看容器 IP 地址

  1. $ docker inspect mysql | grep IPAddress | awk 'NR==2 {print $0}'

输出结果为 MySQL 实例的 IP 地址:

  1. "IPAddress": "172.17.0.6",

将 MySQL 实例注册入协调节点

  1. $ docker exec mysql "/init.sh" --port=3306 --coord='172.17.0.2:11810'

输出结果为:

  1. Creating SequoiaSQL instance: MySQLInstance
  2. Modify configuration file and restart the instance: MySQLInstance
  3. Restarting instance: MySQLInstance
  4. Opening remote access to user root
  5. Restarting instance: MySQLInstance
  6. Instance MySQLInstance is created on port 3306, default user is root

本地登陆 MySQL 测试

  1. $ mysql -h 127.0.0.1 -P 3306 -u root

可以得到 MySQL 连接成功的输出:

  1. Welcome to the MySQL monitor. Commands end with ; or \g.
  2. Your MySQL connection id is 2
  3. Server version: 5.7.25 Source distribution
  4. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  5. Oracle is a registered trademark of Oracle Corporation and/or its
  6. affiliates. Other names may be trademarks of their respective
  7. owners.
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

用户可以使用 MySQL 命令创建数据库与表:

  1. mysql> create database sample;
  2. Query OK, 1 row affected (0.00 sec)
  3. mysql> use sample;
  4. Database changed
  5. mysql> create table t1 (c1 int);
  6. Query OK, 0 rows affected (0.59 sec)
  7. mysql> show table status;
  8. +------+-----------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+-------------+-------------+------------+-------------+----------+----------------+---------+
  9. | Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
  10. +------+-----------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+-------------+-------------+------------+-------------+----------+----------------+---------+
  11. | t1 | SequoiaDB | 10 | Fixed | 0 | 0 | 0 | 8796093022208 | 131072 | 0 | NULL | NULL | NULL | NULL | utf8mb4_bin | NULL | | |
  12. +------+-----------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+-------------+-------------+------------+-------------+----------+----------------+---------+
  13. 1 row in set (0.16 sec)

重置镜像

为方便用户重置已经创建了数据库节点的容器,用户可以使用 cleanup.sh 脚本进行本地容器的重置。

  1. $ docker exec mysql /cleanup.sh
  2. $ docker exec coord_catalog /cleanup.sh
  3. $ docker exec sdb_data1 /cleanup.sh
  4. $ docker exec sdb_data2 /cleanup.sh
  5. $ docker exec sdb_data3 /cleanup.sh

Note:
该集群仅为测试使用,不可直接应用于生产环境。