LVS:DR模式(Direct Routing)部署实验

摘要:
本文描述了如何在kvm虚拟环境中部署实验LVS的DR模式。并使用tcp转储分析ip数据包。网络结构图kvm节点192.168.7.2 |br_ EBridge/eth7:192.168.7.33eth14:192.168.7.99lvs虚拟主机服务器虚拟主机eth8:192.168.88.10eth12:192.168.88.20/br_ LVS网桥实验步骤1.创建网桥:br_ E和br_ LVS,并设置ip#kvm节点$ifconfigbr_ E192.168.7.2 Netmask 255.255.02.lvs configuration$ipvsadm-A-t192.168.7.33:8000 srr$ipvsadm-at192.168.7.33:8000-r192.168.88.20-g3.server configuration#让主机处理dst为192.168.7.33的ip数据包#子网掩码必须为255.255.255.255。如果为255.255.0,IP分组将不会被处理$ifconfiglo:0192.16 8.7.33 Netmask 255.255.255up/etc/sysctl。conf配置(似乎没有必要将IP包的src设置为lvs-IP。

本文介绍怎样在kvm的虚拟环境下,部署实验LVS的DR模式。包含网络结构图,怎样配置。以及使用tcpdump分析ip包。

网络结构图

                              kvm节点(client)
                               192.168.7.2 (CIP)
                                           |
                                          br_e网桥
                                 /                    
                       (VIP)
         eth7:192.168.7.33      eth14: 192.168.7.99
          lvs虚拟主机                      server虚拟主机
                    (DIP)                         (RIP)
         eth8:192.168.88.10     eth12: 192.168.88.20
                                                         /
                                         br_lvs网桥


实验步骤

1.创建bridge:br_e和br_lvs,并分别设置ip

# kvm节点
$ ifconfig br_e 192.168.7.2 netmask 255.255.255.0

2.lvs配置

$ ipvsadm -A -t 192.168.7.33:8000 -s rr
$ ipvsadm -a -t 192.168.7.33:8000 -r 192.168.88.20 -g

3.server配置

# 让主机处理dst为192.168.7.33的ip包
# 子网掩码必须是255.255.255.255,假设是255.255.255.0则不会处理ip包
$ ifconfig lo:0 192.168.7.33 netmask 255.255.255.255 up

/etc/sysctl.conf配置(好像不须要设置?)
ip_forward=0  # 不须要配置为1
rp_filter = 0   # 默认配置

# 解决arp问题
# 官方文档说lo不须要设置arp
# 注销后没问题
# net.ipv4.conf.lo.arp_ignore = 0
# net.ipv4.conf.lo.arp_announce = 0
# eth14是br_e上的网卡
# 仅仅有当arp请求的目标ip和eth14上绑定ip同样时,eth14才会处理
# 否则lvs的vip会和server的vip冲突
# 在本例中,br_e网络中会存在两个192.168.7.33
net.ipv4.conf.eth14.arp_ignore = 1
# 用于eth14发送arp请求时src ip?
net.ipv4.conf.eth14.arp_announce = 2
# net.ipv4.conf.all.arp_ignore = 1
# net.ipv4.conf.all.arp_announce = 2


4.在server虚拟主机上开启web服务

# 默认监听8000port
$ python -m SimpleHTTPServer

5.在kvm节点(client)上

$ curl http://192.168.7.33:8000

tcpdump分析IP包

[kvm send: br_e] 发出ip包(syn)
00:1a:a0:21:21:65 > de:ad:be:ef:24:46, 192.168.7.2.51091 > 192.168.7.33.8000: Flags [S], seq 3773377896

[lvs recv: br_e]lvs收到ip包
 00:1a:a0:21:21:65 > de:ad:be:ef:24:46, 192.168.7.2.51091 > 192.168.7.33.8000: Flags [S], seq 3773377896,

[lvs send: br_lvs] lvs改动ip包的mac,目标mac改成server的mac
00:16:3e:5d:a6:b3 > 52:54:00:ba:3d:b9
, 192.168.7.2.51091 > 192.168.7.33.8000: Flags [S], seq 3773377896,

[server recv: br_lvs] server接收ip包(mac同样)
 00:16:3e:5d:a6:b3 > 52:54:00:ba:3d:b9, 192.168.7.2.51091 > 192.168.7.33.8000: Flags [S], seq 3773377896

[server send: br_e] server发出ip包(ack) 。ip包的src是lvs的ip。 dst是client的ip
52:54:00:c1:a7:5e > 00:1a:a0:21:21:65
, 192.168.7.33.8000 > 192.168.7.2.51091: Flags [S.], seq 3629588945, ack 3773377897

