设为首页 收藏本站
查看: 1610|回复: 0

[经验分享] lvs+keepalived健康检查

[复制链接]

尚未签到

发表于 2018-12-30 06:27:49 | 显示全部楼层 |阅读模式
lvs+keepalived健康检查

  一、 LVS简介

  LVS是Linux Virtual Server的简称,即Linux虚拟服务器。使用LVS技术要达到的目标是:通过LVS提供的负载均衡技术和Linux操作系统实现一个高性能、高可用的服务器群集,它具有良好可靠性、可扩展性和可操作性。从而以低廉的成本实现最优的服务性能。
二、网络拓扑

三、接口IP及属性配置
  1,在Master配置接口IP如下:
[root@localhost network-scripts]# ifconfig
ens33:flags=4163  mtu 1500
       inet 192.168.230.10  netmask255.255.255.0  broadcast 192.168.230.255
       inet6 fe80::250:56ff:fe9a:55c5 prefixlen 64  scopeid0x20
       ether 00:50:56:9a:55:c5 txqueuelen 1000  (Ethernet)
       RX packets 1201  bytes 94251 (92.0KiB)
       RX errors 0  dropped 0  overruns 0 frame 0
       TX packets 5964  bytes 390181(381.0 KiB)
       TX errors 0  dropped 0 overruns0  carrier 0  collisions 0
ens33:0:flags=4163  mtu 1500
       inet 192.168.230.100  netmask255.255.255.255  broadcast192.168.230.100
       ether 00:50:56:9a:55:c5 txqueuelen 1000  (Ethernet)  2,在Slave配置接口IP如下:
[root@localhost ~]# ifconfig
ens33:flags=4163  mtu 1500
       inet 192.168.230.11  netmask255.255.255.0  broadcast 192.168.230.255
       inet6 fe80::250:56ff:fe9a:62e8 prefixlen 64  scopeid0x20
       ether 00:50:56:9a:62:e8 txqueuelen 1000  (Ethernet)
       RX packets 3  bytes 620 (620.0 B)
       RX errors 0  dropped 0  overruns 0 frame 0
       TX packets 50  bytes 7844 (7.6KiB)
       TX errors 0  dropped 0 overruns0  carrier 0  collisions 0
ens33:0:flags=4163  mtu 1500
       inet 192.168.230.100  netmask255.255.255.255  broadcast192.168.230.100
       ether 00:50:56:9a:62:e8 txqueuelen 1000  (Ethernet)  3,在rs1上配置接口IP如下:
[root@localhost]# ifconfig
ens33:flags=4163  mtu 1500
       inet 192.168.230.12  netmask255.255.255.0  broadcast 192.168.230.255
       inet6 fe80::250:56ff:fe9a:daa prefixlen 64  scopeid0x20
       ether 00:50:56:9a:0d:aa txqueuelen 1000  (Ethernet)
       RX packets 162543  bytes 11199233(10.6 MiB)
       RX errors 0  dropped 66  overruns 0 frame 0
       TX packets 74236  bytes 9216209(8.7 MiB)
       TX errors 0  dropped 0 overruns0  carrier 0  collisions 0
lo:0:flags=73  mtu65536
       inet 192.168.230.100  netmask255.255.255.255
       loop  txqueuelen 0  (Local Loopback)  4,在rs2上配置接口IP如下:
[root@localhost]# ifconfig
ens33:flags=4163  mtu 1500
       inet 192.168.230.13  netmask255.255.255.0  broadcast 192.168.230.255
       inet6 fe80::250:56ff:fe9a:2be1 prefixlen 64  scopeid0x20
       ether 00:50:56:9a:2b:e1 txqueuelen 1000  (Ethernet)
       RX packets 161840  bytes 11150452(10.6 MiB)
       RX errors 0  dropped 44  overruns 0 frame 0
       TX packets 73427  bytes 7893814(7.5 MiB)
       TX errors 0  dropped 0 overruns0  carrier 0  collisions 0
lo:0: flags=73  mtu 65536
       inet 192.168.230.100  netmask255.255.255.255
       loop  txqueuelen 0  (Local Loopback)  5,在Master和Slave上开启转发功能
