KingbaseES V9集群部署案例之---docker构建主备流复制
案例说明:
KingbaseES V9通过docker构建主备流复制架构集群,本案例中主备库容器位于同一个宿主机。
适用版本:
KingbaseES V9
主备流复制集群架构:
一、加载docker镜像
1、下载KES docker镜像
https://download.kingbase.com.cn/xzzx/index.htm
2、启动docker服务
# docker版本
[root@node203 ~]# docker -v
Docker version 26.1.4, build 5650f9b
#启动docker服务
[root@node203 soft]# systemctl start docker
[root@node203 soft]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@node203 soft]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2024-12-12 11:08:56 CST; 12s ago
Docs: https://docs.docker.com
Main PID: 14272 (dockerd)
CGroup: /system.slice/docker.service
└─14272 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Dec 12 11:08:53 node203 systemd[1]: Starting Docker Application Container Engine...
.......
Dec 12 11:08:56 node203 systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
3、加载KES镜像
[root@node202 soft]# ls -lh
total 711M
-rw-r--r-- 1 root root 711M Dec 10 14:56 kdb_x86_64_V009R001C002B0014.tar
-rw-r--r-- 1 root root 2.7K Dec 10 14:56 license_企业版.zip
drwxr-xr-x 2 kingbase kingbase 91 Dec 3 11:32 v9
[root@node202 soft]# docker load -i kdb_x86_64_V009R001C002B0014.tar
96723fcc60ed: Loading layer [==================================================>] 309.9MB/309.9MB
3a1017d60ea0: Loading layer [==================================================>] 22.53kB/22.53kB
cd099deb41d7: Loading layer [==================================================>] 7.168kB/7.168kB
c248d1eae5c2: Loading layer [==================================================>] 8.192kB/8.192kB
73aa8302d2a6: Loading layer [==================================================>] 8.704kB/8.704kB
2c81354f8940: Loading layer [==================================================>] 434.5MB/434.5MB
6348b464ae81: Loading layer [==================================================>] 8.192kB/8.192kB
d7ab7cc989d0: Loading layer [==================================================>] 5.632kB/5.632kB
acf47021abde: Loading layer [==================================================>] 3.072kB/3.072kB
73096ce7f3fd: Loading layer [==================================================>] 5.12kB/5.12kB
Loaded image: kingbase_v009r001c002b0014_single_x86:v1
[root@node202 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
kingbase_v009r001c002b0014_single_x86 v1 a12899877a42 2 months ago 733MB
二、启动KES container(主库primary)
1、启动容器参数说明
docker run -idt --privileged
-p ${hostport}:${containerport} \
–v ${hostpath}:${containerpath} \
-e NEED_START=${need_start} \
-e DB_USER=${username} \
-e DB_PASSWORD=${passwd} \
-e DB_MODE=${dbmode} \
-e ENCODING=${encoding} \
--name kingbase kingbase:v1 \
/usr/sbin/init
数据库默认用户名:system 数据库默认密码:12345678ab
数据库默认data目录:/home/kingbase/userdata/data
金仓数据库镜像:kingbase:v1
-p 建立端口映射(左边为主库端口,右边是容器内数据库端口)
设置数据库data目录的持久化路径时, 需要如下设置:
-v 选项冒号左侧宿主机挂载目录(e.g /mnt/data)权限需要设置755的权限(chmod -R 755 /mnt/data),不然会报权限(Permission denied)错误。
-v 选项冒号右侧为容器内的挂载路径需要设置为/home/kingbase/userdata,不然data目录无法持久化。
2、建立primary container
# 建立主机映射目录
[kingbase@node202 ~]$ mkdir -p /home/kingbase/db/docker/data
# 建立container
[root@node202 soft]# docker run -tid --privileged \
> -p 4321:54321 \
> -v /home/kingbase/db/docker/data:/home/kingbase/userdata/ \
> -e NEED_START=yes \
> -e DB_USER=kingbase \
> -e DB_PASSWORD=123456 \
> -e DB_MODE=oracle \
> --name kingbase \
> kingbase_v009r001c002b0014_single_x86:v1 /usr/sbin/init
ce7b304ac8975864cc05cd16680ef8a817f5be1f5d679d17cbae258d05336d6b
3、查看container信息
[root@node202 soft]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ce7b304ac897 kingbase_v009r001c002b0014_single_x86:v1 "/bin/bash /home/kin…" 4 minutes ago Up About a minute 0.0.0.0:4321->54321/tcp, :::4321->54321/tcp kingbase
# 主机映射端口信息
[root@node202 soft]# netstat -antlp |grep 4321
tcp 0 0 0.0.0.0:4321 0.0.0.0:* LISTEN 18318/docker-proxy
tcp6 0 0 :::4321 :::* LISTEN 18322/docker-proxy
# 启动数据库服务
[root@node202 soft]# docker start kingbase
kingbase
[root@node202 soft]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ce7b304ac897 kingbase_v009r001c002b0014_single_x86:v1 "/bin/bash /home/kin…" About an hour ago Up About an hour 0.0.0.0:4321->54321/tcp, :::4321->54321/tcp kingbase
如下所示,容器名称及端口映射信息:
三、访问数据库container
1、访问容器数据库
[root@node202 soft]# docker exec -it kingbase /bin/bash
Welcome to 3.10.0-1160.118.1.el7.x86_64
System information as of time: Tue 10 Dec 2024 08:39:12 AM UTC
System load: 0.24
Processes: 19
Memory used: 14.8%
Swap used: 0.1%
Usage On: 43%
Users online: 0
# 容器内数据库进程
[kingbase@ce7b304ac897 ~]$ ps -ef |grep kingbase
kingbase 1 0 0 07:33 pts/0 00:00:00 /bin/bash /home/kingbase/docker-entrypoint.sh /usr/sbin/init
kingbase 107 1 0 07:34 ? 00:00:00 /home/kingbase/install/kingbase/bin/kingbase -D /home/kingbase/userdata/data
kingbase 108 107 0 07:34 ? 00:00:00 kingbase: logger
kingbase 110 107 0 07:34 ? 00:00:00 kingbase: checkpointer
kingbase 111 107 0 07:34 ? 00:00:00 kingbase: background writer
kingbase 112 107 0 07:34 ? 00:00:00 kingbase: walwriter
kingbase 113 107 0 07:34 ? 00:00:00 kingbase: autovacuum launcher
kingbase 114 107 0 07:34 ? 00:00:00 kingbase: archiver last was 000000010000000000000004
kingbase 115 107 0 07:34 ? 00:00:00 kingbase: stats collector
kingbase 116 107 0 07:34 ? 00:00:00 kingbase: kwr collector
kingbase 117 107 0 07:34 ? 00:00:00 kingbase: ksh writer
kingbase 118 107 0 07:34 ? 00:00:00 kingbase: ksh collector
kingbase 119 107 0 07:34 ? 00:00:00 kingbase: logical replication launcher
# 访问数据库
[kingbase@ce7b304ac897 ~]$ ksql -U kingbase -W test
Password:
Type "help" for help.
test=#
# 免密访问数据库
[kingbase@ce7b304ac897 ~]$ ksql
Type "help" for help.
kingbase=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
kingbase | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
security | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/kingbase +
| | | | | kingbase=CTc/kingbase
template1 | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/kingbase +
| | | | | kingbase=CTc/kingbase
test | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(5 rows)
kingbase=# create database prod;
CREATE DATABASE
kingbase=# \c prod
You are now connected to database "prod" as userName "kingbase".
# 创建测试数据
prod=# create table t1(id int,name varchar(20));
CREATE TABLE
prod=# insert into t1 values(generate_series(1,1000),'usr'||generate_series(1,1000));
INSERT 0 1000
prod=# select count(*) from t1;
count
-------
1000
(1 row)
2、查看宿主机存储
如下所示,宿主机和容器数据库存储建立映射后,容器数据库数据保存在宿主机目录,保证容器内数据存储持久性:
[root@node202 ~]# cd /home/kingbase/db/docker/data/data/
[root@node202 data]# ls -lh
total 76K
drwx------ 8 admin admin 74 Dec 10 16:40 base
-rw------- 1 admin admin 46 Dec 10 15:34 current_logfiles
drwx------ 2 admin admin 4.0K Dec 10 16:40 global
-rw------- 1 admin admin 338 Dec 10 15:33 initdb.conf
-rw------- 1 admin admin 88 Dec 10 15:33 kingbase.auto.conf
-rw------- 1 admin admin 28K Dec 10 15:34 kingbase.conf
-rw------- 1 admin admin 81 Dec 10 15:34 kingbase.opts
-rw------- 1 admin admin 86 Dec 10 15:34 kingbase.pid
-rw------- 1 admin admin 806 Dec 10 15:34 logfile
drwx------ 3 admin admin 18 Dec 10 15:33 sys_aud
drwx------ 2 admin admin 6 Dec 10 15:33 sys_bulkload
drwx------ 2 admin admin 6 Dec 10 15:33 sys_commit_ts
.......
3、查看数据库license信息
[kingbase@ce7b304ac897 ~]$ ls -lh /home/kingbase/install/kingbase/bin/license.dat
lrwxrwxrwx 1 kingbase kingbase 47 Dec 10 07:34 /home/kingbase/install/kingbase/bin/license.dat -> /home/kingbase/install/kingbase/etc/license.dat
4、宿主机访问容器数据库
如下所示,宿主机通过主机ip和端口映射访问容器数据库:
[root@node202 bin]# ./ksql -U kingbase test -p 4321 -h 192.168.1.202
Password for user kingbase:
Type "help" for help.
test=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
kingbase | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
prod | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
security | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/kingbase +
| | | | | kingbase=CTc/kingbase
template1 | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/kingbase +
| | | | | kingbase=CTc/kingbase
test | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(6 rows)
test=# \c prod
You are now connected to database "prod" as userName "kingbase".
prod=# select count(*) from t1;
count
-------
1000
(1 row)
四、配置流复制(primary)
1、编辑sys_hba.conf
如下所示,增加流复制认证条目:
host replication all 0.0.0.0/0 scram-sha-256
2、创建replication用户
[kingbase@ce7b304ac897 data]$ ksql
Type "help" for help.
kingbase=# create user esrep with replication;
CREATE ROLE
kingbase=# alter user esrep with password '123456';
ALTER ROLE
kingbase=# \du esrep
List of roles
Role name | Attributes | Member of
-----------+-------------+-----------
esrep | Replication | {}
[kingbase@ce7b304ac897 data]$ ksql -U esrep -W test
Password:
Type "help" for help.
五、建立备库container
1、创建备库容器
[root@node202 data]# docker run -tid --privileged \
> -p 5321:54321 \
> -v /home/kingbase/db/docker/data1:/home/kingbase/userdata/ \
> -e NEED_START=yes \
> -e DB_USER=kingbase \
> -e DB_PASSWORD=123456 \
> -e DB_MODE=oracle \
> --name kingbase01 \
> kingbase_v009r001c002b0014_single_x86:v1 /usr/sbin/init
c2b6235b29e1b6cd20b7b6159084cb3218081b50e54ffcf66c4030be4334d76f
如下所示,需创建和主库容器不同的端口和存储的映射:
2、查看及访问备库容器
# 启动备库容器
[root@node202 data]# docker start kingbase01
kingbase01
[root@node202 soft]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c2b6235b29e1 kingbase_v009r001c002b0014_single_x86:v1 "/bin/bash /home/kin…" 3 minutes ago Up 32 seconds 0.0.0.0:5321->54321/tcp, :::5321->54321/tcp kingbase01
ce7b304ac897 kingbase_v009r001c002b0014_single_x86:v1 "/bin/bash /home/kin…" 2 hours ago Up About an hour 0.0.0.0:4321->54321/tcp, :::4321->54321/tcp kingbase
# 访问备库容器
[root@node202 data]# docker exec -it kingbase01 /bin/bash
Welcome to 3.10.0-1160.118.1.el7.x86_64
09:52:07 AM UTC
System load: 0.72
Processes: 19
Memory used: 16.8%
Swap used: 0.1%
Usage On: 46%
Users online: 0
# 查看数据库进程
[kingbase@c2b6235b29e1 ~]$ ps -ef |grep kingbase
kingbase 1 0 0 09:50 pts/0 00:00:00 /bin/bash /home/kingbase/docker-entrypoint.sh /usr/sbin/init
kingbase 107 1 0 09:50 ? 00:00:00 /home/kingbase/install/kingbase/bin/kingbase -D /home/kingbase/userdata/data
kingbase 108 107 0 09:50 ? 00:00:00 kingbase: logger
kingbase 110 107 0 09:50 ? 00:00:00 kingbase: checkpointer
kingbase 111 107 0 09:50 ? 00:00:00 kingbase: background writer
kingbase 112 107 0 09:50 ? 00:00:00 kingbase: walwriter
kingbase 113 107 0 09:50 ? 00:00:00 kingbase: autovacuum launcher
kingbase 114 107 0 09:50 ? 00:00:00 kingbase: archiver last was 000000010000000000000004
kingbase 115 107 0 09:50 ? 00:00:00 kingbase: stats collector
kingbase 116 107 0 09:50 ? 00:00:00 kingbase: kwr collector
kingbase 117 107 0 09:50 ? 00:00:00 kingbase: ksh writer
kingbase 118 107 0 09:50 ? 00:00:00 kingbase: ksh collector
kingbase 119 107 0 09:50 ? 00:00:00 kingbase: logical replication launcher
[kingbase@c2b6235b29e1 ~]$ ksql
Type "help" for help.
kingbase=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
kingbase | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
security | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/kingbase +
| | | | | kingbase=CTc/kingbase
template1 | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/kingbase +
| | | | | kingbase=CTc/kingbase
test | kingbase | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(5 rows)
六、备库执行clone
1、关闭备库数据服务并将data目录备份
[kingbase@ce7b304ac897 ~]$ sys_ctl stop -D /home/kingbase/userdata/data
waiting for server to shut down.... done
server stopped
[kingbase@c2b6235b29e1 ~]$ cd /home/kingbase/userdata/
[kingbase@c2b6235b29e1 userdata]$ ls
data etc
[kingbase@c2b6235b29e1 userdata]$ mv data data.bk
2、在备库执行sys_basebackup克隆
[kingbase@c2b6235b29e1 ~]$ sys_basebackup -U kingbase -Fp -X stream -v -P -h 192.168.1.202 -p 4321 -D /home/kingbase/userdata/data
Password:
sys_basebackup: initiating base backup, waiting for checkpoint to complete
sys_basebackup: checkpoint completed
sys_basebackup: write-ahead log start point: 0/8000058 on timeline 1
sys_basebackup: starting background WAL receiver
sys_basebackup: created temporary replication slot "sys_basebackup_500"
89276/89276 kB (100%), 1/1 tablespace
sys_basebackup: write-ahead log end point: 0/8000158
sys_basebackup: waiting for background process to finish streaming ...
sys_basebackup: syncing data to disk ...
sys_basebackup: base backup completed
如下所示,sys_basebackup通过主机ip和主库映射端口访问主库容器数据库:
3、配置备库kingbase.auto.conf
[kingbase@c2b6235b29e1 data]$ cat kingbase.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
primary_conninfo = 'user=esrep password=123456 connect_timeout=10 host=192.168.1.202 port=4321 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000 application_name=node2'
primary_slot_name = 'repmgr_slot_2'
如下所示:在备库kingbase.auto.conf中配置流复制用户及密码,使用主机ip和主库端口映射建立连接,并配置复制槽:
4、在主库容器创建复制槽
kingbase=# select * from sys_replication_slots;
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | res
tart_lsn | confirmed_flush_lsn
-----------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+----
---------+---------------------
(0 rows)
# 创建物理复制槽
kingbase=# select sys_create_physical_replication_slot('repmgr_slot_2');
sys_create_physical_replication_slot
--------------------------------------
(repmgr_slot_2,)
(1 row)
kingbase=# select * from sys_replication_slots;
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin |
restart_lsn | confirmed_flush_lsn
---------------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+
-------------+---------------------
repmgr_slot_2 | | physical | | | f | f | | | |
|
(1 row)
七、测试主备流复制
1、启动备库容器数据库服务
[kingbase@c2b6235b29e1 data]$ sys_ctl start -D /home/kingbase/userdata/data
waiting for server to start....2024-12-10 10:02:26.147 UTC [207] LOG: config the real archive_command string as soon as possible to archive WAL files
........
server started
# 查看数据库进程
[kingbase@c2b6235b29e1 data]$ ps -ef |grep kingbase
kingbase 1 0 0 09:50 pts/0 00:00:00 /bin/bash /home/kingbase/docker-entrypoint.sh /usr/sbin/init
kingbase 145 1 0 09:50 pts/0 00:00:00 sleep 1000
kingbase 147 0 0 09:52 pts/1 00:00:00 /bin/bash
kingbase 207 0 0 10:02 ? 00:00:00 /home/kingbase/install/kingbase/bin/kingbase -D /home/kingbase/userdata/data
kingbase 208 207 0 10:02 ? 00:00:00 kingbase: logger
kingbase 209 207 0 10:02 ? 00:00:00 kingbase: startup waiting for 000000010000000000000009
kingbase 210 207 0 10:02 ? 00:00:00 kingbase: checkpointer
kingbase 211 207 0 10:02 ? 00:00:00 kingbase: background writer
kingbase 212 207 0 10:02 ? 00:00:00 kingbase: archiver
kingbase 213 207 0 10:02 ? 00:00:00 kingbase: stats collector
2、查看主库流复制信息
如下所示,主备容器之间建立流复制:
kingbase=# select * from sys_stat_replication;
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_star
t | backend_xmin | state | sent_lsn | write_lsn | flush_lsn | replay_lsn | write_lag | flush_lag | r
eplay_lag | sync_priority | sync_state | reply_time
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------------
----------+--------------+-----------+-----------+-----------+-----------+------------+-----------+-----------+--
----------+---------------+------------+-------------------------------
537 | 16388 | esrep | node2 | 172.17.0.1 | | 38899 | 2024-12-10 10:04:57.
298191+00 | | streaming | 0/9000130 | 0/9000130 | 0/9000130 | 0/9000130 | | |
| 0 | async | 2024-12-10 10:05:10.020295+00
(1 row)
kingbase=# select * from sys_replication_slots;
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin |
restart_lsn | confirmed_flush_lsn
---------------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+
-------------+---------------------
repmgr_slot_2 | | physical | | | f | t | 165 | | |
0/90001A8 |
(1 row)
3、备库查看数据同步
1)主库执行事务
prod=# create table t2 as select * from t1;
SELECT 1000
prod=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------------------+-------+----------
public | sys_stat_statements | view | kingbase
public | sys_stat_statements_all | view | kingbase
public | t1 | table | kingbase
public | t2 | table | kingbase
(4 rows)
2)备库查看数据
如下所示,备库和主库的数据已经同步:
prod=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------------------+-------+----------
public | sys_stat_statements | view | kingbase
public | sys_stat_statements_all | view | kingbase
public | t1 | table | kingbase
public | t2 | table | kingbase
(4 rows)
prod=# select count(*) from t2;
count
-------
1000
(1 row)
4、通过宿主机访问容器数据库
1)查看主库信息
2)查看备库信息
七、查看docker网络配置
1、查看当前运行的container
[root@node202 16384]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PO RTS NAMES
c2b6235b29e1 kingbase_v009r001c002b0014_single_x86:v1 "/bin/bash /home/kin…" 20 hours ago Up 3 hours 0. 0.0.0:5321->54321/tcp, :::5321->54321/tcp kingbase01
ce7b304ac897 kingbase_v009r001c002b0014_single_x86:v1 "/bin/bash /home/kin…" 23 hours ago Up 3 hours 0. 0.0.0:4321->54321/tcp, :::4321->54321/tcp kingbase
2、查看宿主机网络
[root@node202 16384]# docker network ls
NETWORK ID NAME DRIVER SCOPE
30ce81d99d24 bridge bridge local
1a6c228c55c9 host host local
c443f3100c38 none null local
3、查看bridge网络配置
如下所示,主机docker网卡信息,主备容器kingbase和kingbase01通过主机bridge建立网络通讯:
[root@node202 16384]# docker network inspect bridge
[
{
"Name": "bridge",
"Id": "30ce81d99d2480136d0f35492b118edb37f4d6b65a62e61e1d6749193a7ba119",
"Created": "2024-12-11T10:28:53.565903952+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"c2b6235b29e1b6cd20b7b6159084cb3218081b50e54ffcf66c4030be4334d76f": {
"Name": "kingbase01",
"EndpointID": "d2083cde6a24e8e6a54ae2304f27b329ff3ba3aa5a7a4cca6ca5f7d6b5fa8ddb",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
},
"ce7b304ac8975864cc05cd16680ef8a817f5be1f5d679d17cbae258d05336d6b": {
"Name": "kingbase",
"EndpointID": "085dedbce7ce979b5b141ecd2d7698cd0fa4dec529fd38db6c5b2599a3f92abe",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
4、测试网络连通性
如下所示,在宿主机可以ping通容器网络:
[root@node202 16384]# ping 172.17.0.3
PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.064 ms
64 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.066 ms
......
--- 172.17.0.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.064/0.065/0.066/0.001 ms
[root@node202 16384]# ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.097 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.042 ms
64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.046 ms
......
--- 172.17.0.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.042/0.061/0.097/0.026 ms
八、总结
本案例通过docker方式架构了KES的主备流复制集群,可以用于docker部署集群的参考,在单主机架构下,docker之间通过bridge网络模式通讯。