合 在Docker中快速体验openGauss主备环境数据库
Tags: 高可用openGauss数据库Docker镜像主备环境
- 在Docker中快速体验openGauss数据库:https://www.dbaup.com/zaidockerzhongkuaisutiyanopengaussshujuku.html
- 在CentOS7中安装openGauss数据库单机版:https://www.dbaup.com/zaicentos7zhonganzhuangopengaussshujukudanjiban.html
- PG12高可用之1主2从流复制环境搭建及切换测试:https://www.dbaup.com/dbbao60pg12gaokeyongzhi1zhu2congliufuzhihuanjingdajianjiqiehuanceshi.html
- 安装openGauss极简版单节点和一主一备节点环境:https://www.dbaup.com/anzhuangopengaussjijianbandanjiedianheyizhuyibeijiedianhuanjing.html
参考:
https://hub.docker.com/r/enmotech/opengauss
创建主从复制的openGauss容器
- 拉取容器镜像
- 运行脚本create_master_slave.sh,按照提示输入所需参数,或者直接使用默认值,即可自动创建openGauss一主一备架构的两个容器。
上述脚本有多个自定义参数,以下为这些参数的参数名称(解释)[默认值]。
OG_SUBNET (容器所在网段) [172.11.0.0/24]
GS_PASSWORD (定义数据库密码)[Enmo@123]
MASTER_IP (主库IP)[172.11.0.101]
SLAVE_1_IP (备库IP)[172.11.0.102]
MASTER_HOST_PORT (主库数据库服务端口)[5432]
MASTER_LOCAL_PORT (主库通信端口)[5434]
SLAVE_1_HOST_PORT (备库数据库服务端口)[6432]
SLAVE_1_LOCAL_PORT (备库通信端口)[6434]
MASTER_NODENAME (主节点名称)[opengauss_master]
SLAVE_NODENAME (备节点名称)[opengauss_slave1]
使用示例
拉取镜像
1 | docker pull enmotech/opengauss:latest |
获取创建主备容器脚本并运行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | wget https://raw.githubusercontent.com/enmotech/enmotech-docker-opengauss/master/create_master_slave.sh chmod +x create_master_slave.sh docker network rm opengaussnetwork # 全部回车默认,最后版本的地方输入 latest [root@docker35 ~]# chmod +x create_master_slave.sh [root@docker35 ~]# ./create_master_slave.sh Please input OG_SUBNET (容器所在网段) [172.11.0.0/24]: OG_SUBNET set 172.11.0.0/24 Please input GS_PASSWORD (定义数据库密码)[Enmo@123]: GS_PASSWORD set Enmo@123 Please input MASTER_IP (主库IP)[172.11.0.101]: MASTER_IP set 172.11.0.101 Please input SLAVE_1_IP (备库IP)[172.11.0.102]: SLAVE_1_IP set 172.11.0.102 Please input MASTER_HOST_PORT (主库数据库服务端口)[5432]: MASTER_HOST_PORT set 5432 Please input MASTER_LOCAL_PORT (主库通信端口)[5434]: MASTER_LOCAL_PORT set 5434 Please input SLAVE_1_HOST_PORT (备库数据库服务端口)[6432]: SLAVE_1_HOST_PORT set 6432 Please input SLAVE_1_LOCAL_PORT (备库通信端口)[6434]: SLAVE_1_LOCAL_PORT set 6434 Please input MASTER_NODENAME [opengauss_master]: MASTER_NODENAME set opengauss_master Please input SLAVE_NODENAME [opengauss_slave1]: SLAVE_NODENAME set opengauss_slave1 Please input openGauss VERSION [1.1.0]: latest openGauss VERSION set latest starting cf57b86811530658bafb592d3427bd0058a590bcbf9169607d2f83446c3b1a83 OpenGauss Database Network Created. 2d78115504cf26d5074d0a85112f34425531abcbd26c099b40f4f480c73f351a OpenGauss Database Master Docker Container created. 1a485df6d6a885cb427262727560509148f5fb3744dc58f358f6968b391be4e1 OpenGauss Database Slave1 Docker Container created. |
验证主备状态
主库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # docker exec -it opengauss_master /bin/bash # su - omm omm@opengauss_master:~$ gs_ctl status -D /var/lib/opengauss/data/ [2022-01-07 04:09:26.656][354][][gs_ctl]: gs_ctl status,datadir is /var/lib/opengauss/data gs_ctl: server is running (PID: 1) /usr/local/opengauss/bin/gaussdb "-M" "primary" omm@opengauss_master:~$ gs_ctl query -D /var/lib/opengauss/data/ [2022-01-07 04:09:43.897][358][][gs_ctl]: gs_ctl query ,datadir is /var/lib/opengauss/data HA state: local_role : Primary static_connections : 1 db_state : Normal detail_information : Normal Senders info: sender_pid : 345 local_role : Primary peer_role : Standby peer_state : Normal state : Streaming sender_sent_location : 0/4000268 sender_write_location : 0/4000268 sender_flush_location : 0/4000268 sender_replay_location : 0/4000268 receiver_received_location : 0/4000268 receiver_write_location : 0/4000268 receiver_flush_location : 0/4000268 receiver_replay_location : 0/4000268 sync_percent : 100% sync_state : Sync sync_priority : 1 sync_most_available : On channel : 172.11.0.101:5434-->172.11.0.102:49112 Receiver info: No information |
备库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # docker exec -it opengauss_slave1 /bin/bash # su - omm omm@opengauss_slave1:/var/lib/opengauss/data$ gs_ctl status -D /var/lib/opengauss/data/ [2022-01-07 04:08:49.365][365][][gs_ctl]: gs_ctl status,datadir is /var/lib/opengauss/data gs_ctl: server is running (PID: 1) /usr/local/opengauss/bin/gaussdb "-M" "standby" omm@opengauss_slave1:~$ omm@opengauss_slave1:~$ gs_ctl query -D /var/lib/opengauss/data/ [2022-01-07 04:10:29.842][374][][gs_ctl]: gs_ctl query ,datadir is /var/lib/opengauss/data HA state: local_role : Standby static_connections : 1 db_state : Normal detail_information : Normal Senders info: No information Receiver info: receiver_pid : 360 local_role : Standby peer_role : Primary peer_state : Normal state : Normal sender_sent_location : 0/4000268 sender_write_location : 0/4000268 sender_flush_location : 0/4000268 sender_replay_location : 0/4000268 receiver_received_location : 0/4000268 receiver_write_location : 0/4000268 receiver_flush_location : 0/4000268 receiver_replay_location : 0/4000268 sync_percent : 100% channel : 172.11.0.102:49112<--172.11.0.101:5434 |