Director配置
1:配置IP
Director1和Director2的IP配置
2:安装软件包
Director1和Director2
需要安装heartbeat、ipvsadm以及heartbeat和lvs结合的heartbeat-ldirectord的软件包
shell>yum localinstall heartbeat-2.1.4-9.el5.i386.rpm
heartbeat-devel-2.1.4-9.el5.i386.rpm
heartbeat-gui-2.1.4-9.el5.i386.rpm heartbeat-pils-2.1.4-10.el5.i386.rpm
heartbeat-stonith-2.1.4-10.el5.i386.rpm libnet-1.1.4-3.el5.i386.rpm --nogpgcheck
shell>yum install ipvsadm
shell>yum localinstall heartbeat-ldirectord-2.1.4-9.el5.i386.rpm --nogpgcheck
修改主机名和hosts文件
Director1:
shell>hostname mail1.gz.com
shell>vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=mail1.gz.com
shell>vim /etc/hosts
192.168.2.10 mail1/gz/com
192.168.2.20 mail2.gz.com
Director2:
shell>hostname mail2.gz.com
shell>vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=mail2.gz.com
shell>vim /etc/hosts
192.168.2.10 mail1.gz.com
192.168.2.20 mail2.gz.com
4:配置heartbeat
Director2上的配置
shell>cd /usr/share/doc/heartbeat-2.1.4/
shell>cp -p ha.cf haresources authkeys /etc/ha.d
shell>cd /etc/ha.d
shell>vim ha.cf
92 bcast eth1 #心跳探测
212 node mail1.gz.com #节点位置 使用主机名表示(改主机名和host文件的原因)
213 node mail2.gz.com
shell>vim haresources
47 mail1.gz.com 192.168.2.100/24/eth0 ldirectord::ldirectord.cf#以director1为主节点
shell>vim authkeys
auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!
shell>chmod 600 /etc/ha.d/authkeys
shell>cp -p /etc/init.d/ipvsadm /etc/ha.d/resource.d/
shell>service ipvsaadm stop
sell>chkconfig ipvsadm off (确保ipvsadm停止运行,开机不只能启动)
shell>cp -p /usr/share/doc/heartbeat-ldirectord-2.1.4/ldirectord.cf /etc/ha.d/
shell>vim /etc/ha.d/ldirectord.cf
11 # Global Directives
12 checktimeout=3
13 checkinterval=1
14 #fallback=127.0.0.1:80
15 autoreload=yes
16 #logfile="/var/log/ldirectord.log"
17 #logfile="local0"
18 #emailalert="[email protected]"
19 #emailalertfreq=3600
20 #emailalertstatus=all
21 quiescent=no #静默方式为no则realserver消失的话转发规则不存在
22
23 # Sample for an http virtual service
24 virtual=192.168.2.100:80 #转发规则在此声明
25 real=192.168.2.30:80 gate
26 real=192.168.2.40:80 gate
27 service=http
28 request=".test.html" #后方探测页面
29 receive="OK"
30 #virtualhost=some.domain.com.au
31 scheduler=rr
32 #persistent=600
33 #netmask=255.255.255.255
34 #iprotocol=tcp
35 #checktype=negotiate
36 #checkport=80
37 #request="index.html"
38 #receive="Test Page"
39 #virtualhost=www.x.y.z
Director2上的配置(拷贝当前配置文件到Director2到上)
shell>scp ha.cf haresources authkeys ldirectord.cf 192.168.2.20:/etc/ha.d/
shell>cp -p /etc/init.d/ipvsadm /etc/ha.d/resource.d/
二:服务器配置
1.Arp 忽略请求
服务器E1和E2首先都需要这样做,否则在配置IP重启网络功能时会报错
shell>sysctl -a |grep arp
net.ipv4.conf.all.arp_ignore = 0
net.ipv4.conf.all.arp_announce = 0 (将此行复制)
shell> echo "net.ipv4.conf.all.arp_announce = 2 " >>/etc/sysctl.conf
shell> echo "net.ipv4.conf.all.arp_ignore = 1 " >>/etc/sysctl.conf
shell> sysctl -p (使内核参数立即生效)
2:IP配置和路由配置
服务器E1的IP配置
服务器E1路由配置
shell> route add -host 192.168.2.100/32 dev lo:0
服务器E2的IP配置
服务器E2路由配置
shell> route add -host 192.168.2.100/32 dev lo:0
3:安装http建设网站测试页
E1和E2都需要安装httpd
shell> yum install httpd
E1测试页:
shell> echo "server 1" >>/var/www/html/index.html
E1探测页面:
shell> echo "OK" >>/var/www/html/.test.html
E2测试页:
shell>echo "server 2" >>/var/www/html/index.html
shell> echo "OK" >>/var/www/html/.test.html
测试:
服务器F网卡信息在Director1和Director2上分别开启heartbeat
1:service heartbeart start
2:查看网卡信息和转发
并且会发现Director1出现一个子接口有转发规则,而Director2的网卡配置不变,没有转发规则
Director1网卡信息
ipvsadm
Director2网卡信息
ipvsadm
3:访问192.168.2.100
刷新后
模拟Director1失效
shell>/usr/lib/heartbeat/hb_standby
并且会发现Director2出现一个子接口和装发规则,而Director1的网卡恢复到原来的配置而没有转发规则
继续访问192.168.2.100仍能访问