搜索

3.2. 使​​​​​​​用​​​​​​​直​​​​​​​接​​​​​​​路​​​​​​​由​​​​​​​的​​​​​​​ LVS

download PDF
As mentioned in 第 1.4.2 节 “直​​​​​​​接​​​​​​​路​​​​​​​由​​​​​​​”, direct routing allows real servers to process and route packets directly to a requesting user rather than passing outgoing packets through the LVS router. Direct routing requires that the real servers be physically connected to a network segment with the LVS router and be able to process and direct outgoing packets as well.
网​​​​​​​络​​​​​​​布​​​​​​​局​​​​​​​
在​​​​​​​直​​​​​​​接​​​​​​​路​​​​​​​由​​​​​​​ LVS 设​​​​​​​置​​​​​​​中​​​​​​​,LVS 路​​​​​​​由​​​​​​​器​​​​​​​需​​​​​​​要​​​​​​​接​​​​​​​收​​​​​​​进​​​​​​​入​​​​​​​请​​​​​​​求​​​​​​​,并​​​​​​​将​​​​​​​其​​​​​​​路​​​​​​​由​​​​​​​到​​​​​​​适​​​​​​​当​​​​​​​的​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​进​​​​​​​行​​​​​​​处​​​​​​​理​​​​​​​。​​​​​​​接​​​​​​​着​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​需​​​​​​​要​​​​​​​直​​​​​​​接​​​​​​​将​​​​​​​响​​​​​​​应​​​​​​​路​​​​​​​由​​​​​​​给​​​​​​​客​​​​​​​户​​​​​​​端​​​​​​​。​​​​​​​例​​​​​​​如​​​​​​​:如​​​​​​​果​​​​​​​客​​​​​​​户​​​​​​​端​​​​​​​在​​​​​​​互​​​​​​​联​​​​​​​网​​​​​​​中​​​​​​​并​​​​​​​通​​​​​​​过​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​向​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​发​​​​​​​送​​​​​​​数​​​​​​​据​​​​​​​包​​​​​​​,那​​​​​​​么​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​必​​​​​​​须​​​​​​​可​​​​​​​以​​​​​​​通​​​​​​​过​​​​​​​互​​​​​​​联​​​​​​​网​​​​​​​直​​​​​​​接​​​​​​​连​​​​​​​接​​​​​​​到​​​​​​​客​​​​​​​户​​​​​​​端​​​​​​​。​​​​​​​这​​​​​​​可​​​​​​​通​​​​​​​过​​​​​​​为​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​配​​​​​​​置​​​​​​​网​​​​​​​关​​​​​​​来​​​​​​​将​​​​​​​数​​​​​​​据​​​​​​​包​​​​​​​发​​​​​​​送​​​​​​​到​​​​​​​互​​​​​​​联​​​​​​​网​​​​​​​中​​​​​​​。​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​池​​​​​​​中​​​​​​​的​​​​​​​每​​​​​​​个​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​可​​​​​​​以​​​​​​​有​​​​​​​它​​​​​​​们​​​​​​​独​​​​​​​立​​​​​​​的​​​​​​​网​​​​​​​关​​​​​​​(且​​​​​​​每​​​​​​​个​​​​​​​网​​​​​​​关​​​​​​​都​​​​​​​有​​​​​​​其​​​​​​​自​​​​​​​身​​​​​​​的​​​​​​​互​​​​​​​联​​​​​​​网​​​​​​​连​​​​​​​接​​​​​​​),这​​​​​​​可​​​​​​​允​​​​​​​许​​​​​​​最​​​​​​​大​​​​​​​限​​​​​​​度​​​​​​​的​​​​​​​吞​​​​​​​吐​​​​​​​量​​​​​​​和​​​​​​​可​​​​​​​伸​​​​​​​缩​​​​​​​性​​​​​​​。​​​​​​​但​​​​​​​对​​​​​​​于​​​​​​​典​​​​​​​型​​​​​​​ LVS 设​​​​​​​置​​​​​​​,真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​可​​​​​​​通​​​​​​​过​​​​​​​一​​​​​​​个​​​​​​​网​​​​​​​关​​​​​​​(也​​​​​​​就​​​​​​​是​​​​​​​一​​​​​​​个​​​​​​​网​​​​​​​络​​​​​​​连​​​​​​​接​​​​​​​)进​​​​​​​行​​​​​​​沟​​​​​​​通​​​​​​​。​​​​​​​

重要

