高可用容灾环境部署
更新时间:2024-07-01 14:39:42
AntDB 数据库采用复制组多副本架构,保证数据库的高可用性。同时,AntDB 支持单机、机房和城市级别的容灾,提供双中心部署方案。用户可根据机房配置和容灾需求,选择合适的方案进行部署。
本章所述的双中心集群结构如下:
主中心:一主两备
备中心:一主两备
两者关系:备中心的主是主中心主节点的异步备
主中心部署
参考【高可用集群模式部署】搭建一主两备高可用集群。
搭建完成,集群如下所示:
adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml list
+ Cluster: antdbcluster (7308609900027656685) ---+---------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+------------+--------------------+--------------+---------+----+-----------+
| adbhamgr-1 | 10.21.10.222:6655 | Leader | running | 2 | |
| adbhamgr-2 | 10.21.10.223:6655 | Sync Standby | running | 2 | 0 |
| adbhamgr-3 | 10.21.10.224:6655 | Replica | running | 2 | 0 |
+------------+--------------------+--------------+---------+----+-----------+
备中心部署
一键式部署
参考【高可用集群模式部署】,搭建一主两备高可用集群,方法和搭建主中心一致。
例如,集群如下所示,此时主备中心是两个独立的集群。
adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml list
+ Cluster: antdbcluster (7234420149554224469) ---+---------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+------------+--------------------+--------------+---------+----+-----------+
| adbhamgr-1 | 10.1.206.202:55551 | Leader | running | 2 | |
| adbhamgr-2 | 10.1.206.213:55551 | Sync Standby | running | 2 | 0 |
| adbhamgr-3 | 10.1.206.226:55551 | Replica | running | 2 | 0 |
+------------+--------------------+--------------+---------+----+-----------+
停止备中心
停止 adbhamgr 服务(所有节点都要执行):
sudo systemctl stop adbhamgr
使用 adbhamgr 的 remove 命令清理集群数据(一个节点执行即可):
# remove后跟的参数“antdbcluster”为集群名称
[antdb@localhost ~]$ adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml remove antdbcluster
+ Cluster: antdbcluster (7240007647780694395) -------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-----------+--------------------+---------+---------+----+-----------+
| adbhamgr-3 | 10.1.206.226:55551 | Replica | stopped | | unknown |
+-----------+--------------------+---------+---------+----+-----------+
Please confirm the cluster name to remove: antdbcluster
You are about to remove all information in DCS for antdbcluster, please type: "Yes I am aware": Yes I am aware
重建备中心
步骤一:修改主中心的 hba 文件
重建备中心需要执行 adb_basebackup 命令,因此需要配置 hba,从而允许备机通过流复制连接到主节点。
1、修改主节点的 pg_hba.conf 文件,例如:
host replication all 0.0.0.0/0 trust
2、reload 主节点,使配置生效;
adb_ctl reload -D /home/antdb/data
步骤二:主中心的主节点创建复制槽(可选)
# 记录下创建的复制槽名称为adbhamgr(自定义)
select pg_create_physical_replication_slot('adbhamgr', true);
步骤三:重建备中心(每个节点都执行,操作一样)
下面以数据目录 /home/antdb/data/ 为例。
1、清理数据目录;
rm -rf /home/antdb/data/*
2、修改 adbhamgr 的配置文件;
# 备中心adbhamgr的yml配置文件中bootstrap.dcs下添加 standby_cluster 参数块,如下:
bootstrap:
# this section will be written into adbdcs:/<namespace>/<scope>/config after initializing new cluster
# and all other cluster members will use it as a `global configuration`
dcs:
……
standby_cluster: # 添加standby_cluster参数设置,注意对其格式
host: 10.21.10.222 # 主中心某个节点ip, 执行adb_basebackup和建立流复制的远程节点
port: 6655 # 远程节点的端口
primart_slot_name: adbhamgr # 建立流复制的复制槽,如果使用,需要手动在主中心建立相应的复制槽。(步骤二创建)
create_replica_methods: # 建立基础备份使用的方法,一般为adb_basebackup
- basebackup
注意:host设置的节点与primart_slot_name所在的节点要保持一致。
这里建议设置为主中心的主节点,与上述步骤一、二都是以主中心的主节点操作保持一致。
3、最后,启动各节点的 adbhamgr;
# 启动各节点的adbhamgr:
sudo systemctl start adbhamgr
# 成功后查看集群状态,备中心的主节点为Standby Leader,其余节点都是Replica
[antdb@localhost ~]$ adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml list
+ Cluster: antdbcluster (7240007647780694395) ----+---------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-----------+--------------------+----------------+---------+----+-----------+
| adbhamgr-1 | 10.1.206.202:55551 | Standby Leader | running | 5 | |
| adbhamgr-2 | 10.1.206.213:55551 | Replica | running | 5 | 0 |
| adbhamgr-3 | 10.1.206.226:55551 | Replica | running | 5 | 0 |
+-----------+--------------------+----------------+---------+----+-----------+
# 查看备中心主节点的流复制,可以看到备中心的主节点的流复制源是主中心的主节点
[antdb@localhost ~]$ adb -d antdb -p 55551 -h 10.21.10.222
psql (13.3)
Type "help" for help.
antdb=# \x
Expanded display is on.
antdb=# select * from pg_stat_wal_receiver;
-[ RECORD 1 ]---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pid | 3565881
status | streaming
receive_start_lsn | 0/8000000
receive_start_tli | 5
written_lsn | 0/8000148
flushed_lsn | 0/8000000
received_tli | 5
last_msg_send_time | 2023-06-05 14:46:43.939936+08
last_msg_receipt_time | 2023-06-05 14:45:14.263009+08
latest_end_lsn | 0/8000148
latest_end_time | 2023-06-05 14:02:36.843889+08
slot_name |
sender_host | 10.21.10.211
sender_port | 55551
conninfo | user=replicator passfile=/data/antdb/.pgpass channel_binding=prefer dbname=replication host=10.21.10.211 port=55551 application_name=adbhamgr-1 fallback_application_name=antdbcluster sslmode=prefer sslcompression=0 ssl_min_protocol_version=TLSv1.2 gssencmode=prefer krbsrvname=postgres target_session_attrs=any
# 查看备中心备节点的流复制,可以看到备中心的备节点的流复制源是备中心的主节点
antdb=# select * from pg_stat_wal_receiver;
-[ RECORD 1 ]---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pid | 866301
status | streaming
receive_start_lsn | 0/8000000
receive_start_tli | 5
written_lsn | 0/8000148
flushed_lsn | 0/8000000
received_tli | 5
last_msg_send_time | 2023-06-05 14:46:38.010682+08
last_msg_receipt_time | 2023-06-05 14:46:37.350915+08
latest_end_lsn | 0/8000148
latest_end_time | 2023-06-05 14:01:34.527452+08
slot_name | adbhamgr_2
sender_host | 10.1.206.202
sender_port | 55551
conninfo | user=replicator passfile=/data/antdb/.pgpass channel_binding=prefer dbname=replication host=10.1.206.202 port=55551 application_name=adbhamgr-2 fallback_application_name=antdbcluster sslmode=prefer sslcompression=0 ssl_min_protocol_version=TLSv1.2 gssencmode=prefer krbsrvname=postgres target_session_attrs=any
问题反馈