centos7 - repmgr - Automate process of making primary to standby after failover
问题描述
I have two postgres servers running on CentOS 7 with repmgr 4.1.0-1. So far I have automated the process of promoting the standby to primary after the primary server fails but when it comes back they both act as primary and I don't think the follow_command from repmgr.conf is executed. I can do it manually by deleting the data folder and clone it from the new primary server, and then register it as standby.
repmgr.conf on server 1
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'
repmgr.conf on server 2
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'
After the server starts again it connects to itself and resumes monitoring. Here is the log
[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
Is there a way to automate the primary to switch to standby when it starts again or the original standby that was promoted to go back to standby? Or maybe I can redirect to a script that'll do that from the follow_command, for example: follow_command='change-to-standby.sh'
I will appreciate any help.
解决方案
推荐阅读
- javascript - JS:文本文件到 JSON
- c# - EmguCV Out of memory exception in x86 release mode only-Sharpening Images
- c# - VS Debugger 将 foreach 循环中的当前值显示为 null,而它不是
- javascript - setValue 不是 EelementRef 的属性
- react-native - 哪个 react-native 版本支持所有 npms?
- visual-studio-cordova - VS Tools for Cordova 覆盖 Android 图标
- mongodb - Mongo DB 或任何 nosql DB(Hbase、Cassandra)如何比传统的 RDBMS 具有可扩展性和优势?
- php - 使用 Laravel 的 Eloquent 构建查询
- c++ - 从指针基抽象类调用非虚拟子类方法
- java - JCIFS SMB 库 - 尝试列出域 (.listFiles) 时出错