企业项目实战-----LVS(DR模式的健康检查)

前言

健康检查对企业而言也是由为重要,在生活中,有时候访问网页访问不到,就会跳出来一些图形告诉你访问失败,这就是健康检查的作用,当服务器都挂掉的时候,告诉你暂时访问不了。

实验环境

server1	172.25.64.1		调度器				版本企业六
server2	172.25.64.2		后端真实服务器		版本企业六
server3	172.25.64.3		后端真实服务器		版本企业六

一、LVS负载均衡-DR模式的健康检查

调度器server1

1、添加高可用yum源

[[email protected] html]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# vim rhel-source.repo 
#####################添加高可用yum源###############
[HighAvailability]
name=HighAvailability
baseurl=http://172.25.64.250/rhel6.5/HighAvailability
enabled=1
gpgcheck=0

[[email protected] yum.repos.d]# yum clean all
[[email protected] yum.repos.d]# yum repolist

企业项目实战-----LVS(DR模式的健康检查)
2、安装ldirectord-3.9.5-3.1.x86_64.rpm

[[email protected] yum.repos.d]# cd /mnt
[[email protected] mnt]# ls
ldirectord-3.9.5-3.1.x86_64.rpm  

[[email protected] mnt]# yum install ldirectord-3.9.5-3.1.x86_64.rpm -y

3、将配置文件拷贝到/etc/ha.d目录下

[[email protected] mnt]# rpm -qpl ldirectord-3.9.5-3.1.x86_64.rpm 	#查看软件安装路径
[[email protected] mnt]# cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf /etc/ha.d

企业项目实战-----LVS(DR模式的健康检查)
4、编写配置文件

[[email protected] mnt]# vim /etc/ha.d/ldirectord.cf 
virtual=172.25.64.100:80				#虚拟IP
        real=172.25.64.2:80 gate	#真实服务器
        real=172.25.64.3:80 gate	#真实服务器
        fallback=127.0.0.1:80 gate
        service=http
        scheduler=rr
        #persistent=600
        #netmask=255.255.255.255
        protocol=tcp
        checktype=negotiate
        checkport=80
        request="index.html"
#       receive="Test Page"	#注释掉
#       virtualhost=www.x.y.z	#注释掉

[[email protected] mnt]# /etc/init.d/ldirectord restart

企业项目实战-----LVS(DR模式的健康检查)

5、安装阿帕奇,并编写默认发布文件

[[email protected] html]# vim index.html
当前网络不稳定,请稍后重试!
[[email protected] html]# /etc/init.d/httpd start

[[email protected] html]# netstat -tnlp	#查看端口,要求http对应80端口

测试:

1、当后端两台服务器都正常工作时:

server2和server3轮流来负载。
企业项目实战-----LVS(DR模式的健康检查)

2、真实服务器挂掉一台时:

[[email protected] ~]# /etc/init.d/httpd stop		#手动关闭阿帕奇服务

只访问server3。
企业项目实战-----LVS(DR模式的健康检查)
3、全部真实服务器挂掉时:

[[email protected] ~]# /etc/init.d/httpd stop

访问调度器的默认发布文件。
企业项目实战-----LVS(DR模式的健康检查)