暂无图片
暂无图片
2
暂无图片
暂无图片
暂无图片

openGauss1.0.1支持docker主备搭建

原创 多米爸比 2020-10-24
1347

目前已经支持x86-64和ARM64两种架构。
x86-64架构的openGauss运行在CentOS 7.6操作系统中
ARM64架构的openGauss运行在openEuler 20.03 LTS操作系统中

1. 快速搭建环境

pull镜像文件

docker pull enmotech/opengauss:1.0.1

创建自定义网络,创建容器便于使用固定IP

docker network create --subnet=172.18.0.0/16 myNetwork

创建主库容器并运行

docker run --name op_master \
--network myNetwork --ip 172.18.0.10 --privileged=true \
--hostname op_master --detach \
--env GS_PORT=6432 \
--env OG_SUBNET=172.18.0.0/16 \
--env GS_PASSWORD=Enmotech@1234 \
--env NODE_NAME=op_master \
--env REPL_CONN_INFO="replconninfo1 = 'localhost=172.18.0.10 localport=6439 localservice=6432 remotehost=172.18.0.11 remoteport=6439 remoteservice=6432 '\n" \
enmotech/opengauss:1.0.1 -M primary

创建备库容器并运行

docker run --name op_slave_one \
--network myNetwork --ip 172.18.0.11 --privileged=true \
--hostname op_slave_one --detach \
--env GS_PORT=6432 \
--env OG_SUBNET=172.18.0.0/16 \
--env GS_PASSWORD=Enmotech@1234 \
--env NODE_NAME=op_slave_one \
--env REPL_CONN_INFO="replconninfo1 = 'localhost=172.18.0.11 localport=6439 localservice=6432 remotehost=172.18.0.10 remoteport=6439 remoteservice=6432 '\n" \
enmotech/opengauss:1.0.1 -M standby

说明:也可参考官方镜像脚本来创建
localport与localservice端口间隔要大于2,对外映射端口为localservice

2. 查询主备角色状态

查询命令

gs_ctl query -D /var/lib/opengauss/data/

主库op_master查询

docker exec -it op_master bash

[omm@op_master ~]$ gs_ctl query -D /var/lib/opengauss/data/
[2020-10-20 13:50:39.163][666][][gs_ctl]: gs_ctl query ,datadir is -D "/var/lib/opengauss/data"  
 HA state:           
	local_role                     : Primary
	static_connections             : 1
	db_state                       : Normal
	detail_information             : Normal

 Senders info:       
	sender_pid                     : 637
	local_role                     : Primary
	peer_role                      : Standby
	peer_state                     : Normal
	state                          : Streaming
	sender_sent_location           : 0/5000238
	sender_write_location          : 0/5000238
	sender_flush_location          : 0/5000238
	sender_replay_location         : 0/5000238
	receiver_received_location     : 0/5000238
	receiver_write_location        : 0/5000238
	receiver_flush_location        : 0/5000238
	receiver_replay_location       : 0/5000238
	sync_percent                   : 100%
	sync_state                     : Sync
	sync_priority                  : 1
	sync_most_available            : On
	channel                        : 172.18.0.10:6439-->172.18.0.11:55440

 Receiver info:      
No information 

备库op_slave_one查询

docker exec -it op_slave_one bash

[omm@op_slave_one ~]$ gs_ctl query -D /var/lib/opengauss/data/
[2020-10-20 13:51:24.640][460][][gs_ctl]: gs_ctl query ,datadir is -D "/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                   : 401
	local_role                     : Standby
	peer_role                      : Primary
	peer_state                     : Normal
	state                          : Normal
	sender_sent_location           : 0/5000238
	sender_write_location          : 0/5000238
	sender_flush_location          : 0/5000238
	sender_replay_location         : 0/5000238
	receiver_received_location     : 0/5000238
	receiver_write_location        : 0/5000238
	receiver_flush_location        : 0/5000238
	receiver_replay_location       : 0/5000238
	sync_percent                   : 100%
	channel                        : 172.18.0.11:55440<--172.18.0.10:6439

说明:从上面主库Senders信息和备库Receiver可以看到主备状态正常

3. 读写及切换测试

主库op_master写测试