我​​​​​​​们​​​​​​​不​​​​​​​推​​​​​​​荐​​​​​​​您​​​​​​​将​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​作​​​​​​​为​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​的​​​​​​​网​​​​​​​关​​​​​​​使​​​​​​​用​​​​​​​,因​​​​​​​为​​​​​​​这​​​​​​​样​​​​​​​会​​​​​​​带​​​​​​​来​​​​​​​不​​​​​​​必​​​​​​​要​​​​​​​的​​​​​​​对​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​复​​​​​​​杂​​​​​​​设​​​​​​​置​​​​​​​和​​​​​​​网​​​​​​​络​​​​​​​负​​​​​​​载​​​​​​​,这​​​​​​​些​​​​​​​内​​​​​​​容​​​​​​​我​​​​​​​们​​​​​​​将​​​​​​​在​​​​​​​ NAT 路​​​​​​​由​​​​​​​中​​​​​​​存​​​​​​​在​​​​​​​的​​​​​​​网​​​​​​​络​​​​​​​瓶​​​​​​​颈​​​​​​​中​​​​​​​再​​​​​​​次​​​​​​​论​​​​​​​述​​​​​​​。​​​​​​​
硬​​​​​​​件​​​​​​​
使​​​​​​​用​​​​​​​直​​​​​​​接​​​​​​​路​​​​​​​由​​​​​​​的​​​​​​​ LVS 系​​​​​​​统​​​​​​​的​​​​​​​硬​​​​​​​件​​​​​​​要​​​​​​​求​​​​​​​与​​​​​​​其​​​​​​​它​​​​​​​ LVS 布​​​​​​​局​​​​​​​类​​​​​​​似​​​​​​​。​​​​​​​当​​​​​​​需​​​​​​​要​​​​​​​在​​​​​​​Red Hat Enterprise Linux 中​​​​​​​运​​​​​​​行​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​来​​​​​​​处​​​​​​​理​​​​​​​进​​​​​​​入​​​​​​​请​​​​​​​求​​​​​​​并​​​​​​​为​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​执​​​​​​​行​​​​​​​负​​​​​​​载​​​​​​​平​​​​​​​衡​​​​​​​时​​​​​​​,真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​不​​​​​​​一​​​​​​​定​​​​​​​是​​​​​​​ Linux 机​​​​​​​器​​​​​​​才​​​​​​​可​​​​​​​正​​​​​​​常​​​​​​​工​​​​​​​作​​​​​​​。​​​​​​​每​​​​​​​个​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​需​​​​​​​要​​​​​​​一​​​​​​​个​​​​​​​或​​​​​​​者​​​​​​​两​​​​​​​个​​​​​​​ NIC(要​​​​​​​看​​​​​​​是​​​​​​​否​​​​​​​有​​​​​​​备​​​​​​​用​​​​​​​路​​​​​​​由​​​​​​​器​​​​​​​)。​​​​​​​您​​​​​​​可​​​​​​​以​​​​​​​用​​​​​​​两​​​​​​​个​​​​​​​ NIC 来​​​​​​​缓​​​​​​​解​​​​​​​配​​​​​​​置​​​​​​​并​​​​​​​完​​​​​​​全​​​​​​​分​​​​​​​离​​​​​​​流​​​​​​​量​​​​​​​ — 进​​​​​​​入​​​​​​​请​​​​​​​求​​​​​​​由​​​​​​​一​​​​​​​个​​​​​​​ NIC 处​​​​​​​理​​​​​​​,用​​​​​​​另​​​​​​​一​​​​​​​个​​​​​​​ NIC 将​​​​​​​数​​​​​​​据​​​​​​​包​​​​​​​路​​​​​​​由​​​​​​​到​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​。​​​​​​​
因​​​​​​​为​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​会​​​​​​​绕​​​​​​​过​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​并​​​​​​​将​​​​​​​外​​​​​​​发​​​​​​​的​​​​​​​数​​​​​​​据​​​​​​​包​​​​​​​直​​​​​​​接​​​​​​​发​​​​​​​送​​​​​​​给​​​​​​​客​​​​​​​户​​​​​​​端​​​​​​​,所​​​​​​​以​​​​​​​需​​​​​​​要​​​​​​​连​​​​​​​接​​​​​​​到​​​​​​​互​​​​​​​联​​​​​​​网​​​​​​​的​​​​​​​网​​​​​​​关​​​​​​​。​​​​​​​要​​​​​​​获​​​​​​​得​​​​​​​最​​​​​​​高​​​​​​​性​​​​​​​能​​​​​​​和​​​​​​​可​​​​​​​用​​​​​​​性​​​​​​​,每​​​​​​​个​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​应​​​​​​​使​​​​​​​用​​​​​​​独​​​​​​​立​​​​​​​网​​​​​​​关​​​​​​​连​​​​​​​接​​​​​​​到​​​​​​​互​​​​​​​联​​​​​​​网​​​​​​​,这​​​​​​​些​​​​​​​独​​​​​​​立​​​​​​​网​​​​​​​关​​​​​​​有​​​​​​​其​​​​​​​专​​​​​​​用​​​​​​​的​​​​​​​连​​​​​​​接​​​​​​​连​​​​​​​接​​​​​​​到​​​​​​​客​​​​​​​户​​​​​​​端​​​​​​​连​​​​​​​接​​​​​​​的​​​​​​​载​​​​​​​体​​​​​​​网​​​​​​​络​​​​​​​(比​​​​​​​如​​​​​​​互​​​​​​​联​​​​​​​网​​​​​​​或​​​​​​​者​​​​​​​内​​​​​​​部​​​​​​​网​​​​​​​络​​​​​​​)。​​​​​​​
软​​​​​​​件​​​​​​​
There is some configuration outside of Piranha Configuration Tool that needs to be done, especially for administrators facing ARP issues when using LVS via direct routing. Refer to 第 3.2.1 节 “直​​​​​​​接​​​​​​​路​​​​​​​由​​​​​​​及​​​​​​​ arptables_jf or 第 3.2.2 节 “直​​​​​​​接​​​​​​​路​​​​​​​由​​​​​​​及​​​​​​​ iptables for more information.

