Chinaunix首页 | 论坛 | 博客
  • 博客访问: 363176
  • 博文数量: 80
  • 博客积分: 2056
  • 博客等级: 大尉
  • 技术积分: 961
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-19 12:17
文章分类

全部博文(80)

文章存档

2011年(9)

2010年(13)

2009年(41)

2008年(17)

我的朋友

分类: LINUX

2009-01-04 10:48:44

#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=
 
#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/

阅读(1658) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-03-19 13:52:32

写的不错,就是注解太精简了,呵呵