本文共 2075 字,大约阅读时间需要 6 分钟。
keepalived最初专为LVS设计用来监控LVS集群系统中各个节点的状态,后来加入VRRP功能。因此也可以做nginx,haproxy,mysql的高可用。
VRRP:虚拟路由器冗余协议,解决静态路由单点故障。
通过竞选协议来实现虚拟路由器的功能,所有的协议报文通过ip多播(多播地址224.0.0.18),虚拟路由器的vrid对外的MAC地址00-00-5e-00-01-vrid.master会一直发VRRP广告包,如果BACKUP收不到广播包,会自己配置vip起服务。#############################################################
安装keepalivedyum install keepalived -yvim /etc/keepalived/keepalived.conf
! Configuration File for keepalivedglobal_defs { notification_email { lmkmike#qq.com}notification_email_from haproxy-ha@qq.comsmtp_server 192.168.200.1smtp_connect_timeout 30router_id LV-master #每一台keepalived不一样}
vrrp_instance VI_1 {
state MASTER #角色 另外改BACKUPinterface eth0 #网卡virtual_router_id 51 #不能重复priority 150 #权重 另外改100advert_int 1 #检查时间默认1sauthentication { auth_type PASSauth_pass haproxy_ha}virtual_ipaddress { 192.168.56.10/24}}
vrrp_instance VI_2 {
state BACKUP #角色 另外改MASTERinterface eth0 #网卡virtual_router_id 60 #不能重复priority 150 #权重 另外改100advert_int 1 #检查时间默认1sauthentication { auth_type PASSauth_pass haproxy_ha}virtual_ipaddress { 192.168.56.11/24}}virtual_server 192.168.56.10 80 {
delay_loop 6lb_algo wrrlb_kind DRnat_mask 255.255.255.0persistence_timeout 300protocol TCPreal_server 192.168.56.100 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 }} real_server 192.168.56.21 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 }}}
#############################################################
RS要配置VIP和抑制ARP其他节点绑定vipifconfig lo:0 192.168.56.10/32 up抑制ARPecho 1 >/proc/sys/net/ipv4/conf/lo/arp_ignoreecho 2 >/proc/sys/net/ipv4/conf/lo/arp_announceecho 1 >/proc/sys/net/ipv4/conf/all/arp_ignoreecho 2 >/proc/sys/net/ipv4/conf/all/arp_announce #############################################################启动keepalivedservice keepalived start查看lvs当前链接的状态
ipvsadm -lnc上线RS时通过修改keepalived.cnf后优雅重启/etc/init.d/keepalived reload
转载于:https://blog.51cto.com/13491150/2062952