3.2.1. 直​​​​​​​接​​​​​​​路​​​​​​​由​​​​​​​及​​​​​​​ arptables_jf

In order to configure direct routing using arptables_jf, each real server must have their virtual IP address configured, so they can directly route packets. ARP requests for the VIP are ignored entirely by the real servers, and any ARP packets that might otherwise be sent containing the VIPs are mangled to contain the real server's IP instead of the VIPs.
用​​​​​​​ arptables_jf 方​​​​​​​法​​​​​​​,可​​​​​​​将​​​​​​​应​​​​​​​用​​​​​​​程​​​​​​​序​​​​​​​绑​​​​​​​定​​​​​​​到​​​​​​​每​​​​​​​个​​​​​​​ VIP 或​​​​​​​者​​​​​​​所​​​​​​​有​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​服​​​​​​​务​​​​​​​的​​​​​​​端​​​​​​​口​​​​​​​。​​​​​​​例​​​​​​​如​​​​​​​:arptables_jf 方​​​​​​​法​​​​​​​允​​​​​​​许​​​​​​​ Apache HTTP Server 的​​​​​​​多​​​​​​​个​​​​​​​事​​​​​​​件​​​​​​​明​​​​​​​确​​​​​​​绑​​​​​​​定​​​​​​​到​​​​​​​系​​​​​​​统​​​​​​​中​​​​​​​的​​​​​​​不​​​​​​​同​​​​​​​ VIP 而​​​​​​​运​​​​​​​行​​​​​​​。​​​​​​​使​​​​​​​用​​​​​​​ arptables_jf 的​​​​​​​ IPTables 选​​​​​​​项​​​​​​​还​​​​​​​有​​​​​​​非​​​​​​​常​​​​​​​优​​​​​​​越​​​​​​​的​​​​​​​性​​​​​​​能​​​​​​​。​​​​​​​
但​​​​​​​使​​​​​​​用​​​​​​​ arptables_jf 方​​​​​​​法​​​​​​​,无​​​​​​​法​​​​​​​使​​​​​​​用​​​​​​​标​​​​​​​准​​​​​​​Red Hat Enterprise Linux 系​​​​​​​统​​​​​​​配​​​​​​​置​​​​​​​工​​​​​​​具​​​​​​​将​​​​​​​ VIP 配​​​​​​​置​​​​​​​为​​​​​​​在​​​​​​​引​​​​​​​导​​​​​​​时​​​​​​​启​​​​​​​动​​​​​​​。​​​​​​​
要​​​​​​​将​​​​​​​每​​​​​​​个​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​配​​​​​​​置​​​​​​​为​​​​​​​忽​​​​​​​略​​​​​​​虚​​​​​​​拟​​​​​​​ IP 地​​​​​​​址​​​​​​​的​​​​​​​ ARP 请​​​​​​​求​​​​​​​,请​​​​​​​按​​​​​​​以​​​​​​​下​​​​​​​步​​​​​​​骤​​​​​​​操​​​​​​​作​​​​​​​:
  1. 为​​​​​​​每​​​​​​​个​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​的​​​​​​​每​​​​​​​个​​​​​​​虚​​​​​​​拟​​​​​​​ IP 地​​​​​​​址​​​​​​​创​​​​​​​建​​​​​​​ ARP 表​​​​​​​条​​​​​​​目​​​​​​​(均​​​​​​​衡​​​​​​​器​​​​​​​使​​​​​​​用​​​​​​​ real_ip 作​​​​​​​为​​​​​​​联​​​​​​​络​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​的​​​​​​​ IP,通​​​​​​​常​​​​​​​此​​​​​​​ IP 会​​​​​​​绑​​​​​​​定​​​​​​​到​​​​​​​ eth0):
    arptables -A IN -d <virtual_ip> -j DROP
    arptables -A OUT -s <virtual_ip> -j mangle --mangle-ip-s <real_ip>
    
    这​​​​​​​会​​​​​​​导​​​​​​​致​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​忽​​​​​​​略​​​​​​​所​​​​​​​有​​​​​​​来​​​​​​​自​​​​​​​虚​​​​​​​拟​​​​​​​ IP 地​​​​​​​址​​​​​​​的​​​​​​​ ARP 请​​​​​​​求​​​​​​​,并​​​​​​​修​​​​​​​改​​​​​​​可​​​​​​​能​​​​​​​包​​​​​​​含​​​​​​​虚​​​​​​​拟​​​​​​​ IP 的​​​​​​​外​​​​​​​发​​​​​​​ ARP 响​​​​​​​应​​​​​​​,以​​​​​​​便​​​​​​​其​​​​​​​包​​​​​​​含​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​的​​​​​​​真​​​​​​​正​​​​​​​ IP。​​​​​​​Piranha 唯​​​​​​​一​​​​​​​应​​​​​​​该​​​​​​​回​​​​​​​应​​​​​​​ ARP 请​​​​​​​求​​​​​​​的​​​​​​​节​​​​​​​点​​​​​​​应​​​​​​​该​​​​​​​为​​​​​​​目​​​​​​​前​​​​​​​活​​​​​​​跃​​​​​​​的​​​​​​​ LVS 节​​​​​​​点​​​​​​​。​​​​​​​
  2. 为​​​​​​​每​​​​​​​个​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​完​​​​​​​成​​​​​​​此​​​​​​​操​​​​​​​作​​​​​​​后​​​​​​​,在​​​​​​​每​​​​​​​个​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​中​​​​​​​输​​​​​​​入​​​​​​​以​​​​​​​下​​​​​​​命​​​​​​​令​​​​​​​保​​​​​​​存​​​​​​​ ARP 表​​​​​​​条​​​​​​​目​​​​​​​:
    service arptables_jf save
    chkconfig --level 2345 arptables_jf on
    chkconfig 命​​​​​​​令​​​​​​​将​​​​​​​导​​​​​​​致​​​​​​​系​​​​​​​统​​​​​​​在​​​​​​​重​​​​​​​新​​​​​​​引​​​​​​​导​​​​​​​时​​​​​​​重​​​​​​​新​​​​​​​载​​​​​​​入​​​​​​​ arptables 配​​​​​​​置​​​​​​​ — 在​​​​​​​启​​​​​​​动​​​​​​​网​​​​​​​络​​​​​​​之​​​​​​​前​​​​​​​。​​​​​​​
  3. 在​​​​​​​所​​​​​​​有​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​中​​​​​​​使​​​​​​​用​​​​​​​ ifconfig 命​​​​​​​令​​​​​​​配​​​​​​​置​​​​​​​虚​​​​​​​拟​​​​​​​ IP 地​​​​​​​址​​​​​​​来​​​​​​​生​​​​​​​成​​​​​​​ IP 别​​​​​​​名​​​​​​​。​​​​​​​例​​​​​​​如​​​​​​​:
    # ifconfig eth0:1 192.168.76.24 netmask 255.255.252.0 broadcast 192.168.79.255 up
    或​​​​​​​者​​​​​​​用​​​​​​​利​​​​​​​用​​​​​​​ ip 命​​​​​​​令​​​​​​​的​​​​​​​ iproute2,例​​​​​​​如​​​​​​​:
    # ip addr add 192.168.76.24 dev eth0
    如​​​​​​​前​​​​​​​所​​​​​​​述​​​​​​​,使​​​​​​​用​​​​​​​红​​​​​​​帽​​​​​​​系​​​​​​​统​​​​​​​配​​​​​​​置​​​​​​​工​​​​​​​具​​​​​​​无​​​​​​​法​​​​​​​将​​​​​​​虚​​​​​​​拟​​​​​​​ IP 地​​​​​​​址​​​​​​​配​​​​​​​置​​​​​​​为​​​​​​​在​​​​​​​引​​​​​​​导​​​​​​​时​​​​​​​启​​​​​​​动​​​​​​​。​​​​​​​一​​​​​​​种​​​​​​​解​​​​​​​决​​​​​​​方​​​​​​​法​​​​​​​就​​​​​​​是​​​​​​​将​​​​​​​这​​​​​​​些​​​​​​​命​​​​​​​令​​​​​​​放​​​​​​​在​​​​​​​ /etc/rc.d/rc.local 文​​​​​​​件​​​​​​​中​​​​​​​。​​​​​​​
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.