keepalived配置
清除lvs
ipvsadm -C
ifconfig th0:1 down
node1,node4 安装keepalived
yum install keepalived ipvsadm -y
配置keepalived
cd /etc/keepalived/keepalived.conf
cp keepalived.conf keepalived.conf.bak
配置文件说明:
vrrp*:{ #虚拟路由 冗余协议
state MASTER #主节点 备BACKUP
interface eth0 #传输信息网卡
virtual_router_id 51 #
priority 100 #权重 备50
advert_int 1
virtual_ipaddress { #设置虚拟IP地址,可以设置多个虚拟IP地址,每行一个
192.168.158.128/24 dev eth0 label eth0:1 #ifconfig eth0:1 192.168.158.128/24
}
}
notification_email: 邮件通知
virtual_server 192.168.158.100 80{ #VIP及服务
delay_loop 6 #每隔6秒查询realserver状态
lb_algo rr #后端调试算法(load balancing algorithm)
lb_kind DR #LVS调度类型NAT/DR/TUN
#persistence_timeout 60 同一IP的连接60秒内被分配到同一台realserver
protocol TCP #用TCP协议检查realserver状态
real_server 192.168.158.129 80 {
weight 1 #权重,最大越高,lvs就越优先访问
TCP_CHECK { #keepalived的健康检查方式HTTP_GET | SSL_GET | TCP_CHECK | SMTP_CHECK | MISC
connect_timeout 10 #10秒无响应超时
retry 3 #重连次数3次
delay_before_retry 3 #重连间隔时间
connect_port 80 #健康检查realserver的端口
}
HTTP_GET {
url {
path /index.html #检测url,可写多个
digest 24326582a86bee4 78bac72d5af25089e #检测效验码
#digest效验码获取方法:genhash -s IP -p 80 -u http://IP/index.html
status_code 200 #检测返回http状态码
}
}
real_server 192.168.158.130 80 {
weight 1 #权重,最大越高,lvs就越优先访问
TCP_CHECK { #keepalived的健康检查方式HTTP_GET | SSL_GET | TCP_CHECK | SMTP_CHECK | MISC
connect_timeout 10 #10秒无响应超时
retry 3 #重连次数3次
delay_before_retry 3 #重连间隔时间
connect_port 80 #健康检查realserver的端口
}
HTTP_GET {
url {
path /index.html #检测url,可写多个
digest 24326582a86bee478bac72d5af25089e #检测效验码
#digest效验码获取方法:genhash -s IP -p 80 -u http://IP/index.html
status_code 200 #检测返回http状态码
}
}
}