软件列表:
ipvsadm-1.24.tar.gz
libnet.tar 下载地址:[url]http://www.packetfactory.net/libnet/[/url] 稳定版本是:1.1.2.1
e2fsprogs 可以用rpm 安装光盘
heartbeat-2.0.2.tar.gz
2.6内核已经集成IPVS内核补订了,所以不再需要重新编译内核.
二、配置基于隧道模式Lvs集群
三、配置基于高可用Lvs+heartbeat
四、此种配置方式可以加强LVS的主节点的高安全性前提下(主节点简称DR,备份主节点DRbak),考虑充分利用资源可以将DRbak做为
一、配置基于DR模式Lvs集群
1、下载ipvsadm管理程序
[url]http://www.linuxvirtualserver.org/software/[/url]
注意对应自己的内核版本
cd ipvsadm-1.24
make && make install
# ln -s /usr/src/kernels/2.6.9-22.EL-i686/ /usr/src/linux
# cd ipvsadm-1.24
# make && make install
2、配置VIP脚本
[root@ns ~]#more /etc/init.d/lvsDR
#!/bin/sh
# description: start LVS of Directorserver
VIP=192.168.0.100
RIP1=192.168.0.127
RIP2=192.168.0.128
#RIPn=192.168.0.128~254
GW=192.168.0.1
start)
echo " start LVS of DirectorServer"
# set the Virtual IP Address
/sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev eth0:0
#Clear IPVS table
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -A -t $VIP:80 -s rr (如果需要session保持添加-p 默认保持300秒)
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
#/sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -g
#Run LVS
/sbin/ipvsadm
#end
stop)
echo "close LVS Directorserver"
/sbin/ipvsadm -C
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
如果有多个realserver直接添加就可以了,之后启动此脚本就可以了。
#description : start realserver
VIP=192.168.0.100
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p
#end
此脚本使realserver不响应arp请求,将此脚本分别在realserver上执行就可以了。
在realserver1 执行 echo "This is realserver1" /var/www/html/index.html
在realserver2 执行 echo "This is realserver2" /var/www/html/index.html
二、配置基于隧道模式Lvs集群
#!/bin/sh
# description: start LVS of Directorserver
VIP=192.168.0.100
RIP1=192.168.0.127
RIP2=192.168.0.128
#RIPn=192.168.0.n
GW=192.168.0.1
start)
echo " start LVS of DirectorServer"
# set the Virtual IP Address
/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev tunl0
#Clear IPVS table
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i
#/sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -i
#Run LVS
/sbin/ipvsadm
#end
stop)
echo "close LVS Directorserver"
ifconfig tunl0 down
/sbin/ipvsadm -C
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
#!/bin/sh
# description: Config realserver tunl port and apply arp patch
VIP=192.168.0.100
start)
echo "Tunl port starting"
ifconfig tunl0 $VIP netmask 255.255.255.255 broadcast $VIP up
/sbin/route add -host $VIP dev tunl0
echo "1" >/proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p
stop)
echo "Tunl port closing"
ifconfig tunl0 down
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
此脚本分别在realserver上执行,目的使realserver忽略arp响应,并设定vip.
三、配置基于高可用Lvs+heartbeat
本例使用tun模式
Director server 端脚本文件
[root@ns ~]# more /etc/init.d/tunlvs
#!/bin/sh
# description: start LVS of Directorserver
VIP=192.168.0.100
RIP1=192.168.0.127
RIP2=192.168.0.128
#RIPn=192.168.0.n
GW=192.168.0.1
start)
echo " start LVS of DirectorServer"
# set the Virtual IP Address
/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev tunl0
#Clear IPVS table
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i
#/sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -i
#Run LVS
/sbin/ipvsadm
#end
stop)
echo "close LVS Directorserver"
ifconfig tunl0 down
/sbin/ipvsadm -C
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
libnet.tar 下载地址:[url]http://www.packetfactory.net/libnet/[/url] 稳定版本是:1.1.2.1
e2fsprogs 可以用rpm 安装光盘
heartbeat-2.0.2.tar.gz 下载地址: [url]http://www.linux-ha.org/download/[/url]
2.1安装
cd libnet
./configure
make
make install
cd heartbeat-1.99.4
./ConfigureMe configure --disable-swig --disable-snmp-subagent
make
make install
cp doc/ha.cf doc/haresources doc/authkeys /etc/ha.d/
cp ldirectord/ldirectord.cf /etc/ha.d/
配置:
#debugfile /var/log/ha-debug
logfile /var/log/ha-log #指名heartbeat的日志存放位置
#crm yes #支持ClusterResourceManager(集群资源管理)功能
#bcast eth1 #指明心跳方式使用以太广播方式,并且是在eth1接口上进行广播。
logfacility local0
keepalive 2#指明心跳时间为2秒(即每两秒钟在eth1上发送一次广播)。
deadtime 30#指定在30秒内没有心跳信号,则立即切换服务。
warntime 10 #指明心跳延迟的时间为十秒。当10秒钟内备份机不能联系上主机(当前活动的服务器,即无心跳信号),就会往日志中写入一个警
initdead 120 #With some configurations, the network takes some time to start working after a reboot. This is a separate
udpport 694#Use port number 694 for bcast or ucast communication. This is the default, and the official IANA registered port
serial /dev/ttyS0
mcast eth0 225.0.0.1 694 1 0
auto_failback on
#stonith baytech /etc/ha.d/conf/stonith.baytech
# 如果使用该特性,则在内核中装入"softdog"内核模块,用来生成实际的设备文件,输入"insmod softdog"加载模块。
# 输入"grep misc /proc/devices"(应为10),输入"cat /proc/misc | grep watchdog"(应为130)。
# 生成设备文件:"mknod /dev/watchdog c 10 130" 。
#watchdog /dev/watchdog
node nsbak.ghb.com
# 所以当网络中断时,并不会进行Load Balancer和Backup之间的切换。
# 可以通过ipfail插件,设置'ping nodes'来解决这一问题。详细说明参考hearbeat文档。
#ping 192.168.136.1 172.16.0.1
ping_group group1 192.168.0.25 192.168.0.126
respawn root /usr/lib/heartbeat/ipfail
apiauth ipfail gid=root uid=root
#apiauth ipfail uid=hacluster
#apiauth ccm uid=hacluster
#apiauth cms uid=hacluster
#apiauth ping gid=haclient uid=alanr,root
#apiauth default gid=haclient
ns.ghb.com IPaddr::192.168.0.127/24/eth0 httpd
#设置ns.ghb.com为主节点,集群服务器的ip地址为192.168.0.100 netmask 为255.255.255.240集群的服务有httpd
1 crc
#2 sha1 sha1_any_password
#3 md5 md5_any_password
备份节点192.168.0.126 上的heartbeat和apache的配置与节点1要完全相同,lvs配置也要相同。
2.2
完装完毕进行测试,关闭主节点机器,另一台自动接管,主节点恢复后自动接管回服务。如果以上测试没有问题,那么开始和lvs整合。
Ldirectord的作用是监测Real Server,当Real Server失效时,把它从Load Balancer列表中删除,恢复时重新添加,在安装heartbeat时已经
# Global Directives
checktimeout=3
checkinterval=1
fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
quiescent=yes
virtual=192.168.0.100:80
real=192.168.0.127:80 gate
real=192.168.0.128:80 gate
fallback=127.0.0.1:80 gate
service=http
request="test.html"
receive="Test Page"
virtualhost=www.funbsd.net
scheduler=rr
#persistent=600
#netmask=255.255.255.255
protocol=tcp
在每个Real Server的中添加监控页:
echo "Test Page" >> /var/www/html/test.html
修改heartbeat的资源文件/etc/ha.d/haresources
ns.ghb.com 192.168.0.100 tunlvs ldirectord httpd
四、考虑充份使用资源,将备份节点也做为realserver.
1.director server 需要在脚本文件中将添加realserver,我们预先设置所有机器为realserver。
# description: start LVS of Directorserver
VIP=192.168.0.100
RIP1=192.168.0.127
RIP2=192.168.0.128
RIP3=192.168.0.25
RIP4=192.168.0.126
GW=192.168.0.1
start)
echo " start LVS of DirectorServer"
# set the Virtual IP Address
/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev tunl0
#Clear IPVS table
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i
/sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -i
/sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -i
#Run LVS
/sbin/ipvsadm
#end
stop)
echo "close LVS Directorserver"
ifconfig tunl0 down
/sbin/ipvsadm -C
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
# Global Directives
checktimeout=3
checkinterval=1
fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
quiescent=yes
virtual=192.168.0.100:80
real=192.168.0.126:80 gate
real=192.168.0.127:80 gate
real=192.168.0.128:80 gate
real=192.168.0.25:80 gate
fallback=127.0.0.1:80 gate
service=http
request="test.html"
receive="Test Page"
virtualhost=www.funbsd.net
scheduler=rr
#persistent=600
#netmask=255.255.255.255
protocol=tcp
more /etc/init.d/closetunl
#!/bin/sh
# create in 200608 ghb
# description: close tunl0 and arp_ignore
VIP=192.168.0.100
start)
echo "start director server and close tunl"
ifconfig tunl0 down
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
echo "start Real Server"
ifconfig tunl0 $VIP netmask 255.255.255.255 broadcast $VIP up
/sbin/route add -host $VIP dev tunl0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p
*)
echo "Usage: lvs {start|stop}"
exit 1
esac
5、修改/etc/ha.d/haresources
ns.wdxc.com closetunl 192.168.0.100 tunlvs ldirectord httpd
[url]http://192.168.0.100[/url] 应该可以轮到四台机器上