操作系统centos5.5 32
cat haresources | grep -v ^#
primary.localdomain lvs ldirectord
cat authkeys | grep -v ^#
auth 1
1 sha1 HI!
cat ldirectord.cf | grep -v ^#
checktimeout=3
checkinterval=1
fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
logfile="local0"
emailalert=""
emailalertfreq=3600
emailalertstatus=all
quiescent=no
virtual=192.168.213.1:80
real=192.168.213.130:80 gate
real= 192.168.213.131:80 gate
fallback=127.0.0.1:80 gate
service=http
scheduler=wrr
persistent=5
protocol=tcp
checktype=connect
checkport=80
echo -e "--------------------------------------------------------------------------------------------------------------------"
cat /etc/ha.d/lvs
lvs scripts
#!/bin/bash
# description: start LVS of DirectorServer
#Written by :NetSeek GW=192.168.1.254
## website director vip
GW=192.168.213.1
WEB_VIP=192.168.213.131
WEB_RIP1=192.168.213.130
#WEB_RIP2=192.168.1.110
. /etc/rc.d/init.d/functions
logger $0 called with $1
case "$1" in
start)
/sbin/iptables -F
/sbin/iptables -Z
/sbin/ipvsadm --set 30 5 60
/sbin/ifconfig eth1:0 $WEB_VIP broadcast $WEB_VIP netmask 255.255.255.255 up
/sbin/route add -host $WEB_VIP dev eth1:0
/sbin/ipvsadm -A -t $WEB_VIP:80 -s wrr -p 3
/sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP1:80 -g -w 1
/sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP2:80 -g -w 1
touch /var/lock/subsys/ipvsadm >/dev/null 2>&1
/sbin/arping -I eth1 -c 5 -s $WEB_VIP $GW >/dev/null 2>&1
;;
stop)
/sbin/ipvsadm -C
/sbin/ipvsadm -Z
ifconfig eth1:0 down
route del $WEB_VIP >/dev/null 2>&1
rm -rf /var/lock/subsys/ipvsadm >/dev/null 2>&1
/sbin/arping -I eth1 -c 5 -s $WEB_VIP $GW
echo "ipvsadm stoped"
;;
status)
if [ ! -e /var/lock/subsys/ipvsadm ]; then
echo "ipvsadm is stoped"
exit 1
else
ipvsadm -ln
echo "..........ipvsadm is OK."
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
exit 0
echo -e "--------------------------------------------------------------------------------------------------------------------"
mv /etc/ha.d/lvs /etc/init.d/ ; chmod 755 /etc/init.d/lvs ; ln -s /etc/init.d/lvs
/etc/ha.d/resource.d/ ; cp /etc/init.d/lvs /etc/ha.d/
chkconfig heartbeat on
#-------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------
backup server
yum -y install libnet
yum -y install heartbeat-*
yum -y install heartbeat
yum -y install ipvsadm
rm -f /etc/hosts && scp -P 22 /etc/hosts
rm -fr /etc/ha.d/ && scp -P 22 -r /etc/
rm -f /etc/ha.d/resource.d/lvs && cp /etc/ha.d/lvs /etc/init.d/ && ln -s /etc/init.d/lvs
/etc/ha.d/resource.d/
sed -i 's/ucast eth0 172.16.0.101/ucast eth0 172.16.0.100/' /etc/ha.d/ha.cf
sed -i 's/ping 172.16.0.101/ping 172.16.0.100/' /etc/ha.d/ha.cf
chkconfig heartbeat on
#-------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------
real1 client:
cat /root/real.sh
#/bin/sh
VIP=192.168.213.1
source /etc/rc.d/init.d/functions
case "$1" in
start)
echo "start LVS of RealServer"
/sbin/ifconfig lo:0 ${VIP} broadcast ${VIP} netmask 255.255.255.255 up
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
;;
stop)
/sbin/ifconfig lo:0 down
echo "Close LVS of RealServer"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "wrong,please use start|stop"
exit 1
esac
#-------------------------------------------------------------------------------------------------------------------------------
chmod 755 /root/real.sh
./real.sh start
#-------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------
real2 client:
scp -P 22 .
chmod 755 /root/real.sh
./real.sh start
#-------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------
test
start primary and backup Priority primary backup
/etc/init.d/heartbeat start
primary server enter awk '/Running/{print $0}' /var/log/ha-log
show
2011/12/29_02:58:24 info: Running /etc/ha.d/resource.d/lvs start
2011/12/29_02:58:31 info: Running /etc/ha.d/resource.d/ldirectord start
Success
Or failure
#-------------------------------------------------------------------------------------------------------------------------------
backup server enter awk '/remote*/{print $0}' /var/log/ha-log
show
2011/12/29_03:12:01 info: remote resource transition completed
Success
Or failure
ipvsadm
查看真实主机
阅读(1338) | 评论(0) | 转发(0) |