keepalived 高可用配置
安装
#ubuntu
apt-get install keepalived
#centos
yum install keepalived
master 节点配置,以nginx为例
cat > /etc/keepalived/keepalived.conf <<EOF
# master node
vrrp_script chk_nginx {
script "killall -0 nginx" #检查nginx进程
interval 2 #每隔两秒一次
weight 2 #检查ok的权重
}
vrrp_instance VI_1 {
interface bond0 # 设置对应的网卡,需要修改
state MASTER
virtual_router_id 100 # 一个keepalived组需要一个单独的ID,主从一致,需要修改
priority 101 #master的必须大于slave的值
virtual_ipaddress {
x.x.x.x # vip,需要修改
}
track_script {
chk_nginx #上面检测的配置
}
}
EOF
配置slave节点
cat > /etc/keepalived/keepalived.conf <<EOF
# master node
vrrp_script chk_nginx {
script "killall -0 nginx" #检查nginx进程
interval 2 #每隔两秒一次
weight 2 #检查ok的权重
}
vrrp_instance VI_1 {
interface bond0 # 设置对应的网卡,需要修改
state SLAVE
virtual_router_id 100 # 一个keepalived组需要一个单独的ID,主从一致,需要修改
priority 100 #master的必须大于slave的值
virtual_ipaddress {
x.x.x.x # vip,需要修改
}
track_script {
chk_nginx #上面检测的配置
}
}
EOF
启动keepalived
检查是否ok ip a查看
浙公网安备 33010602011771号