首页 > 代码库 > lvs-keepalived实现高可用
lvs-keepalived实现高可用
实验环境:
ipvsadm-1.26-4.el6.x86_64
system:centos-6.6.x86_64
kernel:2.6.32-504.el6.x86_64
keepalived-1.2.13-4.el6.x86_64
配置DR:
[root@centos-server ~]# sysctl -w net.ipv4.conf.all.send_redirects=0 net.ipv4.conf.all.send_redirects = 0 [root@centos-server ~]# sysctl -w net.ipv4.conf.default.send_redirects=0 net.ipv4.conf.default.send_redirects = 0 [root@centos-server ~]# sysctl -w net.ipv4.conf.eth2.send_redirects=0 net.ipv4.conf.eth2.send_redirects = 0 [root@centos-server ~]# service ipvsadm stop [root@centos-server ~]# ipvsadm -A -t 192.168.150.200:80 -s rr [root@centos-server ~]# ipvsadm -a -t 192.168.150.200:80 -r 192.168.150.129 -g -w 1 [root@centos-server ~]# ipvsadm -a -t 192.168.150.200:80 -r 192.168.150.142 -g -w 1 [root@centos-server ~]# iptable s -I INPUT -p tcp --dport 80 -j ACCEPT [root@centos-server ~]# service ipvsadm save
配置real server:
[root@centos-server ~]# vim /etc/sysctl.conf net.ipv4.conf.all.arp_ignore=1 net.ipv4.conf.all.arp_announce=2 net.ipv4.conf.default.arp_ignore=1 net.ipv4.conf.default.arp_announce=2 net.ipv4.conf.lo.arp_ignore=1 net.ipv4.conf.lo.arp_announce=2 [root@centos-server ~]# sysctl -p [root@centos-server ~]# ifconfig lo:0 192.168.150.200/32 [root@centos-server ~]# route add -host 192.168.150.200 dev lo:0 [root@centos-server ~]# setenforce 0 [root@centos-server ~]# yum install httpd [root@centos-server ~]# service httpd start
配置keepalived:
global_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 220.181.12.11 smtp_connect_timeout 30 router_id haproxy_DEVEL } vrrp_instance VI_1 { state MASTER #另一端为SLAVE interface eth3 #根据自己网卡情况而定 virtual_router_id 51 priority 100 #另一端为80 advert_int 1 authentication { auth_type PASS auth_pass 1234 } virtual_ipaddress { 192.168.150.200/24 dev eth3 } } virtual_server 192.168.150.200/24 80 { delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 50 protocol TCP real_server 192.168.150.129 80 { weight 3 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.150.142 80 { weight 3 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } } [root@centos-server ~]# service keepalived start
检测结果:
查看是否正常调度:
查看MASTER,获得vip:192.168.150.200,及检查后端
查看SLAVE,及检查后端服务:
故障转移:
停掉MASTER的keepalived,查看SLAVE是否自动切换为MASTER
[root@centos-server ~]# service keepalived stop
检测后端检查:
停掉其中一台后端httpd
[root@centos-server ~]# service hdttp stop
本文出自 “龙爱雪琪” 博客,请务必保留此出处http://dragon123.blog.51cto.com/9152073/1602333
lvs-keepalived实现高可用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。