LVS—使用DR模式+ldirectord实现自动检测服务器健康状态
一、配置环境:
DR模式配置:配置教程
二、健康监测
如果一个服务器宕机,访问的链接将时好时坏,这时就需要对后端进行健康检查
1.server1:配置yum源,安装软件ldirectord
vim /etc/yum.repos.d/rhel-source.repo ##添加高可用的软件包
[HighAvailability]
name=HighAvailability
baseurl=http://172.25.60.250/iso/HighAvailability
enabled=1
gpgcheck=0
yum clean all
yum repolist
##此时有高可用的56个包,但是安装还需要依赖性,再额外下载一个安装包ldirectord-.9.5-3.1.x86_64.rpm
安装:
vim /var/www/html/index.html
系统维护中……
/etc/init.d/httpd restart
2.配置文件
rpm -qpl ldirectord-3.9.5-3.1.x86_64.rpm
cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf cd /etc/ha.d
vim /etc/ha.d/ldirectord.cf
24 # Sample for an http virtual service
25 virtual=172.25.60.100:80
26 real=172.25.60.2:80 gate
27 real=172.25.60.3:80 gate
28 fallback=127.0.0.1:80 gate
29 service=http
30 scheduler=rr
31 #persistent=600
32 #netmask=255.255.255.255
33 protocol=tcp
34 checktype=negotiate
35 checkport=80
36 request="index.html"
37 #receive="Test Page"
38 #virtualhost=www.x.y.z
/etc/init.d/ldirectord start
3.测试:
在物理机上:
两台真机都正常工作时,轮循:
[[email protected] ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[[email protected] ~]# curl 172.25.60.100
<h1>server2,example.com</h1>
[[email protected] ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[[email protected] ~]# curl 172.25.60.100
<h1>server2,example.com</h1>
当其中一台宕机时,只显示正常真机的网页信息:
[[email protected] ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[[email protected] ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[[email protected] ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[[email protected] ~]#
当两台都宕机时,显示‘系统维护中……’:
[[email protected] ~]# curl 172.25.60.100
系统维护中……
[[email protected] ~]# curl 172.25.60.100
系统维护中……
[[email protected] ~]# curl 172.25.60.100
系统维护中……
健康检查实现!