heartbeat v2 + lvs
实验拓扑http://blog.运维网.com/attachment/201208/142951189.png
实验步骤
一、配置lvs-DR
1、配置RealServer (在这里以配置node1为例,node2与node1配置相同)
(1)配置web服务
[*]使用yum安装
[*]#yum -y install httpd
[*]#service httpd start
[*]#echo "node1" > /var/www/html/index.html//添加访问页面
[*]#echo "Test Page" > /var/www/html/.test.html//测试页面
[*]#elinks -dump http://192.168.0.11
[*] node1 //访问成功
(2)配置参数及VIP
[*]#echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
[*]#echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
[*]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[*]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[*]
[*]配置VIP
[*]#ifconfig lo:0 172.16.19.1 broadcast 172.16.19.1
[*]netmask 255.255.255.255 up
[*]#route add -host 172.16.19.1 dev lo:0 //添加路由
[*]#ifconfig //查看VIP是否添加成功
http://blog.运维网.com/attachment/201208/165251451.png
2、配置Director
(与RealServer一样,在此以Dir1为例配置。Dir2做相同配置即可)
(1)配置VIP
[*]#ifconfig eth0:0 172.16.19.1 broadcast 172.16.19.1
[*]netmask 255.255.255.255 up
[*]#route add -host 172.16.19.1 dev eth0:0
[*]#echo 1 > /proc/sys/net/ipv4/ip_forward //打开路由转发
(2)安装ipvsadm并定义规则
[*]#yum -y install ipvsadm
[*]#ipvsadm -A -t 172.16.19.1:80 -s rr
[*]#ipvsadm -a -t 172.16.19.1:80 -r 192.168.0.11 -g
[*]#ipvsadm -a -t 172.16.19.1:80 -r 192.168.0.66 -g
(3)访问http://172.16.19.1,查看负载均衡效果
http://blog.运维网.com/attachment/201208/170610150.pnghttp://blog.运维网.com/attachment/201208/170610944.png
(4)保存规则,关闭服务
[*]#ipvsadm -S > /etc/sysconfig/ipvsadm
[*]#service ipvsadm stop
[*]#chkconfig ipvsadm off
[*]
[*]停用VIP 因为VIP也是高可用资源
[*]#ifconfig eth0:0 down
二、配置Director高可用
在这里我们使用除了使用heartbeat相关软件外,还要安装heartbeat-ldirectord包和它的依赖包perl-MailTools。它相当于heartbeat的一个模块,它可以管理集群的虚拟化和资源,同时还可以检查后端节点健康状况,非常符合实际需求。
1、安装前的准备工作
[*]Dir1与Dir2保证时间同步,可使用date命令
[*]
[*]#vim /etc/hosts//添加如下两行,做主机名称解析
[*] 192.168.0.100 Dir1
[*] 192.168.0.101 Dir2
[*]建立双机互信以便Dir1远程启动Dir2的heartbeat服务
[*]#ssh-keygen -t rsa//产生私钥
[*]#ssh-copy-id -i ./ssh/id_rsa.pub root@Dir2
[*]#ssh Dir2 'uname -n'//测试ssh
[*]#scp /etc/hosts Dir2:/etc//Dir1与Dir2的hosts文件保持一致
[*]
[*]在Dir2上
[*]#ssh-keygen -t rsa//产生私钥
[*]#ssh-copy-id -i ./ssh/id_rsa.pub root@Dir2
[*]#ssh Dir2 'uname -n'//测试ssh
2、安装配置软件
[*]#yum -y --nogpgpcheck localinstall heartbeat-2.1.4-9.el5.i386.rpm
[*]heartbeat-pils-2.1.4-10.el5.i386.rpm
[*]heartbeat-gui-2.1.4-9.el5.i386.rpm
[*]heartbeat-stonith-2.1.4-10.el5.i386.rpmlibnet-1.1.4-3.el5.i386.rpm
[*]heartbeat-ldirectord-2.1.4-9.el5.i386.rpm
[*]perl-MailTools-1.77-1.el5.noarch.rpm
[*]
[*]#cd /usr/share/doc/heartbeat-2.1.4/
[*]#cp authkeys ha.cnf haresource /etc/ha.d/
[*]#cd ..heartbeat-ldirectord-2.1.4/
[*]#cp ldirectord.cf /etc/ha.d
[*]#cd /etc/ha.d/
[*]
[*]#vim ha.cf//编辑主配置文件
[*]initdead 120 //第一次启动时等待其他节点启动的时间
[*]bcast eth0 //心跳信息传播方式
[*]auto_failback on//夺回资源是否开启
[*]node Dir1 //定义节点
[*]node Dir2
[*]ping172.16.0.1//当接收不到其他节点的心跳信息时,
[*]通过ping前端路由证实不是本节点发生故障
[*]compressionbz2 //定义压缩方式
[*]compression_threshold 2 //文件大于2k时才压缩
[*]crm on
[*]
[*]#chmod 600 authkeys //必须改变其权限,否则服务无法启动
[*]#vim authkeys
[*]auth 1
[*]1 md5 f4ecab5e96446b2986
[*]//此处的字符串可以使用 dd if=/dev/urandom count=512 bs=1 | md5sum
[*]命令生成的随即数
[*]
[*]#vim ldirectord.cf
[*]checktimeout=3//当检查不到RealServer时的超时时间
[*]checkintervel=1//每隔多长时间检查一个RealServer
[*]autoreload=yes //当此前配置文件发生改变时会不会自动加载
[*]logfile="/var/log/ldirectord.log"
[*]virtual=172.16.19.1:80//VIP
[*] real=192.168.0.11:80 gate//定义RealServer
[*] real=192.168.0.66:80 gate
[*] fallback=127.0.0.1:80 gate
[*] service=http //提供的服务
[*] request=".test.html" //通过此页面判断RS是否工作
[*] receive="Test Page"//页面返回结果
[*] #virtualhost=some.domain.com.au //可定义虚拟主机
[*] scheduler=rr//使用的算法
[*] protocol=tcp
[*] checktype=negotiate
[*] checkport=80
[*]#scp authkeys ha.cf ldirectord.cf Dir2:/etc/ha.d
[*]#service ldirectord stop
[*]#chkconfig ldirector off
[*]
[*]#passwd haclustet //给hacluster用户添加密码redhat,在启动图形界面时要使用
3、启动服务,管理资源
[*]#service heartbeat start
[*]#ssh node2 '/etc/init.d/heartbeat start'
[*]#hb_gui &//启动gui界面
http://blog.运维网.com/attachment/201208/181436644.png
输入密码便可管理界面
http://blog.运维网.com/attachment/201208/181940628.png
(1)首先添加ldirectord资源
右击'Rescources' ,选择"Add new items"。点击"Add Parameter"提交。
http://blog.运维网.com/attachment/201208/182455198.png
(2)添加VIP
同样方法进入定义页面:
http://blog.运维网.com/attachment/201208/182816387.png
(3)查看定义的资源
http://blog.运维网.com/attachment/201208/183100835.png
此时没有定义约束,资源以负载均衡的方式定义在了两个节点上。
(4)定义并列约束
http://blog.运维网.com/attachment/201208/183434378.png
http://blog.运维网.com/attachment/201208/183533968.png
约束定义好后,两个资源都被定义在了Dir1上。此时访问,http://172.16.19.1一切正常。
还可以定义顺序约束,方法同上不再演示。
三、测试实验
1、测试Director是否高可用
由上图可知,此时资源都定义在了Dir1上。现在我们模拟Dir1不能正常工作,查看资源的流转状况。
http://blog.运维网.com/attachment/201208/184321209.png
ok。资源顺利的转移到了dir2上。Director高可用成功。
2、Director是否能够检查RealServer的健康状况
我们现有两个realserver,我们通过iptables来限制192.168.0.66的80端口。
[*]#iptables -A INPUT -d 192.168.0.66 -p tcp --dport 80 -j DROP
再次访问http://172.16.19.1。此时会发现访问页面只会出现“node1”。使用iptables -F 清除规则后,两台RealServer重新恢复负载均衡。现在可以证明Director可以实现检查后端节点健康状况的功能。
至此,实验结束。
页:
[1]