免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 671 | 回复: 0
打印 上一主题 下一主题

lvs+heartbeat+ldirector [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-04 10:48 |只看该作者 |倒序浏览

#environment
GW:192.168.1.254
Director
VIP:192.168.1.200
eth0:192.168.1.120
eth1:192.168.10.1
slave Director
eth0:192.168.1.121
eth1:192.168.10.2
realserver
192.168.1.122
192.168.1.123
config gw 192.168.1.254
#on director
yum -y install ipvsadm
yum -y install heartbeat
yum -y install heartbeat-ldirectord
yum -y install e2fsprogs
cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d
cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d
cp /usr/share/doc/heartbeat-ldirectord-2.1.3/ldirectord.cf /etc/ha.d
#config director
#put "lvs_vs" in /etc/init.d/
# lvs_vs
#!/bin/sh
#chkconfig: 2345 20 80
# description: start LVS   of  Directorserver
echo "0" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/conf/all/send_redirects
echo "1" > /proc/sys/net/ipv4/conf/default/send_redirects
echo "1" > /proc/sys/net/ipv4/conf/eth0/send_redirects
VIP1=192.168.1.200
RIP1=192.168.1.122
RIP2=192.168.1.123
. /etc/rc.d/init.d/functions
case "$1" in
    start)
        echo " start LVS  of DirectorServer"
# set the Virtual  IP Address
        /sbin/ifconfig eth0:0 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up
        /sbin/route add -host $VIP1 dev eth0:0
#Clear IPVS table
        /sbin/ipvsadm -C
#set LVS
        /sbin/ipvsadm -A -t $VIP1:80 -s rr
        /sbin/ipvsadm -a -t $VIP1:80 -r $RIP1:80 -g
        /sbin/ipvsadm -a -t $VIP1:80 -r $RIP2:80 -g
#Run LVS
        /sbin/ipvsadm
        ;;
    stop)
        echo "close LVS Directorserver"
        /sbin/ifconfig eth0:0 down
        /sbin/ipvsadm -C
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
esac
#on realserver
#lvs_rs
#!/bin/bash
# lvsdrrs init script to hide loopback interfaces on LVS-DR
# Real servers. Modify this script to suit
# your needs. You at least need to set the correct VIP address(es).
# Script to start LVS DR real server.
#
# chkconfig: 2345 20 80
# description: LVS DR real server
#
# You must set the VIP address to use here:
VIP=192.168.1.200
host=`/bin/hostname`
case "$1" in
start)
# Start LVS-DR real server on this machine.
        /sbin/ifconfig lo down
        /sbin/ifconfig lo up
        echo "0" > /proc/sys/net/ipv4/ip_forward
        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
        /sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 up
        /sbin/route add -host $VIP dev lo:0
;;
stop)
# Stop LVS-DR real server loopback device(s).
        /sbin/ifconfig lo:0 down
;;
status)
# Status of LVS-DR real server.
        islothere=`/sbin/ifconfig lo:0 | grep $VIP`
        isrothere=`netstat -rn | grep "lo" | grep $VIP`
        if [ ! "$islothere" -o ! "$isrothere" ];then
            echo "LVS-DR real server Stopped."
        else
            echo "LVS-DR Running."
        fi
;;
*)
# Invalid entry.
        echo "$0: Usage: $0 {start|status|stop}"
        exit 1
;;
esac
#config ldirectory heartbeat
#on director
#cat /etc/ha.d/ldirectord.cf
checktimeout=3
checkinterval=1
fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
quiescent=yes
virtual=192.168.1.200:80
        real=192.168.1.122:80 gate
        real=192.168.1.123:80 gate
        fallback=127.0.0.1:80 gate
        service=http
        request="test.html"
        receive="Test Page"
        scheduler=rr
        protocol=tcp
        virtualhost=www.test.com

#cat /etc/ha.d/ha.cf
logfile /var/log/ha-log
logfacility     local0
keepalive 2
deadtime 30
initdead 120
udpport 694
bcast   eth1            # Linux
auto_failback on
watchdog /dev/watchdog
node    master # uname -n
node    slave  # uname -n
ping_group group1 192.168.10.1 192.168.10.2
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
#cat /etc/ha.d/haresources
master 192.168.10.1 lvs_vs ldirectord
#chmod 600 /etc/ha.d/authkeys
#cat /etc/ha.d/authkeys
auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!
#modprobe softdog
#grep misc /proc/devices
10 misc
#cat /proc/misc | grep watchdog
130 watchdog
#mknod /dev/watchdog c 10 130
#tcpdump -i eth1 -n -p udp port 694
#ipvsadm -l -c
#scp -r /etc/ha.d/* 192.168.10.2:/etc/ha.d/


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/66903/showart_1772374.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP