码迷,mamicode.com
首页 > 其他好文 > 详细

LVS的DR设置测试

时间:2017-08-21 14:45:02      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:ifdown   proc   rtu   mask   eal   清空   sbin   route   nat   

dir:
ipvsadm -C
清空之前ipvsadm
 
iptables -t nat -F
防火墙规则清空v
 
rs1,rs2:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
更改rs1,rs2网卡网关信息 为正常网关
 
dir:
ifdown eth1 (ifdown eth0:1)
关闭不用到的ip
DR模式需要多个公网IP ,将客户请求直接发出给客户端
 
3. LVS/DR 配置
 
三台机器:
director(eth010.222.138.200, vip eth0:1: 10.222.138.10)
real server1(eth0 rip: 10.222. 138.201, vip lo:0: 10.222.138.10)
real server2(eth0 rip: 10.222.138.202, vip lo:0: 10.222.138.10)
 
Director 上 vim /usr/local/sbin/lvs_dr.sh //增加 
 

#! /bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
ipv=/sbin/ipvsadm
vip=10.222.138.10
rs1=10.222.138.201
rs2=10.222.138.202
ifconfig eth0:1 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev eth0:1
$ipv -C
$ipv -A -t $vip:80 -s wrr
$ipv -a -t $vip:80 -r $rs1:80 -g -w 3
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1

 

两台rs上:vim /usr/local/sbin/lvs_dr_rs.sh

 

#! /bin/bash
vip=10.222.138.10
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip 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

 

然后director上执行: bash /usr/local/sbin/lvs_dr.sh
两台rs上执行: bash /usr/local/sbin/lvs_dr_rs.sh
 
 

dir 上 

[root@dir network-scripts]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.222.138.10:80 wrr
-> 10.222.138.201:80 Route 3 0 0
-> 10.222.138.202:80 Route 1 0 0

 

打开另外一台centos ,curl 10.222.138.10来测试 

[root@master ~]# curl 10.222.138.10
201.....................
[root@master ~]# curl 10.222.138.10
201.....................
[root@master ~]# curl 10.222.138.10
201.....................
[root@master ~]# curl 10.222.138.10
202----------------------------
[root@master ~]# curl 10.222.138.10
201.....................
[root@master ~]# curl 10.222.138.10
201.....................
[root@master ~]# curl 10.222.138.10
201.....................
[root@master ~]# curl 10.222.138.10
202----------------------------
[root@master ~]# curl 10.222.138.10
201.....................
[root@master ~]# curl 10.222.138.10
201.....................
[root@master ~]# curl 10.222.138.10
201.....................
[root@master ~]# curl 10.222.138.10
202----------------------------

 

安装权重分别循环显示rs1,rs2的内容

 

LVS的DR设置测试

标签:ifdown   proc   rtu   mask   eal   清空   sbin   route   nat   

原文地址:http://www.cnblogs.com/weifeng1463/p/7404105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!