repmgr-故障转移后自动使主数据库变为备用数据库的过程

时间:2018-08-16 19:39:29

标签: centos7 postgresql-9.6 repmgr

我有两个在reentgr 4.1.0-1上运行的CentOS 7上的postgres服务器。到目前为止,在主服务器发生故障之后,我已经自动完成了将备用数据库提升为主数据库的过程,但是当备份服务器返回时,它们都充当了主数据库,并且我认为repmgr.conf中的follow_command不会执行。我可以通过删除数据文件夹并从新的主服务器克隆它,然后将其注册为备用数据库来手动完成此操作。

服务器1上的repmgr.conf

node_id=1
node_name=pgdb1
conninfo='host=192.168.0.105 user=repmgr dbname=repmgr'
pg_bindir=/usr/pgsql-9.6/bin/
master_response_timeout=5
reconnect_attempts=2
reconnect_interval=2
failover=automatic
promote_command='/usr/pgsql-9.6/bin/repmgr standby promote -f /var/lib/pgsql/9.6/repmgr/repmgr.conf --log-to-file'
follow_command='/usr/pgsql-9.6/bin/repmgr standby follow -f /var/lib/pgsql/9.6/repmgr/repmgr.conf --log-to-file --upstream-node-id=2'
data_directory='/var/lib/pgsql/9.6/data'
log_file='/var/log/repmgr/repmgr.log'
log_level=DEBUG
service_start_command   = 'sudo systemctl start postgresql-9.6'
service_stop_command    = 'sudo systemctl stop postgresql-9.6'
service_restart_command = 'sudo systemctl restart postgresql-9.6'
service_reload_command  = 'sudo systemctl reload postgresql-9.6'

服务器2上的repmgr.conf

node_id=2
node_name=pgdb2
conninfo='host=192.168.0.106 user=repmgr dbname=repmgr'
pg_bindir=/usr/pgsql-9.6/bin/
master_response_timeout=5
reconnect_attempts=2
reconnect_interval=2
failover=automatic
promote_command='/usr/pgsql-9.6/bin/repmgr standby promote -f /var/lib/pgsql/9.6/repmgr/repmgr.conf --log-to-file'
follow_command='/usr/pgsql-9.6/bin/repmgr standby follow -f /var/lib/pgsql/9.6/repmgr/repmgr.conf --log-to-file --upstream-node-id=1'
data_directory='/var/lib/pgsql/9.6/data'
log_file='/var/log/repmgr/repmgr.log'
log_level=DEBUG
service_start_command   = 'sudo systemctl start postgresql-9.6'
service_stop_command    = 'sudo systemctl stop postgresql-9.6'
service_restart_command = 'sudo systemctl restart postgresql-9.6'
service_reload_command  = 'sudo systemctl reload postgresql-9.6'

服务器再次启动后,它将连接到自身并恢复监视。这是日志

[2018-08-16 21:29:56] [DEBUG] connecting to: "user=repmgr dbname=repmgr host=192.168.0.105 connect_timeout=2 fallback_application_name=repmgr"
[2018-08-16 21:29:56] [NOTICE] reconnected to primary node after 22 seconds, resuming monitoring
[2018-08-16 21:31:33] [INFO] monitoring primary node "pgdb1" (node ID: 1) in normal state

是否有一种方法可以使主数据库在再次启动时自动切换到备用数据库,或者自动升级为原来的备用数据库以恢复到备用数据库?或者也许我可以重定向到将通过follow_command执行此操作的脚本,例如: follow_command ='更改为standby.sh'

我将不胜感激。

0 个答案:

没有答案