代码改变世界

如何使用pgpool failover_stream.sh自己控制选择指定的master节点

2017-06-20 16:31  DataBases  阅读(1121)  评论(0编辑  收藏  举报

集群架构:

h236:master

h237:standby sync

h238:standby sync

h239:stadnby async

h240:standby async

h241:standby async

pool.conf

failover_command = '/etc/kingbasecluster/failover_stream.sh %H %P %d'

failover_stream.sh

#!/bin/sh
h238=172.19.33.238
h239=172.19.33.239
h240=172.19.33.240
h241=172.19.33.241
h236=172.19.33.236
h237=172.19.33.237
trigger_command="pg_ctl promote -D /data/pgdata"
fix_rec="sed -i 's/172\.19\.33\.236\./172.19.33.237/' /data/pgdata/recovery.conf;\
pg_ctl -D /data/pgdata/ stop -m fast;pg_ctl -D /data/pgdata/ start"

#primary down
#236(node 0) , 237(node1)
if [$2 -eq $3 ];then
        #node 236 down          
        if [ $2 -eq 0 ];then
                /usr/bin/ssh -T $h237 $trigger_command
        fi
        #node 237 down #236手动修复称为standby之后
        if [ $2 -eq 1 ];then
                $fix_rec="sed -i 's/172\.19\.33\.237\./172.19.33.236/' /data/pgdata/recovery.conf;\
                pg_ctl -D /data/pgdata/ stop -m fast;pg_ctl -D /data/pgdata/ start"
                /usr/bin/ssh -T $h236 $trigger_command
        fi

        #238-241 follow new primary
        /usr/bin/ssh -T $h238 $fix_rec &
        /usr/bin/ssh -T $h239 $fix_rec &
        /usr/bin/ssh -T $h240 $fix_rec &
        /usr/bin/ssh -T $h241 $fix_rec &

#do nothing for other  standby down
fi
exit 0;

==============================================================================

failover命令中的参数使用描述

failover_command

This parameter specifies a command to run when a node is detached. pgpool-II replaces the following special characters with backend specific information.

Special character Description
%d Backend ID of a detached node.
%h Hostname of a detached node.
%p Port number of a detached node.
%D Database cluster directory of a detached node.
%M Old master node ID.
%m New master node ID.
%H Hostname of the new master node.
%P Old primary node ID.
%% '%' character

You need to reload pgpool.conf if you change failover_command.

When a failover is performed, pgpool kills all its child processes, which will in turn terminate all active sessions to pgpool. Then pgpool invokes the failover_command and waits for its completion. After this, pgpool starts new child processes and is ready again to accept connections from clients.

failback_command

This parameter specifies a command to run when a node is attached. pgpool-II replaces special the following characters with backend specific information.

Special character Description
%d Backend ID of an attached node.
%h Hostname of an attached node.
%p Port number of an attached node.
%D Database cluster path of an attached node.
%M Old master node
%m New master node
%H Hostname of the new master node.
%P Old primary node ID.
%% '%' character

You need to reload pgpool.conf if you change failback_command.