必須配置項參數
前面有提到過repmgr的必須配置項:
vim /etc/repmgr/12/repmgr.conf ##填寫必須配置項 node_id=1 node_name=node1 conninfo='host=192.168.101.9 port=5432 user=postgres dbname=postgres' data_directory='/var/lib/pgsql/12/data'
repmgr守護程序和自動故障轉移參數
以上參數是repmgr操作所需的基本參數,要啟用repmgr守護程序和自動故障轉移,需要啟用/添加許多其他參數。
failover='automatic'
failover的參數有兩個,manual代表手動,automatic代表自動
promote_command='/usr/pgsql-12/bin/repmgr standby promote -f /etc/repmgr/12/repmgr.conf --log-to-file'
此參數告訴repmgr守護程序應該運行什么命令來提升備用數據庫
follow_command ='/ usr / pgsql-12 / bin / repmgr Standby Follow -f /etc/repmgr/12/repmgr.conf --log-to-file --upstream-node-id =%n'
這是repmgr守護程序的第三個必需參數。此參數告訴備用節點遵循新的主節點。repmgr守護程序在運行時將%n占位符替換為新主節點的節點ID:
priority=60
權重,在選舉主機過程中,權重高的備機具有升主的更高優先級,如果權重為0,則該備機永遠不會升級為主機
monitor_interval_secs = 2
此參數告訴repmgr守護程序應該多久(以秒為單位)檢查上游節點的可用性。默認2s檢查一次。
connection_check_type ='ping'
用什么方式聯系上游節點。此參數可以采用三個值:默認為ping
- ping: repmgr uses the PQPing() method
- connection: repmgr tries to create a new connection to the upstream node
- query: repmgr tries to run a SQL query on the upstream node using the existing connection
reconnect_attempts = 4 reconnect_interval = 8
當主節點不可用時,備用節點中的repmgr守護程序將嘗試重新連接到主節點達reconnect_attempts次。此參數的默認值為6。在每次重新連接嘗試之間,它將等待reconnect_interval秒,默認值為10。
primary_visibility_consensus = true
當主節點在多節點群集中不可用時,備用節點可以相互協商以建立有關故障轉移的仲裁。這是通過詢問每個備用數據庫上次看到主數據庫的時間來完成的。如果節點的最后一次通信是最近的,並且晚於本地節點看到主節點的時間,則本地節點會假定主節點仍然可用,並且不會繼續執行故障轉移決定。
standby_disconnect_on_failover = true
在備用節點中將standby_disconnect_on_failover參數設置為“ true”時,repmgr守護程序將確保其WAL接收者與主節點斷開連接並且不接收任何WAL段。在做出故障轉移決定之前,它還將等待其他備用節點的WAL接收器停止。在每個節點中,此參數應設置為相同的值。
將此參數設置為true意味着在發生故障轉移時,每個備用節點都已停止從主節點接收數據。該過程將有5秒鍾的延遲加上WAL接收器在做出故障轉移決定之前停止所花費的時間。默認情況下,repmgr守護程序將等待30秒以確認所有同級節點在故障轉移發生之前已停止接收WAL段。
repmgrd_service_start_command ='sudo / usr / bin / systemctl start repmgr12.service'
repmgrd_service_stop_command ='sudo / usr / bin / systemctl stop repmgr12.service'
這兩個參數指定如何使用“ repmgr守護程序啟動”和“ repmgr守護程序停止”命令啟動和停止repmgr守護程序。