环境
ha1:192.168.99.200
ha2:192.168.99.202
ha3:192.168.99.222
postgresql 12.1
repmgr 5.0.0
--clone from ha2
# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
ipaddr=192.168.99.222
# vi /etc/hosts
127.0.0.1 ha3 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 ha3 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.99.202 ha2
192.168.99.200 ha1
192.168.99.222 ha3
# hostnamectl set-hostname ha3
# reboot
--ha1和ha2确保集群状态正常,且repmgrd进程正常运行
[postgres@ha2 ~]$ /opt/pgsql/bin/repmgr -f /opt/repmgr.conf cluster show
id | name | role | status | upstream | location | priority | timeline | connection string
---- ------- --------- ----------- ---------- ---------- ---------- ---------- ---------------------------------------------------------------------------
1 | node1 | standby | running | node2 | default | 100 | 16 | host=192.168.99.200 port=6000 user=repmgr dbname=repmgr connect_timeout=2
2 | node2 | primary | * running | | default | 100 | 16 | host=192.168.99.202 port=6000 user=repmgr dbname=repmgr connect_timeout=2
# service postgres-12 stop
[postgres@ha3 ~]$ cd /opt
[postgres@ha3 opt]$ rm -rf archive6000/*
[postgres@ha3 opt]$ rm -rf data6000/*
--初始化数据目录
[postgres@ha3 opt]$ /opt/pgsql/bin/initdb \
-d/opt/data6000 \
-eutf8 \
-upostgres \
-w
[postgres@ha3 opt]$ vi /opt/data6000/postgresql.conf
shared_preload_libraries = 'repmgr'
listen_addresses = '*'
port=6000
logging_collector=on
log_destination=csvlog
log_directory='/opt/data6000/pg_log'
log_filename='pg_log_%y-%m-%d_%h%m%s.log'
log_file_mode=0600
log_truncate_on_rotation=on
log_rotation_age=1d
log_rotation_size=10mb
log_min_messages=warning
log_min_duration_statement=30s
log_checkpoints=on
log_connections=on
log_disconnections=on
log_duration=on
log_lock_waits=on
log_statement=ddl
[postgres@ha3 opt]$ vi /opt/data6000/pg_hba.conf
host repmgr repmgr 192.168.99.0/24 trust
[postgres@ha3 opt]$ /opt/pgsql/bin/pg_ctl -d /opt/data6000/ start &
[postgres@ha3 opt]$ /opt/pgsql/bin/psql -p6000 -h127.0.0.1 -upostgres
create user repmgr superuser connection limit 10 password '123456' ;
create database repmgr owner repmgr;
[postgres@ha3 opt]$ vi /opt/repmgr.conf
node_id=3
node_name='node3'
conninfo='host=192.168.99.222 port=6000 user=repmgr dbname=repmgr connect_timeout=2'
data_directory='/opt/data6000'
replication_user='repmgr'
replication_type='physical'
repmgr_bindir='/opt/pgsql/bin'
pg_bindir='/opt/pgsql/bin'
monitoring_history=yes
monitor_interval_secs=5
log_level='info'
log_file='/opt/data6000/repmgr.log'
--192.168.99.202为主库ha2
[postgres@ha3 opt]$ /opt/pgsql/bin/repmgr -f /opt/repmgr.conf witness register -h 192.168.99.202 -u repmgr -d repmgr --verbose
notice: using provided configuration file "/opt/repmgr.conf"
info: connecting to witness node "node3" (id: 3)
info: connecting to primary node
notice: attempting to install extension "repmgr"
notice: "repmgr" extension successfully installed
info: witness registration complete
notice: witness node "node3" (id: 3) successfully registered
[postgres@ha3 opt]$ /opt/pgsql/bin/repmgr -f /opt/repmgr.conf cluster show
id | name | role | status | upstream | location | priority | timeline | connection string
---- ------- --------- ----------- ---------- ---------- ---------- ---------- ---------------------------------------------------------------------------
1 | node1 | standby | running | node2 | default | 100 | 16 | host=192.168.99.200 port=6000 user=repmgr dbname=repmgr connect_timeout=2
2 | node2 | primary | * running | | default | 100 | 16 | host=192.168.99.202 port=6000 user=repmgr dbname=repmgr connect_timeout=2
3 | node3 | witness | * running | node2 | default | 0 | 1 | host=192.168.99.222 port=6000 user=repmgr dbname=repmgr connect_timeout=2
--启动repmgrd
[postgres@ha3 opt]$ /opt/pgsql/bin/repmgrd -f /opt/repmgr.conf
[postgres@ha2 ~]$ /opt/pgsql/bin/pg_ctl -d /opt/data6000/ stop &
[postgres@ha3 opt]$ tailf /opt/data6000/repmgr.log
[2020-02-03 19:45:11] [detail] pqping() returned "pqping_no_response"
[2020-02-03 19:45:11] [info] sleeping 10 seconds until next reconnection attempt
[2020-02-03 19:45:21] [info] checking state of node 2, 3 of 6 attempts
[2020-02-03 19:45:21] [warning] unable to ping "user=repmgr connect_timeout=2 dbname=repmgr host=192.168.99.202 port=6000 fallback_application_name=repmgr"
[2020-02-03 19:45:21] [detail] pqping() returned "pqping_no_response"
[2020-02-03 19:45:21] [info] sleeping 10 seconds until next reconnection attempt
[2020-02-03 19:45:31] [info] checking state of node 2, 4 of 6 attempts
[2020-02-03 19:45:31] [warning] unable to ping "user=repmgr connect_timeout=2 dbname=repmgr host=192.168.99.202 port=6000 fallback_application_name=repmgr"
[2020-02-03 19:45:31] [detail] pqping() returned "pqping_no_response"
[2020-02-03 19:45:31] [info] sleeping 10 seconds until next reconnection attempt
[2020-02-03 19:45:41] [info] checking state of node 2, 5 of 6 attempts
[2020-02-03 19:45:41] [warning] unable to ping "user=repmgr connect_timeout=2 dbname=repmgr host=192.168.99.202 port=6000 fallback_application_name=repmgr"
[2020-02-03 19:45:41] [detail] pqping() returned "pqping_no_response"
[2020-02-03 19:45:41] [info] sleeping 10 seconds until next reconnection attempt
[2020-02-03 19:45:51] [info] checking state of node 2, 6 of 6 attempts
[2020-02-03 19:45:51] [warning] unable to ping "user=repmgr connect_timeout=2 dbname=repmgr host=192.168.99.202 port=6000 fallback_application_name=repmgr"
[2020-02-03 19:45:51] [detail] pqping() returned "pqping_no_response"
[2020-02-03 19:45:51] [warning] unable to reconnect to node 2 after 6 attempts
[2020-02-03 19:45:54] [notice] witness node 3 now following new primary node 1
[2020-02-03 19:45:54] [info] resuming witness monitoring mode
[2020-02-03 19:45:54] [detail] following new primary "node1" (id: 1)
[2020-02-03 19:45:54] [info] witness monitoring connection to primary node "node1" (id: 1)
[postgres@ha2 ~]$ /opt/pgsql/bin/repmgr -f /opt/repmgr.conf node rejoin -d'host=192.168.99.200 port=6000 user=repmgr dbname=repmgr connect_timeout=2' --force-rewind
最后修改时间:2020-02-06 10:52:39
「喜欢文章,快来给作者赞赏墨值吧」
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。