码迷,mamicode.com
首页 > 系统相关 > 详细

linux系统构架 - LB集群之LVS的DR设置

时间:2016-01-23 18:21:51      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:

在lvs的nat模式的基础上

1.清空ipvsadm规则

 ipvsadm -C

查看
 ipvsadm -ln

2.清空iptables规则

iptables -t nat -F

3.修改rs的网卡配置,修改回来网关

 vi /etc/sysconfig/network-scripts/ifcfg-eth0

重启eth0
ifdown eth0; ifup eth0

4.dir网卡

 ifdown eth1

dirIP:192.168.1.118  rs1IP:192.168.1.116 rs2IP:192.168.1.115  都视为外网IP。

在dir上面添加虚拟IP,vip

 vim /usr/local/sbin/lvs_dr.sh
#! /bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
ipv=/sbin/ipvsadm
vip=192.168.1.100
rs1=192.168.1.116
rs2=192.168.1.115
ifconfig eth0:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev eth0:0
$ipv -C
$ipv -A -t $vip:80 -s rr
$ipv -a -t $vip:80 -r $rs1:80 -g -w 1
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1

echo 1 > /proc/sys/net/ipv4/ip_forward  //打开端口转发
ipv=/sbin/ipvsadm
vip=192.168.1.100    
rs1=192.168.1.116
rs2=192.168.1.115
ifconfig eth0:0 $vip broadcast $vip netmask 255.255.255.255 up  //VIP子网掩码是4个255,只发不收
route add -host $vip dev eth0:0  //增加一条路由
$ipv -C
$ipv -A -t $vip:80 -s rr
$ipv -a -t $vip:80 -r $rs1:80 -g -w 1
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1

sh !$
ifconfig

虚拟网卡已经出来了
eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:CC:11:E7
          inet addr:192.168.1.100  Bcast:192.168.1.100  Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 ipvsadm -ln



多出来一个VIP
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.1.100:80 rr
  -> 192.168.1.115:80             Route   1      0          0
  -> 192.168.1.116:80             Route   1      0          0

5.rs1-2都写个脚本

vim /usr/local/sbin/lvs_rs.sh
#! /bin/bash
vip=192.168.1.100
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
 ifconfig


启动了回环虚拟网卡
lo:0      Link encap:Local Loopback
          inet addr:192.168.1.100  Mask:255.255.255.255
          UP LOOPBACK RUNNING  MTU:16436  Metric:1

6.测试

 在第四台机器上curl  vip

linux系统构架 - LB集群之LVS的DR设置

标签:

原文地址:http://www.cnblogs.com/wangshaojun/p/5153648.html

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