1: 10.152.98.110 VIP
10.152.98.111 lvs_server
10.152.98.112 real_server1
10.152.98.113 real_server2
1):实验目的1:通过在lvs_server上部署lvs,负载112、113 的服务(DR模式)
lsmod |grep ip_vs
看到ipvs模块没有加载进内核
modprobe ip_vs 加载
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
ftp://ftp.muug.mb.ca/mirror/centos/6.6/os/x86_64/Packages/popt-static-1.13-7.el6.x86_64.rpm
yum install -y gcc make kernel-devel openssl-devel popt* libnl*
rpm -ivh popt-static-1.13-7.el6.x86_64.rpm
ln -s /usr/src/kernels/2.6.32-279.el6.x86_64/ /usr/src/linux
tar -zxvf ipvsadm-1.26.tar.gz
make && make install
2)或者rpm -Uvh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
通过yum -y install ipvsadm安装
[root@oracle10g src]# lsmod |grep ip_vs
ip_vs 115490 0
ipv6 322541 15 ip_vs
libcrc32c 1246 1 ip_vs
在111上部署好之后,写入脚本:
vi /etc/init.d/lvs_vip.sh
#!/bin/sh
VIP=10.152.98.110
RIP1=10.152.98.112
RIP2=10.152.98.113
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo "start LVS of DirectorServer"
#Set the Virtual IP Address
/sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev eth0:1
#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 -g
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
#Run Lvs
/sbin/ipvsadm
;;
stop)
echo "close LVS Directorserver"
/sbin/ipvsadm -C
/sbin/ifconfig eth0:1 down
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
在两台real_server上写入脚本:
vi /etc/init.d/real_vip.sh
#!/bin/bash
VIP=10.152.98.110
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo "reparing for Real Server"
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
ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP up
/sbin/route add -host $VIP dev lo:0
;;
stop)
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: lvs {start|stop}"
exit 1
esac
先启动lvs_vip.sh start
可以通过命令查看ipvsadm -Ln
在两台real-server 分别安装apache
yum -y install httpd
echo "<dl><dt>web1-real-server1(10.152.98.112)</dt></dl>" > /var/www/html/index.html
echo "<dl><dt>web2-real-server2(10.152.98.113)</dt></dl>" > /var/www/html/index.html
[root@lvs-server /]# curl http://10.152.98.112
<dl><dt>web1-real-server1(10.152.98.112)</dt></dl>
[root@lvs-server /]# curl http://10.152.98.113
<dl><dt>web2-real-server2(10.152.98.113)</dt></dl>
可以看到单独可以访问
启动两台服务器上的real_vip.sh start
在另外一台服务器上,
for ((i=0;i<=100;i++))
do
curl -I -s http://10.152.98.80 >>/dev/null 2>&1
done
[root@lvs-server ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.152.98.110:80 rr
-> 10.152.98.112:80 Route 1 0 50
-> 10.152.98.113:80 Route 1 0 51