07-patroni-配置vip
【摘要】 #权限配置visudopostgres ALL=(ALL) NOPASSWD:ALLcat >> /etc/sudoers <<EOF postgres ALL=(root) NOPASSWD: ALL EOF#添加callbacks参数:scope: pgha #集群名namespace: /pgsql/ #etcd pathname: node1 # node 名称 每个节点...
#权限配置
visudo
postgres ALL=(ALL) NOPASSWD:ALL
cat >> /etc/sudoers <<EOF
postgres ALL=(root) NOPASSWD: ALL
EOF
#添加callbacks参数:
scope: pgha #集群名
namespace: /pgsql/ #etcd path
name: node1 # node 名称 每个节点不同
restapi:
listen: 192.168.5.201:8008
connect_address: 192.168.5.201:8008
etcd:
hosts: 192.168.5.201:2379,192.168.5.202:2379,192.168.5.203:2379
#host: ip:port #single etd server
bootstrap:
# this section will be written into Etcd:/<namespace>/<scope>/config after initializing new cluster
# and all other cluster members will use it as a `global configuration`
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 20485760
master_start_timeout: 300
# synchronous_mode: false
postgresql:
use_pg_rewind: true
use_slots: false
parameters:
listen_addresses: "*"
port: 5432
wal_level: logical
hot_standby: "on"
wal_keep_segments: 1000
max_wal_senders: 10
#synchronous_standby_names: '*'
max_connections: 150
max_replication_slots: 10
wal_log_hints: "on"
postgresql:
listen: 0.0.0.0:5432
connect_address: 192.168.5.201:5432 # local ip
data_dir: /data/db02
bin_dir: /usr/local/postgresql/bin
# config_dir:
authentication:
replication:
username: replicator
password: replicator
superuser:
username: postgres
password: postgres
callbacks:
on_start: /etc/patroni/patroni_callback.sh
on_stop: /etc/patroni/patroni_callback.sh
on_role_change: /etc/patroni/patroni_callback.sh
#watchdog:
# mode: automatic # Allowed values: off, automatic, required
# device: /dev/watchdog
# safety_margin: 5
tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false
#IP脚本:
#脚本可用性能测试:
#添加ip
./patroni_callback.sh on_role_change master
#删除ip
./patroni_callback.sh on_role_change replica
# 脚本的开头传入了三个变量,但是在patroni.yml文件中我们并没有传入任何的变量,实际测试过程中发现由patroni服务默认传入三个变量
# $1 - action, patroni触发的动作,stop/start/on_role_change/restart/reload
# $2 - role, 当前节点的角色,master/{slave|replica}
# $3 - scope, 作用范围,twpg服务 # 脚本来自于其他博客,由于逻辑很简单,直接引用了
# 当节点角色为主,使用ip addr命令绑定VIP地址
# 当节点角色为备,使用ip addr命令解绑VIP地址
touch /etc/patroni/patroni_callback.sh
chmod +x /etc/patroni/patroni_callback.sh
vi /etc/patroni/patroni_callback.sh
#!/bin/bash
readonly cb_name=$1
readonly role=$2
readonly scope=$3
function 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 in
on_stop)
sudo ip addr del 192.168.5.210/24 dev enp0s8 label ens192:1
#sudo arping -q -A -c 1 -I ens192 192.168.56.100
sudo iptables -F
;;
on_start)
;;
on_role_change)
if [[ $role == 'master' ]]; then
sudo ip addr add 192.168.5.210/24 brd 192.168.5.255 dev ens192 label ens192:1
sudo arping -q -A -c 1 -I ens192 192.168.5.210
sudo iptables -F
elif [[ $role == 'slave' ]]||[[ $role == 'replica' ]]||[[ $role == 'logical' ]]; then
sudo ip addr del 192.168.5.210/24 dev ens192 label ens192:1
#sudo arping -q -A -c 1 -I enp0s8 192.168.5.210
sudo iptables -F
fi
;;
*)
usage
;;
esac
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)