第 1 章 Linux 虚​​​​​​​拟​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​总​​​​​​​览​​​​​​​


Linux 虚​​​​​​​拟​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​(LVS)是​​​​​​​一​​​​​​​组​​​​​​​用​​​​​​​来​​​​​​​在​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​间​​​​​​​平​​​​​​​衡​​​​​​​ IP 负​​​​​​​载​​​​​​​的​​​​​​​整​​​​​​​合​​​​​​​软​​​​​​​件​​​​​​​组​​​​​​​件​​​​​​​。​​​​​​​LVS 在​​​​​​​一​​​​​​​对​​​​​​​配​​​​​​​置​​​​​​​相​​​​​​​同​​​​​​​的​​​​​​​计​​​​​​​算​​​​​​​机​​​​​​​中​​​​​​​运​​​​​​​行​​​​​​​:一​​​​​​​个​​​​​​​是​​​​​​​活​​​​​​​跃​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​,一​​​​​​​个​​​​​​​是​​​​​​​备​​​​​​​用​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​。​​​​​​​活​​​​​​​跃​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​有​​​​​​​两​​​​​​​个​​​​​​​作​​​​​​​用​​​​​​​:
  • 平​​​​​​​衡​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​中​​​​​​​的​​​​​​​负​​​​​​​载​​​​​​​。​​​​​​​
  • 检​​​​​​​查​​​​​​​每​​​​​​​个​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​中​​​​​​​服​​​​​​​务​​​​​​​的​​​​​​​完​​​​​​​整​​​​​​​性​​​​​​​。​​​​​​​
备​​​​​​​用​​​​​​​路​​​​​​​由​​​​​​​器​​​​​​​的​​​​​​​任​​​​​​​务​​​​​​​是​​​​​​​监​​​​​​​控​​​​​​​活​​​​​​​跃​​​​​​​路​​​​​​​由​​​​​​​器​​​​​​​并​​​​​​​在​​​​​​​活​​​​​​​跃​​​​​​​路​​​​​​​由​​​​​​​器​​​​​​​出​​​​​​​错​​​​​​​的​​​​​​​事​​​​​​​件​​​​​​​中​​​​​​​扮​​​​​​​演​​​​​​​它​​​​​​​的​​​​​​​角​​​​​​​色​​​​​​​。​​​​​​​
本​​​​​​​章​​​​​​​提​​​​​​​供​​​​​​​了​​​​​​​ LVS 组​​​​​​​件​​​​​​​和​​​​​​​功​​​​​​​能​​​​​​​的​​​​​​​总​​​​​​​览​​​​​​​,它​​​​​​​们​​​​​​​由​​​​​​​以​​​​​​​下​​​​​​​部​​​​​​​分​​​​​​​组​​​​​​​成​​​​​​​:

1.1. A Basic LVS Configuration

图 1.1 “A Basic LVS Configuration” shows a simple LVS configuration consisting of two layers. On the first layer are two LVS routers — one active and one backup. Each of the LVS routers has two network interfaces, one interface on the Internet and one on the private network, enabling them to regulate traffic between the two networks. For this example the active router is using Network Address Translation or NAT to direct traffic from the Internet to a variable number of real servers on the second layer, which in turn provide the necessary services. Therefore, the real servers in this example are connected to a dedicated private network segment and pass all public traffic back and forth through the active LVS router. To the outside world, the servers appears as one entity.
A Basic LVS Configuration

图 1.1. A Basic LVS Configuration

