本文主要介绍使用 keepalive 实现 presto 的主备高可用
实验环境:CentOS 6 64 位
1. 软件安装
安装keepalive软件包
sudo yum install -y keepalived
presto部署和配置省略,假设进程已经启动,端口监听在8083。
2. 编写presto-master服务存活检测脚本(两台机器都需要)
$sudo vim /usr/bin/check_presto_alive.sh
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
port_test=`nc -z -v localhost 8083|grep succeeded -c`;
if [ $port_test -eq 0 ]
then
echo 'presto server is died'
killall keepalived
fi
$sudo chmod +x /usr/bin/check_presto_alive.sh
2.机器Presto-master1的配置
$sudo vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
vrrp_script check_presto_alive {
script "/usr/bin/check_presto_alive.sh"
interval 3
weight -10
}
global_defs {
router_id LVS_PRESTO #运行keepalived机器的一个标识
}
vrrp_instance VI_1 {
interface eth0 #设置实例绑定的网卡
state MASTER #指定哪个为master,哪个为backup
virtual_router_id 92 #VPID标记,主备必须一样
priority 180 #优先级,高优先级竞选为master
vrrp_unicast_bind 192.168.0.1
vrrp_unicast_peer 192.168.0.2
authentication {
auth_type PASS #认证方式
auth_pass nenad #认证密码
}
virtual_ipaddress {
## 设置VIP,必须是同一网段虚拟IP
192.168.0.251
}
track_script {
check_presto_alive #presto存活检查
}
}
3.机器Presto-master2的配置
$sudo vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
vrrp_script check_presto_alive {
script "/usr/bin/check_presto_alive.sh"
interval 3
weight -10
}
global_defs {
router_id LVS_PRESTO #运行keepalived机器的一个标识
}
vrrp_instance VI_1 {
interface eth0 #设置实例绑定的网卡
state BACKUP #指定哪个为master,哪个为backup
virtual_router_id 92 #VPID标记,主备必须一样
priority 170 #优先级,高优先级竞选为master
vrrp_unicast_bind 192.168.0.2
vrrp_unicast_peer 192.168.0.1
authentication {
auth_type PASS #认证方式
auth_pass nenad #认证密码
}
virtual_ipaddress {
## 设置VIP,必须是同一网段虚拟IP
192.168.0.251
}
track_script {
check_presto_alive #presto存活检查
}
}
4.重启 keepalive 生效(两台机器都执行)
$sudo /etc/init.d/keepalived restart
5.验证
用以下命令可以查看VIP已经绑定到特定的网卡上。
$ ip a
本实验验证了 VIP 的自动漂移,实现了presto-master的主备自动切换
注意:修复失败的服务后,必须重启所在机器的keepalive服务,否则keepalive是无法感知到服务恢复!
下一篇:双活数据中心架构分析及优缺点