heartbeat v1 + ldirctord
一、实验环境介绍
硬件:lenovo T410S
软件:VMWARE workstation
SO: Centos 6.6
二、实验目的
通过ldirectord实现LVS的高可用和后端RS的健康状态监控
三、网路拓扑
http://s3.运维网.com/wyfs02/M00/6E/6C/wKioL1V8L16C9Q2EAAOzAIMuTFE159.jpg
四、实验环境准备
1、配置NTP服务器确保时间同步
# vim /etc/ntp.conf
添加如下
restrict 192.168.239.0 mask 255.255.255.0 nomodify #允许哪些个网段的主机过来同步
注释下面的时间服务器
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server server s1a.time.edu.cn #去该NTP服务器同步时间
# ntpdate s1a.time.edu.cn
# service ntpd start
2、节点之间名称相互通信
# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.239.133 node1.hailang.com node1
192.168.239.134 node2.hailang.com node2
# hostname node1.hailang.com
# uname -n
3、SSH互相认证
# ssh-keygen -t rsa
# ssh-copy-id ~/.ssh/id_isa.pub 192.168.239.134
# ssh node2.hailang.com
4、关闭防火墙和SELINUX
# service iptables stop
# setenforce 0
5、配置yum源
# vim /etc/yum.repos.d/epel.repo
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://mirrors.aliyun.com/epel/6/$basearch
http://mirrors.aliyuncs.com/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
6、httpd(node1提供页面的内容为sorry node1,node2提供页面的内容为sorry node2)
# yum -y install httpd
# service httpd statrt
# vim /var/www/html/index.html
node1
五、安装并配置herartbeat v1 和ldirectord
1、安装(133和134)
# yum install perl-TimeDate net-snmp-libs libnet PyXML
# rpm -ivh heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-2.1.4-12.el6.x86_64.rpmheartbeat-stonith-2.1.4-12.el6.x86_64.rpm heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
2、配置(133和134)
# cp /usr/share/doc/heartbeat-2.1.4/{ha.cf,authkeys,haresources} /etc/ha.d/
# cp/usr/share/doc/heartbeat-ldirectord-2.1.4/ldirectord.cf /etc/ha.d/
1)ha.cf
# vim /etc/ha.d/ha.cf
logfile /var/log/ha-log
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
mcast eth0 225.0.0.1 694 1 0
auto_failback on
node node1.hailang.com
node node2.hailang.com
ping 192.168.239.1
2)authkeys
# vim /etc/ha.d/authkeys
auth 1
1 crc
3)vim /etc/ha.d/ldirectord.cf
checktimeout=3
checkinterval=1
autoreload=yes
quiescent=yes
virtual=192.168.239.200:80
real=192.168.239.135:80 gate
real=192.168.239.128:80 gate
fallback=127.0.0.1:80 gate
service=http
request="index.html"
receive="ok"
scheduler=rr
3)haresources
node1.hailang.com192.168.239.200/32/eth0/192.168.239.200 ldirectord::/etc/ha.d/ldirectord.cf
4)在128和135服务器上设置内核参数
# echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore
# echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
# echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
# echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce
# ifconfig lo:0 192.168.239.200 netmask 255.255.255.255 broadcast 192.168.239.200
# route add -host 192.168.239.200 dev lo
5)在128和135服务器上启动httpd服务并关闭防火墙且提供测试页面
# service httpd start
Starting httpd:
# service iptables stop
# vim /var/www/html/index.html
3、启动(133和134)
# service heartbeat start
4、测试
1)访问http://192.168.239.200
结果:在128和135之间切换
2)停掉128服务器的http服务
# service http stop
结果:显示135页面
3)停掉128和135服务器的http服务
结果:显示133的sorry页面
4)停掉133服务器的heartbeat
# cd /usr/lib64/heartbeat/
# ./hb_standby
结果:显示134的sorry页面
页:
[1]