Service requests arriving at the LVS routers are addressed to a virtual IP address, or VIP. This is a publicly-routable address the administrator of the site associates with a fully-qualified domain name, such as www.example.com, and is assigned to one or more virtual servers. A virtual server is a service configured to listen on a specific virtual IP. Refer to 第 4.6 节 “VIRTUAL SERVERS for more information on configuring a virtual server using the Piranha Configuration Tool. A VIP address migrates from one LVS router to the other during a failover, thus maintaining a presence at that IP address (also known as floating IP addresses).
VIP 地​​​​​​​址​​​​​​​还​​​​​​​可​​​​​​​以​​​​​​​是​​​​​​​同​​​​​​​样​​​​​​​将​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​连​​​​​​​接​​​​​​​到​​​​​​​互​​​​​​​联​​​​​​​网​​​​​​​的​​​​​​​设​​​​​​​备​​​​​​​的​​​​​​​别​​​​​​​名​​​​​​​。​​​​​​​例​​​​​​​如​​​​​​​:如​​​​​​​果​​​​​​​使​​​​​​​用​​​​​​​ eth0 连​​​​​​​接​​​​​​​到​​​​​​​互​​​​​​​联​​​​​​​网​​​​​​​,那​​​​​​​么​​​​​​​多​​​​​​​个​​​​​​​虚​​​​​​​拟​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​就​​​​​​​可​​​​​​​以​​​​​​​别​​​​​​​名​​​​​​​命​​​​​​​名​​​​​​​为​​​​​​​ eth0:1。​​​​​​​另​​​​​​​外​​​​​​​,每​​​​​​​个​​​​​​​虚​​​​​​​拟​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​还​​​​​​​可​​​​​​​以​​​​​​​根​​​​​​​据​​​​​​​服​​​​​​​务​​​​​​​关​​​​​​​联​​​​​​​到​​​​​​​不​​​​​​​同​​​​​​​的​​​​​​​设​​​​​​​备​​​​​​​。​​​​​​​例​​​​​​​如​​​​​​​:HTTP 流​​​​​​​量​​​​​​​可​​​​​​​由​​​​​​​ eth0:1 处​​​​​​​理​​​​​​​,而​​​​​​​ FTP 流​​​​​​​量​​​​​​​可​​​​​​​由​​​​​​​ eth0:2 处​​​​​​​理​​​​​​​。​​​​​​​
Only one LVS router is active at a time. The role of the active router is to redirect service requests from virtual IP addresses to the real servers. The redirection is based on one of eight supported load-balancing algorithms described further in 第 1.3 节 “LVS 调​​​​​​​度​​​​​​​总​​​​​​​览​​​​​​​”.
活​​​​​​​跃​​​​​​​路​​​​​​​由​​​​​​​器​​​​​​​还​​​​​​​通​​​​​​​过​​​​​​​ send/expect 脚​​​​​​​本​​​​​​​动​​​​​​​态​​​​​​​监​​​​​​​控​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​中​​​​​​​特​​​​​​​定​​​​​​​服​​​​​​​务​​​​​​​的​​​​​​​总​​​​​​​体​​​​​​​状​​​​​​​态​​​​​​​。​​​​​​​侦​​​​​​​测​​​​​​​服​​​​​​​务​​​​​​​的​​​​​​​状​​​​​​​态​​​​​​​需​​​​​​​要​​​​​​​动​​​​​​​态​​​​​​​数​​​​​​​据​​​​​​​,比​​​​​​​如​​​​​​​ HTTPS 或​​​​​​​者​​​​​​​ SSL。​​​​​​​管​​​​​​​理​​​​​​​员​​​​​​​还​​​​​​​可​​​​​​​以​​​​​​​调​​​​​​​用​​​​​​​外​​​​​​​部​​​​​​​可​​​​​​​执​​​​​​​行​​​​​​​程​​​​​​​序​​​​​​​。​​​​​​​如​​​​​​​果​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​中​​​​​​​的​​​​​​​某​​​​​​​个​​​​​​​服​​​​​​​务​​​​​​​失​​​​​​​效​​​​​​​,活​​​​​​​跃​​​​​​​路​​​​​​​由​​​​​​​器​​​​​​​会​​​​​​​停​​​​​​​止​​​​​​​向​​​​​​​该​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​发​​​​​​​送​​​​​​​任​​​​​​​务​​​​​​​,直​​​​​​​到​​​​​​​它​​​​​​​能​​​​​​​够​​​​​​​返​​​​​​​回​​​​​​​正​​​​​​​常​​​​​​​操​​​​​​​作​​​​​​​为​​​​​​​止​​​​​​​。​​​​​​​
备​​​​​​​用​​​​​​​路​​​​​​​由​​​​​​​器​​​​​​​是​​​​​​​一​​​​​​​个​​​​​​​替​​​​​​​补​​​​​​​系​​​​​​​统​​​​​​​。​​​​​​​LVS 路​​​​​​​由​​​​​​​器​​​​​​​周​​​​​​​期​​​​​​​性​​​​​​​地​​​​​​​通​​​​​​​过​​​​​​​主​​​​​​​要​​​​​​​外​​​​​​​部​​​​​​​公​​​​​​​共​​​​​​​接​​​​​​​口​​​​​​​交​​​​​​​换​​​​​​​ heartbeat 信​​​​​​​息​​​​​​​,在​​​​​​​失​​​​​​​效​​​​​​​切​​​​​​​换​​​​​​​的​​​​​​​状​​​​​​​态​​​​​​​下​​​​​​​,通​​​​​​​过​​​​​​​专​​​​​​​用​​​​​​​接​​​​​​​口​​​​​​​交​​​​​​​换​​​​​​​。​​​​​​​备​​​​​​​用​​​​​​​节​​​​​​​点​​​​​​​应​​​​​​​该​​​​​​​无​​​​​​​法​​​​​​​在​​​​​​​预​​​​​​​期​​​​​​​间​​​​​​​隔​​​​​​​之​​​​​​​间​​​​​​​接​​​​​​​收​​​​​​​ heartbeat 信​​​​​​​息​​​​​​​,它​​​​​​​会​​​​​​​启​​​​​​​动​​​​​​​一​​​​​​​个​​​​​​​失​​​​​​​效​​​​​​​切​​​​​​​换​​​​​​​,并​​​​​​​假​​​​​​​装​​​​​​​执​​​​​​​行​​​​​​​活​​​​​​​跃​​​​​​​路​​​​​​​由​​​​​​​器​​​​​​​的​​​​​​​任​​​​​​​务​​​​​​​。​​​​​​​在​​​​​​​失​​​​​​​效​​​​​​​切​​​​​​​换​​​​​​​中​​​​​​​,备​​​​​​​用​​​​​​​路​​​​​​​由​​​​​​​器​​​​​​​接​​​​​​​替​​​​​​​了​​​​​​​由​​​​​​​出​​​​​​​错​​​​​​​的​​​​​​​路​​​​​​​由​​​​​​​器​​​​​​​提​​​​​​​供​​​​​​​的​​​​​​​ VIP 地​​​​​​​址​​​​​​​,所​​​​​​​用​​​​​​​技​​​​​​​术​​​​​​​就​​​​​​​是​​​​​​​我​​​​​​​们​​​​​​​知​​​​​​​道​​​​​​​的​​​​​​​ ARP 嗅​​​​​​​探​​​​​​​ — 在​​​​​​​这​​​​​​​里​​​​​​​备​​​​​​​用​​​​​​​ LVS 路​​​​​​​由​​​​​​​器​​​​​​​宣​​​​​​​布​​​​​​​它​​​​​​​自​​​​​​​己​​​​​​​成​​​​​​​为​​​​​​​发​​​​​​​往​​​​​​​出​​​​​​​错​​​​​​​节​​​​​​​点​​​​​​​的​​​​​​​ IP 数​​​​​​​据​​​​​​​包​​​​​​​的​​​​​​​目​​​​​​​的​​​​​​​地​​​​​​​。​​​​​​​当​​​​​​​出​​​​​​​错​​​​​​​节​​​​​​​点​​​​​​​又​​​​​​​可​​​​​​​以​​​​​​​提​​​​​​​供​​​​​​​服​​​​​​​务​​​​​​​时​​​​​​​,备​​​​​​​用​​​​​​​节​​​​​​​点​​​​​​​由​​​​​​​将​​​​​​​自​​​​​​​己​​​​​​​设​​​​​​​为​​​​​​​随​​​​​​​时​​​​​​​可​​​​​​​替​​​​​​​换​​​​​​​的​​​​​​​角​​​​​​​色​​​​​​​。​​​​​​​
The simple, two-layered configuration used in 图 1.1 “A Basic LVS Configuration” is best for serving data which does not change very frequently — such as static webpages — because the individual real servers do not automatically sync data between each node.

1.1.1. 在​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​之​​​​​​​间​​​​​​​的​​​​​​​数​​​​​​​据​​​​​​​重​​​​​​​复​​​​​​​和​​​​​​​数​​​​​​​据​​​​​​​共​​​​​​​享​​​​​​​

因​​​​​​​为​​​​​​​ LVS 中​​​​​​​没​​​​​​​有​​​​​​​可​​​​​​​用​​​​​​​来​​​​​​​在​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​之​​​​​​​间​​​​​​​共​​​​​​​享​​​​​​​相​​​​​​​同​​​​​​​数​​​​​​​据​​​​​​​的​​​​​​​内​​​​​​​置​​​​​​​组​​​​​​​件​​​​​​​,所​​​​​​​以​​​​​​​管​​​​​​​理​​​​​​​员​​​​​​​有​​​​​​​两​​​​​​​个​​​​​​​基​​​​​​​本​​​​​​​选​​​​​​​择​​​​​​​:
  • 在​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​池​​​​​​​之​​​​​​​间​​​​​​​同​​​​​​​步​​​​​​​数​​​​​​​据​​​​​​​
  • 为​​​​​​​共​​​​​​​享​​​​​​​数​​​​​​​据​​​​​​​的​​​​​​​访​​​​​​​问​​​​​​​在​​​​​​​布​​​​​​​局​​​​​​​中​​​​​​​添​​​​​​​加​​​​​​​第​​​​​​​三​​​​​​​层​​​​​​​