[root@localhost ~]# echo "1">/proc/sys/net/ipv4/ip_forward  6,在rs1和rs2配置接口属性
[root@localhost ~]# echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore
[root@localhost ~]# echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce
[root@localhost ~]# echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
[root@localhost ~]# echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
[root@localhost ~]# sysctl -p
net.ipv4.conf.ens33.arp_announce = 2
net.ipv4.conf.ens33.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1四、软件安装
  1,在Master上安装ipvsadm和keepalived
  [root@localhost ~]# yum install -ykeepalived ipvsadm
  2,同样在Slave上安装ipvsadm和keepalived
  [root@localhost ~]# yum install -ykeepalived ipvsadm
  3,在rs1和rs2安装测试服务,这里安装httpd服务,具体服务配置请参考官方配置文档。
  [root@localhost htdocs]# yum install -yhttpd
  访问192.168.230.12服务:

  访问192.168.230.13服务:

五、keepalived配置
  1,TCP健康检查配置如下:
[root@localhost keepalived]# catkeepalived.conf
! Configuration File for keepalived
global_defs {
  notification_email {
    acassen@test.com
    failover@test.com
    sysadmin@test.com
   }
  notification_email_from Alexandre.Cassen@test.com
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id LVS_DEVEL
}
vrrp_instance VI_1 {
   state MASTER
   interface ens33
   virtual_router_id 55
   priority 100
   advert_int 1
   authentication {
       auth_type PASS
       auth_pass 1111
    }
   virtual_ipaddress {
       192.168.230.100
    }
}
virtual_server 192.168.230.100 80 {
   delay_loop 6
   lb_algo rr
   lb_kind DR
   #persistence_timeout 50
   protocol TCP
   real_server 192.168.230.12 80 {
       weight 1
       TCP_CHECK { #tcp健康检查
                connect_port 80
                connect_timeout 3
                Nb_get_retry 3 #最大重试次数
                delay_before_retry 5       #重试延时
       }
    }
   real_server 192.168.230.13 80 {
       weight 1
       TCP_CHECK {
                connect_port 80
                connect_timeout 3
                Nb_get_retry 3
                delay_before_retry 5
       }
    }
}  2,http健康检查配置
[root@localhost ~]# cat/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
  notification_email {
    acassen@test.com
    failover@test.com
    sysadmin@test.com
   }
  notification_email_from Alexandre.Cassen@test.com
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id LVS_DEVEL
}
vrrp_instance VI_1 {
   state MASTER
   interface ens33
   virtual_router_id 55
   priority 100
   advert_int 1
   authentication {
       auth_type PASS
       auth_pass 1111
    }
   virtual_ipaddress {
       192.168.230.100
    }
}
virtual_server 192.168.230.100 80 {
   delay_loop 6
   lb_algo rr
   lb_kind DR
   #persistence_timeout 50
   protocol TCP
   real_server 192.168.230.12 80 {
       weight 1
       HTTP_GET {
                url {
                        path /index.html
                        digest 00f6c72507d2480429e5f32dbf2de638
#digest是根据hash算出来的,算法如下:
# /usr/bin/genhash -s 192.168.230.13 -p 80-u /index.html
#注意!如果不加digest经测试发现,当rs服务down掉后又恢复,lvs不能
#恢复调度到此rs上。即健康检查不能恢复
                        }
                connect_port 80
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 5
                }
    }
   real_server 192.168.230.13 80 {
       weight 1
       HTTP_GET {
                url {
                        path /index.html
                        digest 4b0f20d78e6098eb5c2eed901f5f3b6e
#digest是根据hash算出来的,算法如下:
# /usr/bin/genhash -s 192.168.230.13 -p 80-u /index.html
                        }
                connect_port 80
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 5
                }
        }
}  3,配置完在Master和Slave上重启keepalived服务
  [root@localhost keepalived]# servicekeepalived restart
六、测试
  1,将rs1的httpd服务关闭,在客户端访问。

  2,抓包查看,每5s发送一次重传检查报文。

  3,http健康检查报文,每6秒发送一次请求。

  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-657352-1-1.html 上篇帖子: 负载均衡--LVS+Keepalived 下篇帖子: linux LVS (keepalived+ipvsadm)负载均衡搭建 二
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表