一、heartbeat准备
1、接上文HA集群准备工作
2、 安装heartbeat-ldirectord组件包
[root@node1 heartbeat]# yum localinstall heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
3、ldirectord组件简介
ldirectord依赖于自己的配置文件来生成ipvs的规则,因此,定义LVS集群、添加RS都是在ldirectord的配置文件中指定,而无需手动执行ipvsadm命令。ldirectord对LVS集群的director高可用,并对LVS进群的RS提供健康状态监测,若某节点出现故障,则会把它从集群系统中剔除,并在其回复正常后,将它重新加入集群系统。ldirectord还可以调用ipvsadm命令创建LVS路由表信息,只需要在/etc/ha.d/ldirectord.cf配置文件中指明即可。
4、基本信息
二、配置
RS:
1、准备RS脚本 #!/bin/bash vip=192.168.0.17 interface="lo:0" case $1 in start) echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce ifconfig $interface $vip broadcast $vip netmask 255.255.255.255 up route add -host $vip dev $interface ;; stop) echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/eth0/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce echo 0 > /proc/sys/net/ipv4/conf/eth0/arp_announce ifconfig $interface down ;; status) if ifconfig lo:0 | grep $vip &> /dev/null; then echo "ipvs is running." else echo "ipvs is stopped." fi ;; *) echo "please input : `basename $0` {start|stop|status}" exit 1 esac [root@node3 ~]# chmod +x rs.sh 2、准备httpd [root@node3 ~]# yum install httpd [root@node3 ~]# echo "This is RS" > /var/www/html/index.html [root@node3 ~]# service httpd start [root@node3 ~]# curl 192.168.0.20 This is RS [root@node3 ~]# ./rs.sh start
主备Director测试
[root@node1 ~]# ifconfig eth0:0 192.168.0.17 broadcast 192.168.0.17 netmask 255.255.255.255 up [root@node1 ~]# route add -host 192.168.0.17 dev eth0:0 [root@node1 ~]# ipvsadm -A -t 192.168.0.17:80 -s rr [root@node1 ~]# ipvsadm -a -t 192.168.0.17:80 -r 192.168.0.20 -g
[root@node1 ~]# ipvsadm -C [root@node1 ~]# route del -host 192.168.0.17 [root@node1 ~]# ifconfig eth0:0 down
主Director:node1配置
1、cp样例配置文件 [root@node1 ~]# cd /usr/share/doc/heartbeat-ldirectord-2.1.4/ [root@node1 heartbeat-ldirectord-2.1.4]# cp ldirectord.cf /etc/ha.d [root@node1 heartbeat-ldirectord-2.1.4]# cd /etc/ha.d 2、配置文件 ##全局配置 # Global Directives ##健康状态检测超时时间间隔 checktimeout=3 ##每一秒检查一次 checkinterval=1 #fallback=127.0.0.1:80 ##自动装载配置文件 autoreload=yes ##日志文件 logfile="/var/log/ldirectord.log" ##日志文件级别 #logfile="local0" ##邮件通知警告信息 #emailalert="admin@x.y.z" ##邮件通知间隔1小时 #emailalertfreq=3600 ##邮件通知所有的状态信息 #emailalertstatus=all ##是否工作于静默模式 quiescent=yes ##虚拟服务配置 # Sample for an http virtual service ##VIP virtual=192.168.0.17:80 ##RS gate为dr类型 real=192.168.0.20:80 gate #real=192.168.6.3:80 gate #real=192.168.6.6:80 gate ##backserver fallback=127.0.0.1:80 gate ##健康状态检查基于http协议 service=http ##请求的页面 request=".health.html" ##检查request=“”页面中的字符串是否一致 receive="" ##对多个虚拟主机进行检查 virtualhost=some.domain.com.au ##调度类型为rr scheduler=rr ##持久连接时长 #persistent=600 ##掩码 #netmask=255.255.255.255 ##基于tcp的检查,集群服务类型 protocol=tcp ##检查类型为交互式检查 ##checktype:connect是传输层检查,ping是网络层检查,negotlate是应用层检查 ##当checktype=negotlate时,ldirectord将基于指定的协议与各RS建立连接,完成应用层检查 checktype=negotia ##检查端口为80 checkport=80 ##请求的页面 request="index.html" ##请求的字符串检查 #receive="Test Page" ##对虚拟主机检查 #virtualhost= 3、准备web服务,node1作为back server提供sorry server服务 [root@node1 ha.d]# vim /var/www/html/index.html This is sorry server(node1) [root@node1 ha.d]# service httpd start Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using 192.168.0.15 for ServerName [ OK ] [root@node1 ha.d]# curl 192.168.0.15 This is sorry server(node1) 4、将配置文件cp给node2 [root@node1 ha.d]# scp ldirectord.cf node2:/etc/ha.d/
备Director:node2配置
[root@node2 ~]# vim /var/www/html/index.html This is sorry server(node2) [root@node2 ~]# service httpd start Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using 192.168.0.16 for ServerName [ OK ] [root@node2 ~]# curl 192.168.0.16 This is sorry server(node2)
RS准备测试页
[root@node3 ~]# echo "ok" > /var/www/html/.health.html
启动服务
[root@node1 ~]# service heartbeat start; ssh node2 ‘service heartbeat start‘
gui界面配置资源
1、定义资源组ipvs,定义集群ip资源(vip)
2、定义ipvs规则,lsb格式不提供参数,ocf格式的资源代理须提供配置文件
3、启动资源
4、验证node2节点
[root@node2 ~]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.0.17:80 rr -> 192.168.0.20:80 Route 1 0 0 [root@node2 ~]# ip add show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:15:ea:32 brd ff:ff:ff:ff:ff:ff inet 192.168.0.16/24 brd 192.168.0.255 scope global eth0 inet 192.168.0.17/24 brd 192.168.0.255 scope global secondary eth0 inet6 fe80::20c:29ff:fe15:ea32/64 scope link valid_lft forever preferred_lft forever
5、验证负载均衡集群效果
6、检测RS下线,director错误页面
[root@node3 ~]# mv /var/www/html/.health.html /var/www/html/a.html [root@node2 ~]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.0.17:80 rr -> 127.0.0.1:80 Local 1 0 0 -> 192.168.0.20:80 Route 0 0 0
同理检查node1。
本文出自 “linux启航” 博客,请务必保留此出处http://jiayimeng.blog.51cto.com/10604001/1874717
原文地址:http://jiayimeng.blog.51cto.com/10604001/1874717