先簡單的介紹下關(guān)于LVS負(fù)載均衡
LVS(Linux Virtual Server)Linux服務(wù)器集群系統(tǒng)
在lvs環(huán)境中,需要設(shè)定以下的參數(shù)
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce |
先來看看關(guān)于arp_ignore和arp_announce的有關(guān)介紹
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_ignore:定義對(duì)目標(biāo)地址為本地IP的ARP詢問不同的應(yīng)答模式0
0 - (默認(rèn)值): 回應(yīng)任何網(wǎng)絡(luò)接口上對(duì)任何本地IP地址的arp查詢請(qǐng)求
1 - 只回答目標(biāo)IP地址是來訪網(wǎng)絡(luò)接口本地地址的ARP查詢請(qǐng)求
2 -只回答目標(biāo)IP地址是來訪網(wǎng)絡(luò)接口本地地址的ARP查詢請(qǐng)求,且來訪IP必須在該網(wǎng)絡(luò)接口的子網(wǎng)段內(nèi)
3 - 不回應(yīng)該網(wǎng)絡(luò)界面的arp請(qǐng)求,而只對(duì)設(shè)置的唯一和連接地址做出回應(yīng)
4-7 - 保留未使用
8 -不回應(yīng)所有(本地地址)的arp查詢
有關(guān)arp_announce的相關(guān)介紹:
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_announce:對(duì)網(wǎng)絡(luò)接口上,本地IP地址的發(fā)出的,ARP回應(yīng),作出相應(yīng)級(jí)別的限制: 確定不同程度的限制,宣布對(duì)來自本地源IP地址發(fā)出Arp請(qǐng)求的接口
0 - (默認(rèn)) 在任意網(wǎng)絡(luò)接口(eth0,eth1,lo)上的任何本地地址
1 -盡量避免不在該網(wǎng)絡(luò)接口子網(wǎng)段的本地地址做出arp回應(yīng). 當(dāng)發(fā)起ARP請(qǐng)求的源IP地址是被設(shè)置應(yīng)該經(jīng)由路由達(dá)到此網(wǎng)絡(luò)接口的時(shí)候很有用.此時(shí)會(huì)檢查來訪IP是否為所有接口上的子網(wǎng)段內(nèi)ip之一.如果改來訪IP不屬于各個(gè)網(wǎng)絡(luò)接口上的子網(wǎng)段內(nèi),那么將采用級(jí)別2的方式來進(jìn)行處理.
2 - 對(duì)查詢目標(biāo)使用最適當(dāng)?shù)谋镜氐刂?/span>.在此模式下將忽略這個(gè)IP數(shù)據(jù)包的源地址并嘗試選擇與能與該地址通信的本地地址.首要是選擇所有的網(wǎng)絡(luò)接口的子網(wǎng)中外出訪問子網(wǎng)中包含該目標(biāo)IP地址的本地地址. 如果沒有合適的地址被發(fā)現(xiàn),將選擇當(dāng)前的發(fā)送網(wǎng)絡(luò)接口或其他的有可能接受到該ARP回應(yīng)的網(wǎng)絡(luò)接口來進(jìn)行發(fā)送.
關(guān)于對(duì)arp_announce 理解的一點(diǎn)補(bǔ)充
Assume that a linux box X has three interfaces - eth0, eth1 and eth2. Each interface has an IP address IP0, IP1 and IP2. When a local application tries to send an IP packet with IP0 through the eth2. Unfortunately, the target node’s mac address is not resolved. Thelinux box X will send the ARP request to know the mac address of the target(or the gateway). In this case what is the IP source address of the “ARP request message”? The IP0- the IP source address of the transmitting IP or IP2 - the outgoing interface? Until now(actually just 3 hours before) ARP request uses the IP address assigned to the outgoing interface(IP2 in the above example) However the linux’s behavior is a little bit different. Actually the selection of source address in ARP request is totally configurable bythe proc variable “arp_announce” If we want to use the IP2 not the IP0 in the ARP request, we should change the value to 1 or 2. The default value is 0 - allow IP0 is used for ARP request. |
其實(shí)就是路由器的問題,因?yàn)槁酚善饕话闶莿?dòng)態(tài)學(xué)習(xí)ARP包的(一般動(dòng)態(tài)配置DHCP的話),當(dāng)內(nèi)網(wǎng)的機(jī)器要發(fā)送一個(gè)到外部的ip包,那么它就會(huì)請(qǐng)求 路由器的Mac地址,發(fā)送一個(gè)arp請(qǐng)求,這個(gè)arp請(qǐng)求里面包括了自己的ip地址和Mac地址,而linux默認(rèn)是使用ip的源ip地址作為arp里面 的源ip地址,而不是使用發(fā)送設(shè)備上面的 ,這樣在lvs這樣的架構(gòu)下,所有發(fā)送包都是同一個(gè)VIP地址,那么arp請(qǐng)求就會(huì)包括VIP地址和設(shè)備 Mac,而路由器收到這個(gè)arp請(qǐng)求就會(huì)更新自己的arp緩存,這樣就會(huì)造成ip欺騙了,VIP被搶奪,所以就會(huì)有問題。
arp緩存為什么會(huì)更新了,什么時(shí)候會(huì)更新呢,為了減少arp請(qǐng)求的次數(shù),當(dāng)主機(jī)接收到詢問自己的arp請(qǐng)求的時(shí)候,就會(huì)把源ip和源Mac放入自 己的arp表里面,方便接下來的通訊。如果收到不是詢問自己的包(arp是廣播的,所有人都收到),就會(huì)丟掉,這樣不會(huì)造成arp表里面無用數(shù)據(jù)太多導(dǎo)致 有用的記錄被刪除。
聯(lián)系客服