拓扑图:
1、LVS配置脚本:
需要安装:ipvsadm-1.24-10.i386.rpm
vi /etc/rc.d/init.d/lvsdr
#!/bin/bash
vip=192.168.0.116
web1=192.168.0.104
web2=192.168.0.114
./etc/rc.d/init.d/functions
case "$1" in
start)
echo "start
lvs-dr"
echo "1"
> /proc/sys/net/ipv4/ip_forward
ifconfig eth0:0 ${vip} broadcast ${vip} netmask 255.255.255.255
up
route add -host ${vip} dev eth0:0
ipvsadm -C
ipvsadm -A -t ${vip}:80 -s rr
ipvsadm -a -t ${vip}:80 -r ${web1}:80 -g
ipvsadm -a -t ${vip}:80 -r ${web2}:80 -g
ipvsadm
;;
stop)
echo "stop
lvs-dr"
echo "0"
>/proc/sys/net/ipv4/ip_forward
ipvsadm -C
ifconfig eth0:0 down
;;
*)
echo
"Usage:$0 {start|stop}"
exit 1
esac
service lvsdr start #启动服务
service lvsdr stop #停止服务
2、lvsweb1配置
vi /etc/rc.d/init.d/lvsweb
#!/bin/bash
vip=192.168.1.116
./etc/rc.d/init.d/functions
case "$1" in
start)
echo "start lvs-web1"
ifconfig lo:0 ${vip} broadcast ${vip} netmask 255.255.255.255
up
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
;;
stop)
echo "stop lvs-web1"
ifconfig lo:0 down
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 "Usage:$0 {start|stop}"
exit 1
esac
启动脚本:
[root@linux-2 local]# service lvsweb start
start lvs-web1
3、lvsweb2配置
vi /etc/rc.d/init.d/lvsweb
#!/bin/bash
vip=192.168.1.116
./etc/rc.d/init.d/functions
case "$1" in
start)
echo "start lvs-web2"
ifconfig lo:0 ${vip} broadcast ${vip} netmask 255.255.255.255
up
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
;;
stop)
echo "stop lvs-web2"
ifconfig lo:0 down
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 "Usage:$0 {start|stop}"
exit 1
esac
启动脚本:
[root@linux-3 ~]# service lvsweb start
start lvs-web2
#####################到此简单的LVS-DR集群成功##################
4,监控LVS (在LVS服务器上安装)
1、安装rrdtool工具
tar zxvf rrdtool-1.2.30.tar.gz
cd rrdtool-1.2.30
./configure --prefix=/usr/local/rrdtool
make&&make
install
echo “/usr/local/rrdtool/lib”
>>/etc/ld.so.conf
ldconf -v
2、安装lvs-rrd
tar tar zxvf lvs-rrd-v0.7.tar.gz
mv lvs-rrd-v0.7 /var/www/html/lvs-rrd
3、配置lvs-rrd
cd /var/www/html/lvs-rrd
vi lvs.rrd.update (只需要配置指定的路径即可)
RRDTOOL="/usr/local/rrdtool/bin/rrdtool"
IPVSADM="/sbin/ipvsadm"
WORKDIR="/var/www/html/lvs-rrd"
vi graph-lvs.sh
WORKDIR="/var/www/html/lvs-rrd"
RRDTOOL="/usr/local/rrdtool/bin/rrdtool"
GRAPHS="$WORKDIR/graphs"
WEBPATH="/lvs-rrd/graphs"
4、设置权限:
chown -R apache.apache graphs/
5 、使用crontab 更新
crontab -e
* * * * * /var/www/html/lvs-rrd/lvs.rrd.update 2>
/dev/null > /dev/null
测试结果: