postgresql 高可用 pacemaker + corosync 之三 vip-mas vip-sla 的绑定方式

os: ubuntu 16.04
db: postgresql 9.6.8
pacemaker: Pacemaker 1.1.14 Written by Andrew Beekhof
corosync: Corosync Cluster Engine, version ‘2.3.5’

一般把 pcs 的批操作执行写入 /root/cluster.pcs 文件,在处理 vip-mas vip-sla 的绑定时又有两种模式.

vip-mas ,vip-sla 均绑定 master

这个模式比较常用,是 vip-mas ,vip-sla 都绑定在 master 节点的网卡上.
生产环境时 服务网卡 和 复制网卡 应该是两个独立的物理网卡,以免相互干扰.

vip-mas 192.168.56.119
vip-sla 192.168.56.120

node1 192.168.56.92
node2 192.168.56.90
node3 192.168.56.88

pcs cluster cib pgsql_cfg
 
pcs -f pgsql_cfg property set no-quorum-policy="ignore"
pcs -f pgsql_cfg property set stonith-enabled="false"
pcs -f pgsql_cfg resource defaults resource-stickiness="INFINITY"
pcs -f pgsql_cfg resource defaults migration-threshold="1"
 
pcs -f pgsql_cfg resource create vip-mas IPaddr2 \
   ip="192.168.56.119" \
   nic="eno1" \
   cidr_netmask="24" \
   op start   timeout="60s" interval="0s"  on-fail="restart" \
   op monitor timeout="60s" interval="10s" on-fail="restart" \
   op stop    timeout="60s" interval="0s"  on-fail="block"
 
pcs -f pgsql_cfg resource create vip-sla IPaddr2 \
   ip="192.168.56.120" \
   nic="eno1" \
   cidr_netmask="24" \
   meta migration-threshold="0" \
   op start   timeout="60s" interval="0s"  on-fail="stop" \
   op monitor timeout="60s" interval="10s" on-fail="restart" \
   op stop    timeout="60s" interval="0s"  on-fail="ignore"
 
pcs -f pgsql_cfg resource create pgsql pgsql \
   pgctl="/usr/lib/postgresql/9.6/bin/pg_ctl" \
   psql="/usr/lib/postgresql/9.6/bin/psql" \
   pgdata="/data/pg9.6/main/" \
   config="/etc/postgresql/9.6/main/postgresql.conf" \
   socketdir="/var/run/postgresql" \
   rep_mode="async" \
   node_list="node1 node2 node3" \
   master_ip="192.168.56.120" \
   repuser="repl" \
   primary_conninfo_opt="password=pass0rd!@123 keepalives_idle=60 keepalives_interval=5 keepalives_count=5" \
   restart_on_promote='true' \
   op start   timeout="60s" interval="0s"  on-fail="restart" \
   op monitor timeout="60s" interval="4s"  on-fail="restart" \
   op monitor timeout="60s" interval="3s"  on-fail="restart" role="Master" \
   op promote timeout="60s" interval="0s"  on-fail="restart" \
   op demote  timeout="60s" interval="0s"  on-fail="stop" \
   op stop    timeout="60s" interval="0s"  on-fail="block" \
   op notify  timeout="60s" interval="0s"
 
pcs -f pgsql_cfg resource master msPostgresql pgsql \
   master-max=1 master-node-max=1 clone-max=5 clone-node-max=1 notify=true
 
pcs -f pgsql_cfg resource group add master-group vip-mas vip-sla
 
pcs -f pgsql_cfg constraint colocation add master-group with Master msPostgresql INFINITY
pcs -f pgsql_cfg constraint order promote msPostgresql then start master-group symmetrical=false score=INFINITY
pcs -f pgsql_cfg constraint order demote  msPostgresql then stop  master-group symmetrical=false score=0
 
pcs cluster cib-push pgsql_cfg

vip-mas 绑定 master,vip-sla 绑定 slave

这种模式是 vip-mas 绑定在 master 节点的网卡上,vip-sla 绑定在 slave 节点的网卡上.

vip-mas 192.168.56.119 
vip-sla 192.168.56.120

node1 192.168.56.92
node2 192.168.56.90
node3 192.168.56.88

pcs cluster cib pgsql_cfg
 
pcs -f pgsql_cfg property set no-quorum-policy="ignore"
pcs -f pgsql_cfg property set stonith-enabled="false"
pcs -f pgsql_cfg resource defaults resource-stickiness="INFINITY"
pcs -f pgsql_cfg resource defaults migration-threshold="1"
 
pcs -f pgsql_cfg resource create vip-mas IPaddr2 \
   ip="192.168.56.119" \
   nic="eno1" \
   cidr_netmask="24" \
   op start   timeout="60s" interval="0s"  on-fail="restart" \
   op monitor timeout="60s" interval="10s" on-fail="restart" \
   op stop    timeout="60s" interval="0s"  on-fail="block"
 
pcs -f pgsql_cfg resource create vip-sla IPaddr2 \
   ip="192.168.56.120" \
   nic="eno1" \
   cidr_netmask="24" \
   meta migration-threshold="0" \
   op start   timeout="60s" interval="0s"  on-fail="stop" \
   op monitor timeout="60s" interval="10s" on-fail="restart" \
   op stop    timeout="60s" interval="0s"  on-fail="ignore"
 
pcs -f pgsql_cfg resource create pgsql pgsql \
   pgctl="/usr/lib/postgresql/9.6/bin/pg_ctl" \
   psql="/usr/lib/postgresql/9.6/bin/psql" \
   pgdata="/data/pg9.6/main/" \
   config="/etc/postgresql/9.6/main/postgresql.conf" \
   socketdir="/var/run/postgresql" \
   rep_mode="async" \
   node_list="node1 node2 node3" \
   master_ip="192.168.56.119" \
   repuser="repl" \
   primary_conninfo_opt="password=pass0rd!@123 keepalives_idle=60 keepalives_interval=5 keepalives_count=5" \
   restart_on_promote='true' \
   op start   timeout="60s" interval="0s"  on-fail="restart" \
   op monitor timeout="60s" interval="4s"  on-fail="restart" \
   op monitor timeout="60s" interval="3s"  on-fail="restart" role="Master" \
   op promote timeout="60s" interval="0s"  on-fail="restart" \
   op demote  timeout="60s" interval="0s"  on-fail="stop" \
   op stop    timeout="60s" interval="0s"  on-fail="block" \
   op notify  timeout="60s" interval="0s"
 
pcs -f pgsql_cfg resource master msPostgresql pgsql \
   master-max=1 master-node-max=1 clone-max=5 clone-node-max=1 notify=true
 
pcs -f pgsql_cfg resource group add master-group vip-mas
pcs -f pgsql_cfg resource group add slave-group vip-sla
 
pcs -f pgsql_cfg constraint colocation add master-group with master msPostgresql INFINITY
pcs -f pgsql_cfg constraint order promote msPostgresql then start master-group symmetrical=false score=INFINITY
pcs -f pgsql_cfg constraint order demote  msPostgresql then stop  master-group symmetrical=false score=0
 
pcs -f pgsql_cfg constraint colocation add slave-group with slave msPostgresql INFINITY
pcs -f pgsql_cfg constraint order promote msPostgresql then start slave-group symmetrical=false score=INFINITY         
pcs -f pgsql_cfg constraint order demote  msPostgresql then stop  slave-group symmetrical=false score=0 
 
pcs cluster cib-push pgsql_cfg

你可能感兴趣的:(#,postgresql,ha,pacemaker)