keepalived 实现主从VIP切换
keepalived安装在网上查询;地址如下:
http://5434718.blog.运维网.com/5424718/1238988;
1. 机器:192.168.0.180(主)192.168.0.113 (从)
前提:2个机器上都安装keepalived
2. 配置主上的keepalived.conf(如下)
#keepalived config
! Configuration File for keepalived
global_defs {
notification_email {
wangxinghua1234@163.com
}
notification_email_from wangxinghua1234@163.com
smtp_server smtp.163.com
smtp_connect_timeout 30
router_id MySQL-ha
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
# notify_master /home/sh/master.sh
# notify_backup /home/sh/backup.sh
# notify_stop /home/sh/stop.sh
virtual_ipaddress {
192.168.0.100
}
virtual_server 192.168.0.100 3306 {
delay_loop 2 #每个2秒检查一次real_server状态
lb_algo wrr #LVS算法
lb_kind DR #LVS模式
persistence_timeout 60 #会话保持时间
protocol TCP
real_server 192.168.0.180 3306 {
weight 3
notify_down /home/sh/keepalived_stop.sh#检测到服务down后执行的脚本
TCP_CHECK {
connect_timeout 10 #连接超时时间
nb_get_retry 3 #重连次数
delay_before_retry 3 #重连间隔时间
connect_port 3306 #健康检查端口
}
}
}
3. 配置从上的keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
wangxinghua1234@163.com
}
notification_email_from wangxinghua1234@163.com
smtp_server smtp.163.com
smtp_connect_timeout 30
router_id MySQL-ha
}
vrrp_instance VI_HA {
state BACKUP #都是backup
interface eth0
virtual_router_id 51
priority 90 #优先级
advert_int 5 #检查间隔
nopreempt
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
192.168.0.100
}
4.重启keepalived;
/home/sh/keepalived_stop.sh 中就'pkill keepalived;';
验证切换:
关闭主的mysql,VIP飘逸到从机;
当主的mysql恢复,还是在从机;
当把主的keepalived启动,VIP再飘逸过来;
页:
[1]