环境
client eth0 192.168.200.100
router eth0 192.168.200.254
eth0:1 192.168.100.254
分发器 eth0 192.168.100.253
apache1 eth0 192.168.100.251
apache2 eth0 192.168.100.250
client 配置
[client ~]#ifconfig eth0 192.168.200.100
[client ~]#route add default gw 192.168.200.254
router配置
打开包转发
[router ~]#vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
#或 echo 1 > /proc/sys/net/ipv4/ip_forward
[router ~]#sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
分发器配置
[ff ~]#ifconfig eth0:0 192.168.100.252 netmask 255.255.255.255 broadcast 192.168.100.252 up
[ff ~]#route add -host 192.168.100.252 dev eth0:0
[ff ~]#mount /dev/cdrom /mnt/
mount: block device /dev/cdrom is write-protected, mounting
read-only
[ff ~]#cd /mnt/Cluster
[ff /mnt/Cluster]#rpm -ivh ipvsadm-1.24-10.i386.rpm
#或yum安装
#[root@localhost ~]# vim /etc/yum.repos.d/server.repo
#[Cluster]
#name=Cluster
#baseurl=file:///mnt/Cluster
#enabled=1
#gpgcheck=0
#[root@localhost ~]# mount /dev/cdrom /mnt/
#[root@localhost ~]# yum install ipvsadm -y
[ff ~]#ipvsadm -A -t 192.168.100.252:80 -s rr
[ff ~]#ipvsadm -a -t 192.168.100.252:80 -r 192.168.100.251 -g
[ff ~]#ipvsadm -a -t 192.168.100.252:80 -r 192.168.100.250 -g
apache1 server 配置
安装apache
[apache1 ~]#yum install httpd -y
绑定vip
[apache1 ~]#ifconfig lo:0 192.168.100.252 netmask 255.255.255.255 broadcast 192.168.100.252 up
[apache1 ~]#route add -host 192.168.100.252 dev lo:0
[apache1 ~]#route add default gw 192.168.100.254
[apache1 ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[apache1 ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[apache1 ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[apache1 ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[apache1 ~]#echo 251 > /var/www/html/index.html
[apache1 ~]#/etc/init.d/httpd restart
apache2 server 配置
安装apache
[apache2 ~]#yum install httpd -y
[apache2 ~]#ifconfig lo:0 192.168.100.252 netmask 255.255.255.255 broadcast 192.168.100.252 up
[apache1 ~]#route add -host 192.168.100.252 dev lo:0
[apache2 ~]#route add default gw 192.168.100.254
[apache2 ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[apache2 ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[apache2 ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[apache2 ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[apache2 ~]#echo 250 > /var/www/html/index.html
重启服务
[apache2 ~]#/etc/init.d/httpd restart
测试
client端
[root@localhost ~]# elinks http://192.168.100.252/index.html
--dump
250
[root@localhost ~]# elinks http://192.168.100.252/index.html
--dump
251
[root@localhost ~]# elinks http://192.168.100.252/index.html
--dump
250
[root@localhost ~]# elinks http://192.168.100.252/index.html
--dump
251