postgresql 高可用 repmgr 的使用之十一 1 Primary + 3 Standby + 1 Witness
os: ubuntu 16.04
db: postgresql 9.6.8
repmgr: 4.2
ip 规划如下
192.168.56.94 witness1
192.168.56.92 node1
192.168.56.90 node2
192.168.56.88 node3
192.168.56.86 node4
1 Primary + 3 Standby + 1 Witness 具备 location 划分,高可用更上一层楼,如下图
datanode 节点 witness 节点 os 设置
参考<<ubuntu 16.04 安装 postgresql 的优化设置>>
datanode 节点安装 postgresql 9.6 软件
参考<<ubuntu 16.04 + apt/make + postgresql 11>>
datanode 节点安装 repmgr 软件
参考<<postgresql 高可用 repmgr 的使用之一 apt install repmgr>>
datanode 节点配置/etc/repmgr.conf 文件
参考<<postgresql 高可用 repmgr 的使用之七 /etc/repmgr.conf>>
datanode 节点添加 Primary Standby
参考<<postgresql 高可用 repmgr 的使用之三 1 Primary + 1 Standby 安装>>
启用 repmgrd,注册 1个 Primary 和 3 个 Standby
配置好后的结果如下:
[email protected]:~$ repmgr -f /etc/repmgr.conf cluster show;
ID | Name | Role | Status | Upstream | Location | Connection string
----+-------+---------+-----------+----------+----------+--------------------------------------------------------------------------------------
1 | node1 | primary | * running | | default | host=192.168.56.92 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2
2 | node2 | standby | running | node1 | default | host=192.168.56.90 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2
3 | node3 | standby | running | node1 | default | host=192.168.56.88 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2
4 | node4 | standby | running | node1 | default | host=192.168.56.86 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2
[email protected]:~$ repmgr -f /etc/repmgr.conf daemon status;
ID | Name | Role | Status | repmgrd | PID | Paused?
----+-------+---------+---------+---------+------+---------
1 | node1 | primary | running | running | 1887 | no
2 | node2 | standby | running | running | 1880 | no
3 | node3 | standby | running | running | 1872 | no
4 | node4 | standby | running | running | 1874 | no
至此 1 Primary + 3 Standby 已经配置好,接下来进行 witness 操作.
witness1 节点操作
witness1 节点同样需要安装 postgresql 9.6, repmgr 4.2 软件,但是witness是运行在一个独立的master上(也就是要在 witness1 节点上创建一个新的postgresql master)
在witness1节点上创建 postgresql,为省事,直接从 node1 节点拉一个,然后 promote 一下.
$ repmgr -f /etc/repmgr.conf -h 192.168.56.92 -U repmgr -d repmgr -D /data/pg9.6/main standby clone --dry-run
$ repmgr -f /etc/repmgr.conf -h 192.168.56.92 -U repmgr -d repmgr -D /data/pg9.6/main standby clone
$ rm -f /data/pg9.6/main/recovery.conf
$ sudo /usr/bin/pg_ctlcluster 9.6 main start
$ psql repmgr -c "drop extension repmgr;"
$ psql repmgr -c "drop schema repmgr;"
初始化witness
$ repmgr -f /etc/repmgr.conf -h 192.168.56.92 -U repmgr -d repmgr witness register
INFO: connecting to witness node "witness1" (ID: 11)
INFO: connecting to primary node
NOTICE: attempting to install extension "repmgr"
NOTICE: "repmgr" extension successfully installed
INFO: witness registration complete
NOTICE: witness node "witness1" (ID: 11) successfully registered
操作成功.
这个时候再执行 cluster show
$ repmgr -f /etc/repmgr.conf cluster show
ID | Name | Role | Status | Upstream | Location | Connection string
----+----------+---------+-----------+----------+----------+--------------------------------------------------------------------------------------
1 | node1 | primary | * running | | default | host=192.168.56.92 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2
2 | node2 | standby | running | node1 | default | host=192.168.56.90 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2
3 | node3 | standby | running | node1 | default | host=192.168.56.88 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2
4 | node4 | standby | running | node1 | default | host=192.168.56.86 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2
11 | witness1 | witness | * running | node1 | default | host=192.168.56.94 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2
参考:
https://www.2ndquadrant.com/en/resources/repmgr/
https://repmgr.org/docs/4.2/index.html