上次总结了我使用ldirectord实现对后端服务器进行健康检查及lvs的功能,今天有时间,看了一下ha的实现,通过使用heartbeat软件解决LB单点的问题,由于家里电脑配置的关系,我只使用了两个虚拟机linux01,linux02,这两台既做RS又做LB
结构如下
linux01(vip:153.128)-------------------linux02(vip:153.128)
(192.168.153.129) (192.168.153.130)
(master) (slave)
两台机器均是独立网卡
操作系统我使用的是centos4.4
yum -y install ipvsadm
heartbeat的安装参考我上篇文章,这里不在写出
安装完heartbeat后
cp heartbeatsrc/doc/authkeys heartbeatsrc/doc/ha.cf heartbeatsrc/doc/haresources /etc/ha.d/
vi /etc/ha.d/ha.cf,将如下参数前的注释去掉,并根据自己的实际要求进行调整
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
bcast eth0 # Linux
auto_failback on
node linux01 #通过uanme -n得到
node linux02
ping_group group1 192.168.153.129 192.168.153.130
respawn hacluster /usr/lib/heartbeat/ipfail
|
vi /etc/ha.d/haresources文件,加入
linux01 closetunl 192.168.153.128 ldirectord::ldirectord.cf starttunl
|
vi /etc/ha.d/authkeys,将如下两行的注释去掉
# crc adds no security, except from packet corruption.
# Use only on physically secure networks.
#
auth 1
1 crc
#2 sha1
#3 md5
|
chomd 600 /etc/ha.d/authkeys
mkdir -p /etc/ha.d/conf
vi /etc/ha.d/conf/ldirectord.cf
# Global Directives
checktimeout=30
checkinterval=10
#fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
logfile="local0"
#emailalert="admin@x.y.z"
#emailalertfreq=3600
#emailalertstatus=all
quiescent=yes
# Sample for an http virtual service
virtual=192.168.153.128:80
real=192.168.153.129:80 ipip
real=192.168.153.130:80 ipip
service=http
request="index.html"
scheduler=rr
#persistent=600
#netmask=255.255.255.255
protocol=tcp
checktype=negotiate
checkport=80
request="index.html"
|
到此,一台机器就配置完毕,在另外一台上使用相同的配置
并在/etc/ha.d/resource.d下建立closetunl脚本,内容如下
#!/bin/sh
VIP=192.168.153.128
case "$1" in
start)
# close tunl0 interface
echo $"Close tunl0 interface"
/sbin/route del -host $VIP dev tunl0
/sbin/ifconfig tunl0 down
echo "0">/proc/sys/net/ipv4/conf/all/arp_announce
echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0">/proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "0">/proc/sys/net/ipv4/conf/tunl0/arp_ignore
;;
stop)
# start tunl0 interface
echo $"Start tunl0 interface"
/sbin/ifconfig tunl0 $VIP/32 broadcast $VIP up
/sbin/route add -host $VIP dev tunl0
echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2">/proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "1">/proc/sys/net/ipv4/conf/tunl0/arp_ignore
;;
*)
echo $"Usage: $0 (start|stop)"
exit 1
;;
esac
|
/etc/ha.d/resource.d下建立starttunl脚本,
#!/bin/sh
VIP=192.168.153.128
case "$1" in
stop)
# close tunl0 interface
echo $"Close tunl0 interface"
/sbin/route del -host $VIP dev tunl0
/sbin/ifconfig tunl0 down
echo "0">/proc/sys/net/ipv4/conf/all/arp_announce
echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0">/proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "0">/proc/sys/net/ipv4/conf/tunl0/arp_ignore
;;
start)
# start tunl0 interface
echo $"Start tunl0 interface"
/sbin/ifconfig tunl0 $VIP/32 broadcast $VIP up
/sbin/route add -host $VIP dev tunl0
echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2">/proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "1">/proc/sys/net/ipv4/conf/tunl0/arp_ignore
;;
*)
echo $"Usage: $0 (start|stop)"
exit 1
;;
esac
|
以上两个文件在另外一台机器的相同文件夹下copy一份
至此,两台机器的配置工作就完成了,下面进行测试
首先在两台机器上执行/etc/ha.d/resource.d/starttunl start命令
然后使用/etc/init.d/heartbeat start来启动ha
使用ifconfig查看一下执行结果
linux01的
eth0 Link encap:Ethernet HWaddr 00:0C:29:D8:12:CA
inet addr:192.168.153.129 Bcast:192.168.153.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fed8:12ca/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2894 errors:0 dropped:0 overruns:0 frame:0
TX packets:3394 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:333960 (326.1 KiB) TX bytes:488387 (476.9 KiB)
Interrupt:185 Base address:0x1400
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:D8:12:CA
inet addr:192.168.153.128 Bcast:192.168.153.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:185 Base address:0x1400
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1031 errors:0 dropped:0 overruns:0 frame:0
TX packets:1031 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:105022 (102.5 KiB) TX bytes:105022 (102.5 KiB)
tunl0 Link encap:IPIP Tunnel HWaddr
inet addr:192.168.153.128 Mask:0.0.0.0
UP RUNNING NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
|
linux02的
eth0 Link encap:Ethernet HWaddr 00:0C:29:D7:3C:D2
inet addr:192.168.153.130 Bcast:192.168.153.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fed7:3cd2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1614 errors:0 dropped:0 overruns:0 frame:0
TX packets:1563 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:190618 (186.1 KiB) TX bytes:232555 (227.1 KiB)
Interrupt:185 Base address:0x1400
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:288 errors:0 dropped:0 overruns:0 frame:0
TX packets:288 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:30359 (29.6 KiB) TX bytes:30359 (29.6 KiB)
tunl0 Link encap:IPIP Tunnel HWaddr
inet addr:192.168.153.128 Mask:0.0.0.0
UP RUNNING NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
|
由此可以发现在linux02中并没有eth0:0的接口
测试方法:
在linux01上执行/etc/init.d/heartbeat stop命令
在使用ifconfig命令查看接口
linux01
eth0 Link encap:Ethernet HWaddr 00:0C:29:D8:12:CA
inet addr:192.168.153.129 Bcast:192.168.153.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fed8:12ca/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3329 errors:0 dropped:0 overruns:0 frame:0
TX packets:3836 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:394140 (384.9 KiB) TX bytes:552075 (539.1 KiB)
Interrupt:185 Base address:0x1400
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1359 errors:0 dropped:0 overruns:0 frame:0
TX packets:1359 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:138060 (134.8 KiB) TX bytes:138060 (134.8 KiB)
tunl0 Link encap:IPIP Tunnel HWaddr
inet addr:192.168.153.128 Mask:0.0.0.0
UP RUNNING NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
|
发现linux01上没有了eth0:0的接口了,在用ipvsadm看下
IP Virtual Server version 1.2.0 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
|
没有了table
现在用ifconfig看下linux02上的接口
eth0 Link encap:Ethernet HWaddr 00:0C:29:D7:3C:D2
inet addr:192.168.153.130 Bcast:192.168.153.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fed7:3cd2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2760 errors:0 dropped:0 overruns:0 frame:0
TX packets:2697 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:346756 (338.6 KiB) TX bytes:406694 (397.1 KiB)
Interrupt:185 Base address:0x1400
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:D7:3C:D2
inet addr:192.168.153.128 Bcast:192.168.153.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:185 Base address:0x1400
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:876 errors:0 dropped:0 overruns:0 frame:0
TX packets:876 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:92925 (90.7 KiB) TX bytes:92925 (90.7 KiB)
tunl0 Link encap:IPIP Tunnel HWaddr
inet addr:192.168.153.128 Mask:0.0.0.0
UP RUNNING NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
|
eth0:0的接口出现了,说明linux02接管了linux01的服务,在看下ipvsadm的情况
[root@linux02 resource.d]# ipvsadm
IP Virtual Server version 1.2.0 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.153.128:http rr
-> 192.168.153.129:http Tunnel 1 0 0
-> 192.168.153.130:http Local 1 0 0
|
linux02同样接管了lvs的服务
具体ldirectord的测试我就不做了,结论应该和我上篇文章是相同的
参考文章:
阅读(1409) | 评论(0) | 转发(0) |