postgresql 高可用 etcd + patroni 之六 callback bind vip
os: centos 7.4
postgresql: 9.6.9
etcd: 3.2.18
patroni: 1.4.4
本篇blog介紹下 etcd + patroni 發生切換時使用 callback 來重新設定 master 的 vip。
主要是方便自有機房或托管的,云環境貌似不能綁定固定的vip。
patroni 的一些參數
官方文檔描述在callback時又這幾個狀態:
on_reload: run this script when configuration reload is triggered.
on_restart: run this script when the cluster restarts.
on_role_change: run this script when the cluster is being promoted or demoted.
on_start: run this script when the cluster starts.
on_stop: run this script when the cluster stops.
patroni_callback.sh
這個腳本的作用就是,當本地postgresql變為 master 時,就綁定vip,變為slave時,就刪除vip。
# cd /usr/patroni/conf/ # vi patroni_callback.sh#!/bin/bashreadonly cb_name=$1 readonly role=$2 readonly scope=$3function usage() {echo "Usage: $0 <on_start|on_stop|on_role_change> <role> <scope>";exit 1; }echo "this is patroni callback $cb_name $role $scope"case $cb_name inon_stop)sudo ip addr del 192.168.56.100/24 dev enp0s8 label enp0s8:1 #sudo arping -q -A -c 1 -I enp0s8 192.168.56.100sudo iptables -F;;on_start);;on_role_change)if [[ $role == 'master' ]]; thensudo ip addr add 192.168.56.100/24 brd 192.168.56.255 dev enp0s8 label enp0s8:1sudo arping -q -A -c 1 -I enp0s8 192.168.56.100sudo iptables -Felif [[ $role == 'slave' ]]||[[ $role == 'replica' ]]||[[ $role == 'logical' ]]; thensudo ip addr del 192.168.56.100/24 dev enp0s8 label enp0s8:1 #sudo arping -q -A -c 1 -I enp0s8 192.168.56.100sudo iptables -Ffi;; *)usage;; esac修改ip后,一定要使用 arping
配置 sudo
# visudo postgres ALL=(ALL) NOPASSWD:ALL更改權限
# chown -R postgres:postgres /usr/patroni/conf/* # ls -l total 8 -rwxr--r-x 1 postgres postgres 768 Aug 8 18:59 patroni_callback.sh -rw-r--r-- 1 postgres postgres 1616 Aug 8 18:44 patroni_postgresql.yml參考:
https://postgresconf.org/system/events/document/000/000/228/Patroni_tutorial_4x3-2.pdf
轉載于:https://www.cnblogs.com/ctypyb2002/p/9792860.html
總結
以上是生活随笔為你收集整理的postgresql 高可用 etcd + patroni 之六 callback bind vip的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2018-2019-1 20189210
- 下一篇: react todolist代码优化