本次实验基于rhel6.5版本虚拟机
调度器server1 IP:172.25.35.1
服务端1 server2 IP:172.25.35.2
服务端2 server3 IP:172.25.35.3
调度器配置:
vim /etc/yum.repos.d/yum.repo #添加本地yum 源
[LoadBalancer]
name=LoadBalancer
baseurl=file:///rhel6.5/LoadBalancer
enabled=1
gpgcheck=0
yum install ipvsadm -y #安装管理工具
ip addr add 172.25.35.100/24 dev eth0 #给eth0添加第二个ip(临时)
[root@server1 rhel6.5]# ipvsadm -A -t 172.25.35.100:80 -s rr
[root@server1 rhel6.5]# ipvsadm -a -t 172.25.35.100:80 -r 172.25.35.2:80 -g
[root@server1 rhel6.5]# ipvsadm -a -t 172.25.35.100:80 -r 172.25.35.3:80 -g
服务端1配置:
开启Apache服务
/etc/init.d/httpd start
ip addr add 172.25.35.100/32 dev eth0 临时增加ip,重启后消失
服务端2配置:
开启Apache服务
/etc/init.d/httpd start
ip addr add 172.25.35.100/32 dev eth0
客户端测试:
curl 172.25.35.100
arp -an | grep 100 看缓存
arp -d 172.25.35.100 清缓存
注:
随机访问三个服务器
访问调度器IP会轮询访问 1,2
访问服务器1,2则一直访问
2.访问控制arp,使客户端只访问调度器:
服务器1:
yum install arptables_jf
arptables -A IN -d 172.25.35.100 -j DROP
arptables -A OUT -s 172.25.35.100 -j mangle --mangle-ip-s 172.25.35.2
保存策略
[root@server2 ~]# /etc/init.d/arptables_jf save
Saving current rules to /etc/sysconfig/arptables: [ OK ]
查看策略
[root@server2 ~]# arptables -L
Chain IN (policy ACCEPT)
target source-ip destination-ip source-hw destination-hw hlen op hrd pro
DROP anywhere 172.25.35.100 anywhere anywhere any any any any
Chain OUT (policy ACCEPT)
target source-ip destination-ip source-hw destination-hw hlen op hrd pro
mangle 172.25.35.100 anywhere anywhere anywhere any any any any --mangle-ip-s 172.25.35.2
Chain FORWARD (policy ACCEPT)
target source-ip destination-ip source-hw destination-hw hlen op hrd pro
服务器3:
yum install arptables_jf
arptables -A IN -d 172.25.35.100 -j DROP
arptables -A OUT -s 172.25.35.100 -j mangle --mangle-ip-s 172.25.35.3
保存策略
[root@server3 ~]# /etc/init.d/arptables_jf save
Saving current rules to /etc/sysconfig/arptables: [ OK ]
客户端测试:
arp -d 172.25.35.100
轮询访问,为服务端1.
[root@foundation35 Packages]# curl 172.25.35.100
server2's Apache server
[root@foundation35 Packages]# curl 172.25.35.100
server3's Apache server
[root@foundation35 Packages]# curl 172.25.35.100
server2's Apache server
[root@foundation35 Packages]# curl 172.25.35.100
server3's Apache server