LVS模式一:DR模式下LVS的健康检查(ldirectord)

为什么需要健康检查?

如果后端真实服务器出现问题,那么在测试端测试的时候,会返回给我们一个错误的页面,那么我们需要对后端服务器做健康检查,保证只返回正确的页面提供给用户。

实验环境:
rhel6.5 selinux and iptables disabled

主机环境:

主机名IP
hetoto1172.25.12.1
hetoto2172.25.12.2
hetoto3172.25.12.3
  • Load Balance: 172.25.12.1(hetoto1)
  • Virtual IP:172.25.12.100
  • RealRerver1:172.25.12.2 (hetoto2)
  • RealRerver2:172.25.12.3(hetoto3)
  • 物理机内网 : 172.25.12.250

配置hetoto2
1.安装apache

[root@hetoto2 ~]# yum install httpd -y

2.编写前端文件

[root@hetoto2 ~]# cd /var/www/html
[root@hetoto2 html]# vim index.html
<h1>www.westos.org - hetoto2</h1>

配置hetoto3:同上

[root@hetoto3 ~]# cd /var/www/html
[root@hetoto3 html]# vim index.html
<h1>www.westos.org - hetoto3</h1>

实现健康检查的配置步骤:

  • 下载ldirectord
  • 配置更高级的yum源
[root@server1 ~]# vim /etc/yum.repos.d/rhel-source.repo 
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=http://172.25.12.250/rhel6.5	
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[LoadBalancer]        
name=LoadBalancer
baseurl=http://172.25.12.250/rhel6.5/LoadBalancer
enabled=1
gpgcheck=0

[HighAvailability]        
name=HighAvailability
baseurl=http://172.25.12.250/rhel6.5/HighAvailability
enabled=1
gpgcheck=0

在这里插入图片描述

[root@server1 ~]# yum clean all
[root@server1 ~]# yum repolist

1.安装软件ldirectord-3.9.5-3.1.x86_64.rpm用来对后端服务器做健康检查:

[root@hetoto1 ~]# yum install -y ldirectord-3.9.5-3.1.x86_64.rpm
  • 查看配置文件
[root@hetoto1 ~]# rpm -qpl ldirectord-3.9.5-3.1.x86_64.rpm
warning: ldirectord-3.9.5-3.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 7b709911: NOKEY
/etc/ha.d
/etc/ha.d/resource.d
/etc/ha.d/resource.d/ldirectord
/etc/init.d/ldirectord
/etc/logrotate.d/ldirectord
/usr/lib/ocf/resource.d/heartbeat/ldirectord
/usr/sbin/ldirectord
/usr/share/doc/ldirectord-3.9.5
/usr/share/doc/ldirectord-3.9.5/COPYING
/usr/share/doc/ldirectord-3.9.5/ldirectord.cf
/usr/share/man/man8/ldirectord.8.gz

在这里插入图片描述
2.配置文件的母板拷到/etc/ha.d/

[root@hetoto1 ~]# cd /etc/ha.d/ 
[root@hetoto1 ha.d]# cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf . 
[root@hetoto1 ha.d]# ls
ldirectord.cf  resource.d  shellfuncs

在这里插入图片描述
3.编辑 ldirectord的配置文件

[root@server1 ha.d]# vim ldirectord.cf 
# Global Directives                 #“ 全局 ” 设置
checktimeout=3                      #指定定real server出错的时间间隔
checkinterval=1                     #指定ldirectord在两次检查之间的时间间隔
autoreload=yes                      #自动重载配置文件,选yes时,当配置文件发生变化,自动载入配置信息
quiescent=no                        
#当一个节点在 checktimeout 设置的时间周期内没有响应是它是 “ 静止的 ” (它的权重为0),当你设置了这个选项后,ldirectord 将 会从 IPVS 表中移除真实服务器而不是 “ 停止 ” 它,从 IPVS 表移除节点将中断现有的客户端连接,并使 LVS 丢掉所有的连接跟踪记录和持续连接模板,如果 你不将这个选项设置为 no,当某个节点崩溃时,对某些客户端计算机而言可能会显示为集群关闭了,因为在这个节点崩溃前这些客户端计算机被分配给它了,而连接跟踪记录和程序连接模板仍然保留在Director上。
logfile="/var/log/ldirectord.log"     #设定ldirectord日志输出文件路径
# Sample for an http virtual service
virtual=172.25.12.100:80              #VIP 地址和端口号
        real=172.25.12.2:80 gate      #指定RealServer地址和端口,同时设定LVS工作模式,gate表示DR模式,ipip表示TUNL模式,masq表示NAT模式。
        real=172.25.12.3:80 gate      #当所有的real server节点不能工作时,web服务重定向的地址
        fallback=127.0.0.1:80 gate    #当所有的real server节点不能工作时,web服务重定向的地址
        service=http                  #指定服务类型,对http服务做负载均衡
        scheduler=rr                  #指定调度算法,这里是rr(轮叫)算法
        #persistent=600
        #netmask=255.255.255.255
        protocol=tcp                      #指出该服务使用的协议:tcp、udp 或 fwm
        checktype=negotiate               #指定Ldirectord的检测类型,默认为negotiate
        checkport=80                      #健康检查使用的端口是 80
        request="index.html"
        #receive="Test Page"              #指定请求和应答字串
        #virtualhost=www.x.y.z            #虚拟服务器的名称
  • 开启服务
[root@hetoto1 ha.d]# /etc/init.d/ldirectord start
Starting ldirectord... success

4.物理机 测试:

  • 后端真实服务器都正常时(RealServer 无宕机 ):实行轮叫

在这里插入图片描述

  • 将hetoto3关掉(RealServer 有一台宕机)
    则显示只调度hetoto2服务器

    在这里插入图片描述

RealServer 全部宕机

1.将hetoto2,和hetoto3的httpd服务都关掉

[root@hetoto2 html]# /etc/init.d/httpd stop
[root@hetoto3 html]# /etc/init.d/httpd stop

2.在调度器hetoto1上编写前端文件

[root@hetoto1 ~]# yum install httpd -y
[root@hetoto1 html]# cd /var/www/html
[root@hetoto1 html]# vim index.html
<h1>网站维护中..</h1>

3.hetoto1的httpd服务端口改成80

[root@hetoto1 html]# vim /etc/httpd/conf/httpd.conf  
Listen 80
[root@hetoto1 html]# /etc/init.d/httpd restart 

4.重启ldirectord 服务

[root@hetoto1 ha.d]# /etc/init.d/ldirectord restart
Restarting ldirectord... success

5.物理机测试

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值