Greenplum——Master自动fail-over高可用方案
在 linux2.4 内核以后,已经完全内置了 LVS 的各个功能模块。
当内核版本小于2.5,需要把keepalived注册为系统服务
##uname -a查看内核版本信息
uname -a
安装
yum方式
安装依赖包
[root@localhost ~]# yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel
[root@localhost ~]# yum install -y keepalived
可能报错:ImportError: No module named site
1.报错原因
Centos自带的python版本为2.7, 升级后yum与高版本的python不兼容
2.解决方法
在终端输入:
unset PYTHONPATH
unset PYTHONHOME
keepalived+greenplum+虚拟ip方案
mastet配置
! Configuration File for keepalived
global_defs {
router_id mdw
}
vrrp_script chk_gp {
script"/home/gpadmin/bin/check_gp.sh"
interval 5
}
vrrp_instance VI_1 {
state MASTER
nopreempt
interface eno16777736
virtual_router_id 51
priority 110
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
172.20.10.100
}
track_script
{
chk_gp
}
notify /home/gpadmin/bin/keep.sh
}
standby
! Configuration File for keepalived
global_defs {
router_id smdw
}
vrrp_script chk_gp {
script"/home/gpadmin/bin/check_gp.sh"
interval 5
}
vrrp_instance VI_1 {
state BACKUP
interface eno16777736
virtual_router_id 51
priority 105
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
172.20.10.100
}
track_script
{
chk_gp
}
notify /home/gpadmin/bin/keep.sh
}
其他相关脚本
- check_gp.sh
#!/bin/sh
CHECK_PROCESS=`ps aux | grep postgres | grep 5432 | wc -l`
if [ $CHECK_PROCESS -eq 0 ]
then
echo “GP is stopped”
sleep 2
CHECK_PROCESS=`ps aux | grep postgres | grep 5432 |wc -l`
if [ $CHECK_PROCESS -eq 0 ]
then
exit 1
else
exit 0
#systemctl stop keepalived.service
fi
fi
- keep.sh
#!/bin/bash
TYPE=$1
NAME=$2
STATE=$3
case $STATE in
MASTER) /bin/bash /home/gpadmin/bin/runner.sh >>/home/gpadmin/bin/keep.data;;
BACKUP) echo "Executing as BACKUP date" >> /home/gpadmin/bin/keep.data;;
FAULT) echo "Executing as FAULT date" >> /home/gpadmin/bin/keep.data exit 0;;
*) echo "Unknown state <<<<<<<<<<<<<<<<<<< date" >> /home/gpadmin/bin/keep.data exit 1;;
esac
- runner.sh
#!/bin/sh
username=`whoami`
if [ "$username" = "gpadmin" ]; then
# /etc/keepalived/bin/monitor.sh
/home/gpadmin/bin/activateGPstandby.sh
else
# /bin/su - gpadmin -c /etc/keepalived/bin/monitor.sh
/bin/su - gpadmin -c /home/gpadmin/bin/activateGPstandby.sh
fi
4.activateGPstandby.sh
source /usr/local/greenplum-db-6.19.3/greenplum_path.sh
export export MASTER_DATA_DIRECTORY=/home/gpadmin/data/master/gpseg-1
export PGPORT=5432
echo "Activating MASTER on smdw date" >> /home/gpadmin/status
gpactivatestandby -a -d $MASTER_DATA_DIRECTORY
以上脚本可实现MASTER挂了之后服务访问BACKUP。此时BACKUP作为MASTER使用,当原MASTER具备能力时,将其挂载到原BACKUP节点上,作为原BACKUP的BACKUP。当原BACKUP挂掉之后,又可以访问原MASTER。
nopreempt和weight可以重点关注。动态权重weight在此场景下并不适用。动态权重可以在keepalive+nginx高可用和负载均衡场景下使用,具体可查看其他文章。