1.在master和standby上安裝PG、repmgr,建立postgres角色(rsync
is available and passwordless SSH connections are possible between both servers)node
【 [postgres@node1 ~]$ ssh-keygen -t rsasql
[postgres@node1 ~]$ ssh-copy-id -i .ssh/id_rsa.pub postgres@node2數據庫
[postgres@node1 ~]$ ssh node2 dateless
Tue Apr 15 01:17:20 CST 2014ssh
[postgres@node2 ~]$ ssh-keygen -t rsapost
[postgres@node2 ~]$ ssh-copy-id -i .ssh/id_rsa.pub postgres@node1postgresql
[postgres@node2 ~]$ ssh node1 datecode
Tue Apr 15 01:18:13 CST 2014server
】;io
2.master初始化數據庫,建立配置文件postgresql.replication.conf:
max_wal_senders = 10
wal_level = 'hot_standby'
hot_standby = on
archive_mode = on
archive_command = '/bin/true'
# wal_keep_segments = 5000
,並修改postgresql.conf: include ‘postgresql.replication.conf’
3.master建立用戶、數據庫:createuser -s repmgr | createdb repmgr -O repmgr
4.master配置pg_hba.conf:
host replication repmgr 127.0.0.1/32 trust
host replication repmgr 192.168.98.0/24 trust
host repmgr repmgr 192.168.98.0/24 trust
5.master建立repmgr.conf配置文件:
cluster=test 【全部節點保持一致】 node=1 node_name=node1 conninfo='host=repmgr_node1 user=repmgr dbname=repmgr'
6.master修改repmgr的搜索路徑:ALTER USER repmgr SET search_path TO repmgr_test, "$user", public;
7.master節點初始化master:repmgr -f repmgr.conf master register
8.standby節點建立repmgr.conf:
ALTER USER repmgr SET search_path TO repmgr_test, "$user", public;repmgr -f repmgr.conf master register
9.克隆standby:repmgr -h 192.168.98.55 -U repmgr -d repmgr -D /home/postgres/PG-9.6.1/ -f /home/postgres/repmgr.conf standby clone10.調整配置文件,啓動standby數據庫:pg_ctl -D /home/postgres/PG-9.6.1/ start11.註冊standy數據庫:repmgr -f repmgr.conf standby registercluster=test node=2 node_name=node2 conninfo='host=repmgr_node2 user=repmgr dbname=repmgr'