【参赛作品66】快速搭建一套openGauss主备高可用集群
作者:Sally
openGauss是一款开源关系型数据库管理系统,采用木兰宽松许可证v2发行。openGauss内核早期源自PostgreSQL,深度融合华为在数据库领域多年的经验,结合企业级场景需求,持续构建竞争力特性。同时openGauss也是一个开源、免费的数据库平台,鼓励社区贡献、合作。
今天无意看到恩墨开源团队发布了openGauss新的容器镜像,此版本镜像还支持创建主从复制的openGauss高可用集群。
本篇文件记录快速部署的主从复制的openGauss高可用集群的过程以及中间遇到的问题,希望对学习openGauss的同学有所帮助。
参考dockerhub网址:https://hub.docker.com/r/enmotech/opengauss
基础环境准备
[[email protected] ~]# cat /etc/system-release
Oracle Linux Server release 7.9
[[email protected] ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
scan: Docker Scan (Docker Inc., v0.8.0)
Server:
Containers: 48
Running: 0
Paused: 0
Stopped: 48
Images: 18
Server Version: 20.10.7
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: false
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 5.4.17-2102.201.3.el7uek.x86_64
Operating System: Oracle Linux Server 7.9
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 4.268GiB
Name: hhj
ID: HHHZ:DPVB:WA2L:J5BI:D4Q6:YMH4:NQEQ:WS4M:A6KP:R3JC:L6EW:LS6V
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
192.168.56.102:5000
127.0.0.0/8
Registry Mirrors:
https://1nj0zren.mirror.aliyuncs.com/
https://docker.mirrors.ustc.edu.cn/
http://f1361db2.m.daocloud.io/
https://registry.docker-cn.com/
Live Restore Enabled: false
快速拉取openGauss最新镜像
[[email protected] ~]# docker pull enmotech/opengauss:latest
latest: Pulling from enmotech/opengauss
Digest: sha256:d5a3e38fa2553a44e7fa1cd5cad0b4f0845a679858764067d7b0052a228578a0
Status: Image is up to date for enmotech/opengauss:latest
docker.io/enmotech/opengauss:latest
修改openGauss的镜像标签
注意:不修改标签在启动容器时会报找不到镜像
[[email protected] ~]# docker tag enmotech/opengauss:latest opengauss:latest
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
enmotech/opengauss latest b4dd24d09223 2 months ago 383MB
opengauss latest b4dd24d09223 2 months ago 383MB
获取创建主备容器脚本并运行
[[email protected] ~]# # wget https://raw.githubusercontent.com/enmotech/enmotech-docker-opengauss/master/create_master_slave.sh
[[email protected] ~]## chmod +x create_master_slave.sh
[[email protected] ~]# ./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 (定义数据库密码)[[email protected]]:
GS_PASSWORD set [email protected]
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.0.1]: latest
openGauss VERSION set latest
starting
13b4cf3a545cdc51539b2f4e6b227536cacd5caa764a167701927d7a6cbd21e5
OpenGauss Database Network Created.
85c9894a167ca992c237900bb27ed50c8ffb323217de6c1011614f5a67f8dcd6
OpenGauss Database Master Docker Container created.
e3fbdd36d6203a34051eea9d6a756d404528a0dcdca169aa2be42502a45d3087
OpenGauss Database Slave1 Docker Container created.
注意如果遇到容器存在或者网络存在可以如下删除
[[email protected] ~]# docker rm opengauss_master
opengauss_master
[r[email protected] ~]# docker network rm opengaussnetwork
opengaussnetwork
验证openGauss主备集群状态
查看容器启动情况
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e3fbdd36d620 opengauss:latest "entrypoint.sh -M st…" 13 seconds ago Up 12 seconds 5432/tcp, 0.0.0.0:6432->6432/tcp, :::6432->6432/tcp opengauss_slave1
85c9894a167c opengauss:latest "entrypoint.sh -M pr…" 46 seconds ago Up 43 seconds 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp opengauss_master
进入openGauss主库
[[email protected] ~]# docker exec -it opengauss_master bash
[email protected]_master:/# su - omm
[email protected]_master:~$ gsql
gsql ((openGauss 2.1.0 build 590b0f8e) compiled at 2021-09-30 14:29:04 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
omm=# l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
omm | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm +
| | | | | omm=CTc/omm
(4 rows)
omm=# q
检查主从情况
[2021-12-19 04:29:35.624][350][][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 : 320
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:38096
Receiver info:
No information
[email protected]_master:~$
[email protected]_master:~$ exit
logout
[email protected]_master:/# exit
exit
进入openGauss从库
[email protected]_slave1:/# su - omm
[email protected]_slave1:~$ gsql -r -p6432
gsql ((openGauss 2.1.0 build 590b0f8e) compiled at 2021-09-30 14:29:04 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
omm=# l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
omm | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm +
| | | | | omm=CTc/omm
(4 rows)
omm=# q
检查主从情况
[email protected]_slave1:~$ gs_ctl query -D /var/lib/opengauss/data/
[2021-12-19 04:31:24.788][361][][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 : 338
local_role : Standby
peer_role : Primary
peer_state : Normal
state : Normal
sender_sent_location : 0/40004A8
sender_write_location : 0/40004A8
sender_flush_location : 0/40004A8
sender_replay_location : 0/40004A8
receiver_received_location : 0/40004A8
receiver_write_location : 0/40004A8
receiver_flush_location : 0/40004A8
receiver_replay_location : 0/40004A8
sync_percent : 100%
channel : 172.11.0.102:38096<--172.11.0.101:5434
[email protected]_slave1:~$ exit
logout
[email protected]_slave1:/# exit
exit
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e3fbdd36d620 opengauss:latest "entrypoint.sh -M st…" 8 minutes ago Up 8 minutes 5432/tcp, 0.0.0.0:6432->6432/tcp, :::6432->6432/tcp opengauss_slave1
85c9894a167c opengauss:latest "entrypoint.sh -M pr…" 9 minutes ago Up 9 minutes 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp opengauss_master
验证openGauss主备集群主从同步
进入主库创建表和插入数据
[[email protected] ~]# docker exec -it opengauss_master bash
[email protected]_master:/# su - omm
[email protected]_master:~$ gsql -r
gsql ((openGauss 2.1.0 build 590b0f8e) compiled at 2021-09-30 14:29:04 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
omm= create table test(id int);
CREATE TABLE
omm=# insert into test values(1);
INSERT 0 1
omm=# insert into test values(2);
INSERT 0 1
omm=# select * from test;
id
----
1
2
(2 rows)
omm=# exit
omm-# q
[email protected]_master:~$ exit
logout
[email protected]_master:/# exit
exit
进入从库验证数据同步
[[email protected] ~]# docker exec -it opengauss_slave1 bash
[email protected]_slave1:/# su - omm
[email protected]_slave1:~$ gsql -r -p 6432
gsql ((openGauss 2.1.0 build 590b0f8e) compiled at 2021-09-30 14:29:04 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
omm=# d
List of relations
Schema | Name | Type | Owner | Storage
--------+------+-------+-------+----------------------------------
public | test | table | omm | {orientation=row,compression=no}
(1 row)
omm=# select * from test;
id
----
1
2
(2 rows)
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
二维码