要求:通过使用LVS的直接路由来实现服务器的负载均衡
注:在做实验之前一定要先关闭每台主机的防火墙与SELinux
拓扑图
#
LVS服务器配置:
1> 开启转发功能
[root@localhost ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
2> 安装lvs控制软件ipvsadm
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# cd /mnt/cdrom/Cluster
[root@localhost Cluster]# rpm -ivh ipvsadm-1.24-10.i386.rpm
warning: ipvsadm-1.24-10.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ###################################### [100%]
1:ipvsadm ###################################### [100%]
3> 创建规则
[root@localhost Cluster]# ipvsadm -A -t 192.168.2.11:80 -s rr
[root@localhost Cluster]# ipvsadm -a -t 192.168.2.11:80 -r 192.168.2.20 -g
[root@localhost Cluster]# ipvsadm -a -t 192.168.2.11:80 -r 192.168.2.30 -g
4> 保存规则并启动服务
[root@localhost Cluster]# service ipvsadm save
Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]
[root@localhost Cluster]# service ipvsadm start
Clearing the current IPVS table: [ OK ]
Applying IPVS configuration: [ OK ]
Http server 1 配置
1> 安装http服务器软件
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# cd /mnt/cdrom/Server/
[root@localhost Server]# rpm -ivh httpd-2.2.3-31.el5.i386.rpm
warning: httpd-2.2.3-31.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ################################## [100%]
1:httpd #################################### [100%]
[root@localhost Server]#
2> 开启服务
[root@localhost Server]# service httpd start
Starting httpd: [ OK ]
3> 为http服务创建一个主页
[root@localhost Server]# echo "111111" > /var/www/html/index.html
4> 开启arp过滤
先查看arp支持的状态
[root@localhost Server]# sysctl -a | grep arp
dev.parport.parport0.devices.lp.timeslice = 200
dev.parport.parport0.devices.active = none
dev.parport.parport0.modes = PCSPP,TRISTATE
dev.parport.parport0.dma = -1
dev.parport.parport0.irq = 7
dev.parport.parport0.base-addr = 888 0
dev.parport.parport0.spintime = 500
dev.parport.default.spintime = 500
dev.parport.default.timeslice = 200
net.ipv4.conf.eth1.arp_accept = 0
net.ipv4.conf.eth1.arp_ignore = 0
net.ipv4.conf.eth1.arp_announce = 0
net.ipv4.conf.eth1.arp_filter = 0
net.ipv4.conf.eth1.proxy_arp = 0
net.ipv4.conf.eth0.arp_accept = 0
net.ipv4.conf.eth0.arp_ignore = 0
net.ipv4.conf.eth0.arp_announce = 0
net.ipv4.conf.eth0.arp_filter = 0
net.ipv4.conf.eth0.proxy_arp = 0
net.ipv4.conf.lo.arp_accept = 0
net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.conf.lo.arp_announce = 0
net.ipv4.conf.lo.arp_filter = 0
net.ipv4.conf.lo.proxy_arp = 0
net.ipv4.conf.default.arp_accept = 0
net.ipv4.conf.default.arp_ignore = 0
net.ipv4.conf.default.arp_announce = 0
net.ipv4.conf.default.arp_filter = 0
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.arp_accept = 0
net.ipv4.conf.all.arp_ignore = 0
net.ipv4.conf.all.arp_announce = 0
net.ipv4.conf.all.arp_filter = 0
net.ipv4.conf.all.proxy_arp = 0
对其进行过滤
[root@localhost ~]# echo "net.ipv4.conf.all.arp_ignore = 2" >> /etc/sysctl.conf
[root@localhost ~]# echo "net.ipv4.conf.eth0.arp_announce = 1" >> /etc/sysctl.conf
5> 添加到主机192.168.2.11的路由
[root@localhost ~]# route add -host 192.168.2.11 dev lo:0