postgresql 高可用 repmgr 的使用之十一 1 Primary + 3 Standby + 1 Witness

编程入门 行业动态 更新时间:2024-10-11 15:24:21

postgresql 高可用 <a href=https://www.elefans.com/category/jswz/34/1729849.html style=repmgr 的使用之十一 1 Primary + 3 Standby + 1 Witness"/>

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
配置好后的结果如下:

postgres@node1:~$ 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=22  | node2 | standby |   running | node1    | default  | host=192.168.56.90 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=23  | node3 | standby |   running | node1    | default  | host=192.168.56.88 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=24  | node4 | standby |   running | node1    | default  | host=192.168.56.86 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2postgres@node1:~$ 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 registerINFO: 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 showID | 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=22  | node2    | standby |   running | node1    | default  | host=192.168.56.90 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=23  | node3    | standby |   running | node1    | default  | host=192.168.56.88 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=24  | node4    | standby |   running | node1    | default  | host=192.168.56.86 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=211 | witness1 | witness | * running | node1    | default  | host=192.168.56.94 user=repmgr password=repmgrrepmgr dbname=repmgr connect_timeout=2

参考:
/
.2/index.html

更多推荐

postgresql 高可用 repmgr 的使用之十一 1 Primary + 3 Standby + 1 Witness

本文发布于:2024-03-11 20:37:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1729846.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:repmgr   postgresql   Primary   Witness   Standby

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!