LVS realserver配置机制

2024-02-16 02:08
文章标签 配置 机制 lvs realserver

本文主要是介绍LVS realserver配置机制,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在配置LVS的real server的时候,总是会有以下几句:

ifconfig lo:0 $VIP netmask 255.255.255.255broadcast $VIP

 /sbin/route add -host $VIP dev 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

 sysctl -p > /dev/null 2>&1


实验配置为:

VIP:192.168.1.99

realserver: 192.168.1.41

client: 192.168.1.182

当前realserver机器的路由如下:

[root@internal41 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0   *                   255.255.255.0      U            0      0        0 eth1
192.168.2.0     *                  255.255.255.0      U            0      0        0 eth0
162.251.0.0     *                  255.255.0.0           U            0      0        0 eth1
default         billrouter.cn. 0.0.0.0                     UG          0      0        0 eth1


如果不设置arp_ignore和arp_announce,那么通过一台其他机器(192.168.1.182)ping VIP(192.168.1.98)的时候,将会有响应如下:

[root@internal41 ~]# tcpdump -i eth1 -nn icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes
10:03:58.128381 IP 192.168.1.182 > 192.168.1.99: ICMP echo request, id 512, seq 61952, length 40
10:03:58.128447 IP 192.168.1.99 > 192.168.1.182: ICMP echo reply, id 512, seq 61952, length 40
10:03:59.129950 IP 192.168.1.182 > 192.168.1.99: ICMP echo request, id 512, seq 62208, length 40
10:03:59.129961 IP 192.168.1.99 > 192.168.1.182: ICMP echo reply, id 512, seq 62208, length 40
10:04:00.130915 IP 192.168.1.182 > 192.168.1.99: ICMP echo request, id 512, seq 62464, length 40
10:04:00.130926 IP 192.168.1.99 > 192.168.1.182: ICMP echo reply, id 512, seq 62464, length 40
10:04:01.131884 IP 192.168.1.182 > 192.168.1.99: ICMP echo request, id 512, seq 62720, length 40
10:04:01.131897 IP 192.168.1.99 > 192.168.1.182: ICMP echo reply, id 512, seq 62720, length 40


可见响应数据包通过eth1返回。

而LVS就是要禁止这样的事情发生,使得realserver不能响应对VIP的ARP请求。


先看一下arp_ignore与arp_announce的定义:
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}


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.


对一个网络interface比如eth0来说,如果不设置arp_ignore (默认值为0),那么它将对发往其他interface的ARP请求(该interface无法响应的条件下)进行响应。

对于本实验环境而言,realserver的lo:0上绑定了VIP,如果不设置arp_ignore,那么发往lo:0的ARP请求将会通过eth1返回响应,

将arp_ignore设置为1以后,eth1不会帮lo:0返回响应。其实对本实验环境来说,抑制ARP请求通过echo "1" > /proc/sys/net/ipv4/conf/eth1/arp_ignore就可以实现,最开始的做法应该是针对所有情况的通用做法。


再来看arp_announce,正好与arp_ignore相对应,arp_announce是针对网络interface往外发送ARP请求的时候,设置源IP地址,默认为0,比如lo:0通过eth1往外发ARP请求,默认情况下源IP地址是lo:0上绑定的VIP地址,这样接收方就会confuse,因为realserver不止一个,这样会出现一个IP对应多个MAC地址的情况,实际应该只是最后一次的生效。 设置为2就保证lo:0通过eth1发ARP请求的时候,源IP地址是eth1本身的IP地址。对本实验环境来说,设置echo "2" > /proc/sys/net/ipv4/conf/eth1/arp_announce就可以满足条件,最开始的做法是通用做法。


当设置好以后,在client上先通过arp -d清除arp表,然后去ping VIP,发现已经ping不通了。




这篇关于LVS realserver配置机制的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/713191

相关文章

Nacos注册中心和配置中心的底层原理全面解读

《Nacos注册中心和配置中心的底层原理全面解读》:本文主要介绍Nacos注册中心和配置中心的底层原理的全面解读,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录临时实例和永久实例为什么 Nacos 要将服务实例分为临时实例和永久实例?1.x 版本和2.x版本的区别

如何搭建并配置HTTPD文件服务及访问权限控制

《如何搭建并配置HTTPD文件服务及访问权限控制》:本文主要介绍如何搭建并配置HTTPD文件服务及访问权限控制的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、安装HTTPD服务二、HTTPD服务目录结构三、配置修改四、服务启动五、基于用户访问权限控制六、

CentOS 7 YUM源配置错误的解决方法

《CentOS7YUM源配置错误的解决方法》在使用虚拟机安装CentOS7系统时,我们可能会遇到YUM源配置错误的问题,导致无法正常下载软件包,为了解决这个问题,我们可以替换YUM源... 目录一、备份原有的 YUM 源配置文件二、选择并配置新的 YUM 源三、清理旧的缓存并重建新的缓存四、验证 YUM 源

Windows 系统下 Nginx 的配置步骤详解

《Windows系统下Nginx的配置步骤详解》Nginx是一款功能强大的软件,在互联网领域有广泛应用,简单来说,它就像一个聪明的交通指挥员,能让网站运行得更高效、更稳定,:本文主要介绍W... 目录一、为什么要用 Nginx二、Windows 系统下 Nginx 的配置步骤1. 下载 Nginx2. 解压

VS配置好Qt环境之后但无法打开ui界面的问题解决

《VS配置好Qt环境之后但无法打开ui界面的问题解决》本文主要介绍了VS配置好Qt环境之后但无法打开ui界面的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目UKeLvb录找到Qt安装目录中designer.UKeLvBexe的路径找到vs中的解决方案资源

windows系统上如何进行maven安装和配置方式

《windows系统上如何进行maven安装和配置方式》:本文主要介绍windows系统上如何进行maven安装和配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不... 目录1. Maven 简介2. maven的下载与安装2.1 下载 Maven2.2 Maven安装2.

Apache 高级配置实战之从连接保持到日志分析的完整指南

《Apache高级配置实战之从连接保持到日志分析的完整指南》本文带你从连接保持优化开始,一路走到访问控制和日志管理,最后用AWStats来分析网站数据,对Apache配置日志分析相关知识感兴趣的朋友... 目录Apache 高级配置实战:从连接保持到日志分析的完整指南前言 一、Apache 连接保持 - 性

MySQL 安装配置超完整教程

《MySQL安装配置超完整教程》MySQL是一款广泛使用的开源关系型数据库管理系统(RDBMS),由瑞典MySQLAB公司开发,目前属于Oracle公司旗下产品,:本文主要介绍MySQL安装配置... 目录一、mysql 简介二、下载 MySQL三、安装 MySQL四、配置环境变量五、配置 MySQL5.1

mybatis的mapper对应的xml写法及配置详解

《mybatis的mapper对应的xml写法及配置详解》这篇文章给大家介绍mybatis的mapper对应的xml写法及配置详解,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,... 目录前置mapper 对应 XML 基础配置mapper 对应 xml 复杂配置Mapper 中的相

Jvm sandbox mock机制的实践过程

《Jvmsandboxmock机制的实践过程》:本文主要介绍Jvmsandboxmock机制的实践过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、背景二、定义一个损坏的钟1、 Springboot工程中创建一个Clock类2、 添加一个Controller