配置如下:
#修改keepalived配置文件
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { notification_email { root@localhost #邮件地址 } notification_email_from Alexandre.Cassen@firewall.loc #定义发件人 smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id 192.168.37.133 #此为keepalived1服务器的IP vrrp_mcast_group4 224.0.100.32 #定义多播地址 } vrrp_instance nginx1 { #节点名称 state BACKUP #节点模式 interface eth0 #指定网卡名 virtual_router_id 51 priority 95 #权重 advert_int 1 #健康检查间隔时间,生产环境配置请慎重 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { #指定VIP 192.168.37.200/16 dev eth0 } } virtual_server 192.168.37.200 80{ #指定虚拟服务器 delay_loop 6 lb_algo wrr #循环模式 lb_kind DR #LVS工作模式 protocol TCP #协议 real_server 192.168.37.134 80 #真实物理机的ip和端口 { weight 2 #权重 HTTP_GET { #健康检查的模式 url { path / status_code 200 #如果返回状态码为200,则视为服务器健康 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.37.135 80 { #定义第二台真实服务器 weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
vrrp_instance nginx2 { #定义第二台虚拟服务器state MASTERinterface eth0virtual_router_id 34priority 100advert_int 1authentication {auth_type PASSauth_pass 2222}virtual_ipaddress {192.168.37.201/16 dev eth0}}virtual_server 192.168.37.201 80{delay_loop 6lb_algo wrrlb_kind DRprotocol TCPreal_server 192.168.37.134 80{weight 2HTTP_GET {url {path /status_code 200}connect_timeout 3nb_get_retry 3delay_before_retry 3}}real_server 192.168.37.135 80 {weight 1HTTP_GET {url {path /status_code 200}connect_timeout 3nb_get_retry 3delay_before_retry 3} } }
修改keepalived配置文件
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { notification_email { root@localhost } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id 192.168.37.130 vrrp_mcast_group4 224.0.100.32 } vrrp_instance nginx1 { state MASTER interface eth0 virtual_router_id 51 priority100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.37.200/16 dev eth0 } } virtual_server 192.168.37.200 80{ delay_loop 6 lb_algo wrr lb_kind DR protocol TCP real_server 192.168.37.134 80 { weight 2 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.37.135 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
vrrp_instance nginx2 {state BACKUPinterface eth0virtual_router_id 34priority 95advert_int 1authentication {auth_type PASSauth_pass 2222}virtual_ipaddress {192.168.37.201/16 dev eth0}}virtual_server 192.168.37.201 80{delay_loop 6lb_algo wrrlb_kind DRprotocol TCPreal_server 192.168.37.134 80{weight 2HTTP_GET {url {path /status_code 200}connect_timeout 3nb_get_retry 3delay_before_retry 3}}real_server 192.168.37.135 80 {weight 1HTTP_GET {url {path /status_code 200}connect_timeout 3nb_get_retry 3delay_before_retry 3} } }
vim setpara.shvip=192.168.37.200vip2=192.168.37.201mask='255.255.255.255'case $1 instart)echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignoreecho 1 > /proc/sys/net/ipv4/conf/lo/arp_ignoreecho 2 > /proc/sys/net/ipv4/conf/all/arp_announceecho 2 > /proc/sys/net/ipv4/conf/lo/arp_announceifconfig lo:0 $vip netmask $mask broadcast $vip uprgoute add -host $vip dev lo:0ifconfig lo:1 $vip2 netmask $mask broadcast $vip2 uprgoute add -host $vip2 dev lo:0;;stop)ifconfig lo:0 downifconfig lo:1 downecho 0 > /proc/sys/net/ipv4/conf/all/arp_ignoreecho 0 > /proc/sys/net/ipv4/conf/lo/arp_ignoreecho 0 > /proc/sys/net/ipv4/conf/all/arp_announceecho 0 > /proc/sys/net/ipv4/conf/lo/arp_announce;;*)echo "Usage $(basename $0) start|stop"exit 1;;esac
#执行脚本
bash setpara.sh start
vim setpara.shvip=192.168.37.200vip2=192.168.37.201mask='255.255.255.255'case $1 instart)echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignoreecho 1 > /proc/sys/net/ipv4/conf/lo/arp_ignoreecho 2 > /proc/sys/net/ipv4/conf/all/arp_announceecho 2 > /proc/sys/net/ipv4/conf/lo/arp_announceifconfig lo:0 $vip netmask $mask broadcast $vip uprgoute add -host $vip dev lo:0ifconfig lo:1 $vip2 netmask $mask broadcast $vip2 uprgoute add -host $vip2 dev lo:0;;stop)ifconfig lo:0 downifconfig lo:1 downecho 0 > /proc/sys/net/ipv4/conf/all/arp_ignoreecho 0 > /proc/sys/net/ipv4/conf/lo/arp_ignoreecho 0 > /proc/sys/net/ipv4/conf/all/arp_announceecho 0 > /proc/sys/net/ipv4/conf/lo/arp_announce;;*)echo "Usage $(basename $0) start|stop"exit 1;;esac
#执行脚本
bash setpara.sh start
service nginx restart
有关keepalived配置问题,已及LVS-DR模式的ARP抑制原理随后更新。
原创文章,作者:cnc,如若转载,请注明出处:http://www.178linux.com/75374