[omm@op_master ~]$ gsql -p6432
gsql ((openGauss 1.0.1 build e9da9fb9) compiled at 2020-10-01 20:21:42 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

omm=# create table t(id json);
CREATE TABLE
omm=# insert into t values('{"name":"Mr.D"}');
INSERT 0 1

备库op_slave_one读测试

[omm@op_slave_one ~]$ gsql -p6432
gsql ((openGauss 1.0.1 build e9da9fb9) compiled at 2020-10-01 20:21:42 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

omm=# select * from t;
       id        
-----------------
 {"name":"Mr.D"}
(1 row)

omm=# delete from t;
ERROR:  cannot execute DELETE in a read-only transaction

切换测试:将op_slave_one 切换为主库,op_master 切换为备库

op_slave_one执行switchover

[omm@op_slave_one ~]$ gs_ctl switchover -D /var/lib/opengauss/data/
[2020-10-20 13:57:02.877][504][][gs_ctl]: gs_ctl switchover ,datadir is -D "/var/lib/opengauss/data"  
[2020-10-20 13:57:02.877][504][][gs_ctl]: switchover term (1)
[2020-10-20 13:57:02.888][504][][gs_ctl]: waiting for server to switchover.........
[2020-10-20 13:57:08.920][504][][gs_ctl]: done
[2020-10-20 13:57:08.920][504][][gs_ctl]: switchover completed (/var/lib/opengauss/data)

op_slave_one查询状态

[omm@op_slave_one ~]$ gs_ctl query -D /var/lib/opengauss/data/
[2020-10-20 13:58:13.340][555][][gs_ctl]: gs_ctl query ,datadir is -D "/var/lib/opengauss/data"  
 HA state:           
	local_role                     : Primary
	static_connections             : 1
	db_state                       : Normal
	detail_information             : Normal

 Senders info:       
	sender_pid                     : 523
	local_role                     : Primary
	peer_role                      : Standby
	peer_state                     : Normal
	state                          : Streaming
	sender_sent_location           : 0/5004A10
	sender_write_location          : 0/5004A10
	sender_flush_location          : 0/5004A10
	sender_replay_location         : 0/5004A10
	receiver_received_location     : 0/5004A10
	receiver_write_location        : 0/5004A10
	receiver_flush_location        : 0/5004A10
	receiver_replay_location       : 0/5004A10
	sync_percent                   : 100%
	sync_state                     : Sync
	sync_priority                  : 1
	sync_most_available            : On
	channel                        : 172.18.0.11:6439-->172.18.0.10:39314

 Receiver info:      
No information   

op_master查询状态

 [omm@op_master ~]$ gs_ctl query -D /var/lib/opengauss/data/
[2020-10-20 13:58:42.827][743][][gs_ctl]: gs_ctl query ,datadir is -D "/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                   : 739
	local_role                     : Standby
	peer_role                      : Primary
	peer_state                     : Normal
	state                          : Normal
	sender_sent_location           : 0/5004A10
	sender_write_location          : 0/5004A10
	sender_flush_location          : 0/5004A10
	sender_replay_location         : 0/5004A10
	receiver_received_location     : 0/5004A10
	receiver_write_location        : 0/5004A10
	receiver_flush_location        : 0/5004A10
	receiver_replay_location       : 0/5004A10
	sync_percent                   : 100%
	channel                        : 172.18.0.10:39314<--172.18.0.11:6439

可以看到 op_master变为备库,op_slave_one变为主库,切换成功。

数据读写验证

主库op_slave_one做写入验证

[omm@op_slave_one ~]$ gsql -p6432
gsql ((openGauss 1.0.1 build e9da9fb9) compiled at 2020-10-01 20:21:42 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

omm=# select * from t;
       id        
-----------------
 {"name":"Mr.D"}
(1 row)

omm=# insert into t values('{"name":"insert from op_slave_one "}');
INSERT 0 1

备库op_master做读取验证

[omm@op_master ~]$ gsql -p6432
gsql ((openGauss 1.0.1 build e9da9fb9) compiled at 2020-10-01 20:21:42 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

omm=# select * from t;
                  id                  
--------------------------------------
 {"name":"Mr.D"}
 {"name":"insert from op_slave_one "}
(2 rows)

omm=# delete from t;
ERROR:  cannot execute DELETE in a read-only transaction

其他平台版本也支持

例如centos arm架构 opengauss 5.0.0版本

docker pull --platform linux/arm64 enmotech/opengauss:5.0.0

docker run --publish 5000:5432 \
--privileged=true --detach --env GS_PASSWORD=Admin@1234 \
--name opengauss5  enmotech/opengauss:5.0.0

更多:opengauss1.0.1部分新特性测试

最后修改时间:2023-04-14 16:21:09
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论