[kvm recv: br_e] client收到ip包(ack)
52:54:00:c1:a7:5e > 00:1a:a0:21:21:65, 192.168.7.33.8000 > 192.168.7.2.51091: Flags [S.], seq 3629588945, ack 3773377897


arp_ignore和arp_announce
arp_announce - INTEGER
Define different restriction levels for announcing the local
source IP address from IP packets in ARP requests sent on
interface:
0 - (default) Use any local address, configured on any interface
1 - Try to avoid local addresses that are not in the target's
subnet for this interface. This mode is useful when target
hosts reachable via this interface require the source IP
address in ARP requests to be part of their logical network
configured on the receiving interface. When we generate the
request we will check all our subnets that include the
target IP and will preserve the source address if it is from
such subnet. If there is no such subnet we select source
address according to the rules for level 2.
2 - Always use the best local address for this target.
In this mode we ignore the source address in the IP packet
and try to select local address that we prefer for talks with
the target host. Such local address is selected by looking
for primary IP addresses on all our subnets on the outgoing
interface that include the target IP address. If no suitable
local address is found we select the first local address
we have on the outgoing interface or on all other interfaces,
with the hope we will receive reply for our request and
even sometimes no matter the source IP address we announce.

The max value from conf/{all,interface}/arp_announce is used.

Increasing the restriction level gives more chance for
receiving answer from the resolved target while decreasing
the level announces more valid sender's information.

arp_ignore - INTEGER
Define different modes for sending replies in response to
received ARP requests that resolve local target IP addresses:
0 - (default): reply for any local target IP address, configured
on any interface
1 - reply only if the target IP address is local address
configured on the incoming interface
2 - reply only if the target IP address is local address
configured on the incoming interface and both with the
sender's IP address are part from same subnet on this interface
3 - do not reply for local addresses configured with scope host,
only resolutions for global and link addresses are replied
4-7 - reserved
8 - do not reply for all local addresses

The max value from conf/{all,interface}/arp_ignore is used
when ARP request is received on the {interface}

免责声明:文章转载自《LVS:DR模式(Direct Routing)部署实验》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇JMeter定时器设置延迟与同步UE4_武器4_武器切换(下)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

NLog简单配置与使用

对项目添加NLog 安装完成后,在项目里面会自动引入该引入的dll,并且会添加如下两个文件   NLog的配置主要是在这个config文件里。当然也可以将这个文件里面的nlog节点复制到项目配置文件App.config/Web.config里面。  NLog的配置文件主要有3个节点variable,targets,rules。 variable节点用于...

Linux多网卡负载均衡 : bond

USERCTL=no/yes 普通用户是否可以关闭或启用网关 -------------------------------- 在这介绍的Linux双网卡绑定实现就是使用两块网卡虚拟成为一块网卡,这个聚合起来的设备看起来是一个单独的以太网接口设备,通俗点讲就是两块网卡具有相同的IP地址而并行链接聚合成一个逻辑链路工作。其实这项技术在Sun和Cisco中早已...

CentOS 7修改默认启动界面

文章目录 CentOS 7修改默认启动界面 查看当前默认启动界面 设置默认启动界面为图形界面 设置默认启动界面为命令行界面 CentOS 7修改默认启动界面 环境说明: 内核版本:3.10.0-1062.9.1.el7.x86_64 查看当前默认启动界面 [root@jarvis ~]# systemctl get-default m...

Apache Ant介绍

 ant详解: http://www.cnblogs.com/huozhicheng/archive/2010/04/08/2533199.html ant使用指南:http://www.cnblogs.com/hoojo/archive/2013/06/14/java_ant_project_target_task_run.html Apache Ant...

设计模式学习笔记十一:适配器模式(Adapter Pattern)

    1.概述    在软件开发中,我们经常会遇到系统间集成,在系统集成时,最常见的问题就是系统间的接口不一致。很多能够满足功能的系统模块,由于接口不一致,导致无法使用。例如,常用的媒体播放器是MS Media player和RealPlayer,他们的文件结构和软件接口完全不同,前者支持WMF格式的音频和视频,后者支持RM格式的音频和视频。如果我们希望自...

LVS配置

今天面试时,突然被面试官问到怎样用shell命令搞定某个文件夹下java代码行数的统计。 想了一下,基本思路就是找到这个文件夹下面的所有java文件,然后每个文件统计一下代码,外层套个for循环,叠加一下结果,就拿到想要的结果了。 不过显然面试官希望我用一句shell搞定,当场晕菜了,没搞定。回来想了一下,其实确实不是啥太难的问题。 最粗略版 Shel...