对​​​​​​​于​​​​​​​不​​​​​​​允​​​​​​​许​​​​​​​上​​​​​​​传​​​​​​​大​​​​​​​量​​​​​​​用​​​​​​​户​​​​​​​或​​​​​​​者​​​​​​​在​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​中​​​​​​​进​​​​​​​行​​​​​​​数​​​​​​​据​​​​​​​修​​​​​​​改​​​​​​​的​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​来​​​​​​​说​​​​​​​,第​​​​​​​一​​​​​​​个​​​​​​​选​​​​​​​择​​​​​​​是​​​​​​​首​​​​​​​选​​​​​​​的​​​​​​​。​​​​​​​如​​​​​​​果​​​​​​​配​​​​​​​置​​​​​​​允​​​​​​​许​​​​​​​大​​​​​​​量​​​​​​​用​​​​​​​户​​​​​​​修​​​​​​​改​​​​​​​数​​​​​​​据​​​​​​​,比​​​​​​​如​​​​​​​电​​​​​​​子​​​​​​​商​​​​​​​务​​​​​​​网​​​​​​​站​​​​​​​,最​​​​​​​好​​​​​​​添​​​​​​​加​​​​​​​第​​​​​​​三​​​​​​​层​​​​​​​。​​​​​​​

1.1.1.1. 配​​​​​​​置​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​来​​​​​​​同​​​​​​​步​​​​​​​数​​​​​​​据​​​​​​​

管​​​​​​​理​​​​​​​员​​​​​​​可​​​​​​​用​​​​​​​来​​​​​​​同​​​​​​​步​​​​​​​真​​​​​​​实​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​池​​​​​​​数​​​​​​​据​​​​​​​的​​​​​​​方​​​​​​​法​​​​​​​有​​​​​​​很​​​​​​​多​​​​​​​。​​​​​​​例​​​​​​​如​​​​​​​:可​​​​​​​采​​​​​​​用​​​​​​​ shell 脚​​​​​​​本​​​​​​​,那​​​​​​​么​​​​​​​如​​​​​​​果​​​​​​​网​​​​​​​页​​​​​​​工​​​​​​​程​​​​​​​师​​​​​​​更​​​​​​​新​​​​​​​了​​​​​​​页​​​​​​​面​​​​​​​,就​​​​​​​可​​​​​​​同​​​​​​​时​​​​​​​将​​​​​​​该​​​​​​​页​​​​​​​面​​​​​​​发​​​​​​​送​​​​​​​到​​​​​​​所​​​​​​​有​​​​​​​服​​​​​​​务​​​​​​​器​​​​​​​中​​​​​​​。​​​​​​​还​​​​​​​有​​​​​​​,系​​​​​​​统​​​​​​​管​​​​​​​理​​​​​​​员​​​​​​​可​​​​​​​以​​​​​​​使​​​​​​​用​​​​​​​类​​​​​​​似​​​​​​​ rsync 的​​​​​​​程​​​​​​​序​​​​​​​来​​​​​​​在​​​​​​​设​​​​​​​定​​​​​​​的​​​​​​​间​​​​​​​隔​​​​​​​期​​​​​​​间​​​​​​​重​​​​​​​复​​​​​​​所​​​​​​​有​​​​​​​节​​​​​​​点​​​​​​​中​​​​​​​修​​​​​​​改​​​​​​​的​​​​​​​数​​​​​​​据​​​​​​​。​​​​​​​
但​​​​​​​是​​​​​​​,如​​​​​​​果​​​​​​​由​​​​​​​于​​​​​​​用​​​​​​​户​​​​​​​经​​​​​​​常​​​​​​​上​​​​​​​传​​​​​​​文​​​​​​​件​​​​​​​或​​​​​​​者​​​​​​​进​​​​​​​行​​​​​​​数​​​​​​​据​​​​​​​库​​​​​​​传​​​​​​​送​​​​​​​造​​​​​​​成​​​​​​​配​​​​​​​置​​​​​​​超​​​​​​​载​​​​​​​,这​​​​​​​种​​​​​​​数​​​​​​​据​​​​​​​同​​​​​​​步​​​​​​​就​​​​​​​不​​​​​​​是​​​​​​​最​​​​​​​佳​​​​​​​的​​​​​​​同​​​​​​​步​​​​​​​方​​​​​​​法​​​​​​​。​​​​​​​对​​​​​​​于​​​​​​​有​​​​​​​高​​​​​​​负​​​​​​​载​​​​​​​的​​​​​​​配​​​​​​​置​​​​​​​,三​​​​​​​层​​​​​​​布​​​​​​​局​​​​​​​是​​​​​​​最​​​​​​​佳​​​​​​​解​​​​​​​决​​​​​​​方​​​​​​​案​​​​​​​。​​​​​​​
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.