Virtual Server Red Hat Enterprise Linux 6 Administration

Transcription

Red Hat Enterprise Linux 6Virtual ServerAdministrationLoad Balancer Add-On for Red Hat Enterprise Linux

Virtual Server AdministrationRed Hat Enterprise Linux 6 Virtual Server AdministrationLoad Balancer Add-On for Red Hat Enterprise LinuxEdition 6Copyright 2010 Red Hat, Inc.The text of and illustrations in this document are licensed by Red Hat under a Creative CommonsAttribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is availableat http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute thisdocument or an adaptation of it, you must provide the URL for the original version.Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert,Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora, the InfinityLogo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.Linux is the registered trademark of Linus Torvalds in the United States and other countries.Java is a registered trademark of Oracle and/or its affiliates.XFS is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United Statesand/or other countries.MySQL is a registered trademark of MySQL AB in the United States, the European Union and othercountries.All other trademarks are the property of their respective owners.1801 Varsity DriveRaleigh, NC 27606-2072 USAPhone: 1 919 754 3700Phone: 888 733 4281Fax: 1 919 754 3701Building a Load Balancer Add-On system offers a highly available and scalable solution for productionservices using specialized Linux Virtual Servers (LVS) for routing and load-balancing techniquesconfigured through the PIRANHA configuration tool. This book discusses the configuration of highperformance systems and services with Red Hat Enterprise Linux and the Load Balancer Add-On forRed Hat Enterprise Linux 6.

Introductionv1. Document Conventions . v1.1. Typographic Conventions . vi1.2. Pull-quote Conventions . vii1.3. Notes and Warnings . viii2. Feedback . viii1. Load Balancer Add-On Overview11.1. A Basic Load Balancer Add-On Configuration . 11.1.1. Data Replication and Data Sharing Between Real Servers . 31.2. A Three-Tier Load Balancer Add-On Configuration . 31.3. Load Balancer Add-On Scheduling Overview . 41.3.1. Scheduling Algorithms . 51.3.2. Server Weight and Scheduling . 61.4. Routing Methods . 61.4.1. NAT Routing . 71.4.2. Direct Routing . 71.5. Persistence and Firewall Marks . 91.5.1. Persistence . 91.5.2. Firewall Marks . 91.6. Load Balancer Add-On — A Block Diagram . 101.6.1. Load Balancer Add-On Components . 112. Initial Load Balancer Add-On Configuration2.1. Configuring Services on the LVS Routers .2.2. Setting a Password for the Piranha Configuration Tool .2.3. Starting the Piranha Configuration Tool Service .2.3.1. Configuring the Piranha Configuration Tool Web Server Port .2.4. Limiting Access To the Piranha Configuration Tool .2.5. Turning on Packet Forwarding .2.6. Configuring Services on the Real Servers .13131414151516163. Setting Up Load Balancer Add-On3.1. The NAT Load Balancer Add-On Network .3.1.1. Configuring Network Interfaces for Load Balancer Add-On with NAT .3.1.2. Routing on the Real Servers .3.1.3. Enabling NAT Routing on the LVS Routers .3.2. Load Balancer Add-On via Direct Routing .3.2.1. Direct Routing and arptables jf .3.2.2. Direct Routing and iptables .3.3. Putting the Configuration Together .3.3.1. General Load Balancer Add-On Networking Tips .3.4. Multi-port Services and Load Balancer Add-On .3.4.1. Assigning Firewall Marks .3.5. Configuring FTP .3.5.1. How FTP Works .3.5.2. How This Affects Load Balancer Add-On Routing .3.5.3. Creating Network Packet Filter Rules .3.6. Saving Network Packet Filter Settings .17171718191920212222232324242525274. Configuring the Load Balancer Add-On with Piranha Configuration Tool4.1. Necessary Software .4.2. Logging Into the Piranha Configuration Tool .4.3. CONTROL/MONITORING .4.4. GLOBAL SETTINGS .4.5. REDUNDANCY .292929303133iii

Virtual Server Administration4.6. VIRTUAL SERVERS .4.6.1. The VIRTUAL SERVER Subsection .4.6.2. REAL SERVER Subsection .4.6.3. EDIT MONITORING SCRIPTS Subsection .4.7. Synchronizing Configuration Files .4.7.1. Synchronizing lvs.cf .4.7.2. Synchronizing sysctl .4.7.3. Synchronizing Network Packet Filtering Rules .4.8. Starting the Load Balancer Add-On .353638414343444444A. Using the Load Balancer Add-On with the High Availability Add-On47B. Revision History49Index51iv

IntroductionThis document provides information about installing, configuring, and managing the Load BalancerAdd-On components. The Load Balancer Add-On provides load balancing through specialized routingtechniques that dispatch traffic to a pool of servers.The audience of this document should have advanced working knowledge of Red Hat Enterprise Linuxand understand the concepts of clusters, storage, and server computing.This document is organized as follows: Chapter 1, Load Balancer Add-On Overview Chapter 2, Initial Load Balancer Add-On Configuration Chapter 3, Setting Up Load Balancer Add-On Chapter 4, Configuring the Load Balancer Add-On with Piranha Configuration Tool Appendix A, Using the Load Balancer Add-On with the High Availability Add-OnFor more information about Red Hat Enterprise Linux 6, refer to the following resources: Red Hat Enterprise Linux Installation Guide — Provides information regarding installation of RedHat Enterprise Linux 6. Red Hat Enterprise Linux Deployment Guide — Provides information regarding the deployment,configuration and administration of Red Hat Enterprise Linux 6.For more information about the Load Balancer Add-On and related products for Red Hat EnterpriseLinux 6, refer to the following resources: Red Hat Cluster Suite Overview — Provides a high-level overview of the High Availability Add-On,Resilient Storage Add-On, and the Load Balancer Add-On. Configuring and Managing the High Availability Add-On Provides information about configuring andmanaging the High Availability Add-On (also known as Red Hat Cluster) for Red Hat EnterpriseLinux 6. Logical Volume Manager Administration — Provides a description of the Logical Volume Manager(LVM), including information on running LVM in a clustered environment. Global File System 2: Configuration and Administration — Provides information about installing,configuring, and maintaining the Red Hat Resilient Storage Add-On (also known as Red Hat GlobalFile System 2). DM Multipath — Provides information about using the Device-Mapper Multipath feature of Red HatEnterprise Linux 6. Release Notes — Provides information about the current release of Red Hat products.This document and other Red Hat documents are available in HTML, PDF, and RPM versions on theRed Hat Enterprise Linux Documentation CD and online at http://www.redhat.com/docs/.1. Document ConventionsThis manual uses several conventions to highlight certain words and phrases and draw attention tospecific pieces of information.v

Introduction1In PDF and paper editions, this manual uses typefaces drawn from the Liberation Fonts set. TheLiberation Fonts set is also used in HTML editions if the set is installed on your system. If not,alternative but equivalent typefaces are displayed. Note: Red Hat Enterprise Linux 5 and later includesthe Liberation Fonts set by default.1.1. Typographic ConventionsFour typographic conventions are used to call attention to specific words and phrases. Theseconventions, and the circumstances they apply to, are as follows.Mono-spaced BoldUsed to highlight system input, including shell commands, file names and paths. Also used to highlightkeycaps and key combinations. For example:To see the contents of the file my next bestselling novel in your currentworking directory, enter the cat my next bestselling novel command at theshell prompt and press Enter to execute the command.The above includes a file name, a shell command and a keycap, all presented in mono-spaced boldand all distinguishable thanks to context.Key combinations can be distinguished from keycaps by the hyphen connecting each part of a keycombination. For example:Press Enter to execute the command.Press Ctrl Alt F2 to switch to the first virtual terminal. Press Ctrl Alt F1 toreturn to your X-Windows session.The first paragraph highlights the particular keycap to press. The second highlights two keycombinations (each a set of three keycaps with each set pressed simultaneously).If source code is discussed, class names, methods, functions, variable names and returned valuesmentioned within a paragraph will be presented as above, in mono-spaced bold. For example:File-related classes include filesystem for file systems, file for files, and dir fordirectories. Each class has its own associated set of permissions.Proportional BoldThis denotes words or phrases encountered on a system, including application names; dialog box text;labeled buttons; check-box and radio button labels; menu titles and sub-menu titles. For example:Choose System Preferences Mouse from the main menu bar to launch MousePreferences. In the Buttons tab, click the Left-handed mouse check box and clickClose to switch the primary mouse button from the left to the right (making the mousesuitable for use in the left hand).To insert a special character into a gedit file, choose Applications Accessories Character Map from the main menu bar. Next, choose Search Find from theCharacter Map menu bar, type the name of the character in the Search field and clickNext. The character you sought will be highlighted in the Character Table. vi

Pull-quote Conventionsclick this highlighted character to place it in the Text to copy field and then click theCopy button. Now switch back to your document and choose Edit Paste from thegedit menu bar.The above text includes application names; system-wide menu names and items; application-specificmenu names; and buttons and text found within a GUI interface, all presented in proportional bold andall distinguishable by context.Mono-spaced Bold Italic or Proportional Bold ItalicWhether mono-spaced bold or proportional bold, the addition of italics indicates replaceable orvariable text. Italics denotes text you do not input literally or displayed text that changes depending oncircumstance. For example:To connect to a remote machine using ssh, type ssh username@domain.name ata shell prompt. If the remote machine is example.com and your username on thatmachine is john, type ssh john@example.com.The mount -o remount file-system command remounts the named filesystem. For example, to remount the /home file system, the command is mount -oremount /home.To see the version of a currently installed package, use the rpm -q packagecommand. It will return a result as follows: package-version-release.Note the words in bold italics above — username, domain.name, file-system, package, version andrelease. Each word is a placeholder, either for text you enter when issuing a command or for textdisplayed by the system.Aside from standard usage for presenting the title of a work, italics denotes the first use of a new andimportant term. For example:Publican is a DocBook publishing system.1.2. Pull-quote ConventionsTerminal output and source code listings are set off visually from the surrounding text.Output sent to a terminal is set in mono-spaced roman and presented thus:booksbooks agesmssnotesphotosscriptsstuffsvgssvnSource-code listings are also set in mono-spaced roman but add syntax highlighting as follows:package org.jboss.book.jca.ex1;import javax.naming.InitialContext;public class ExClient{public static void main(String args[])throws Exception{InitialContext iniCtx new InitialContext();Objectref iniCtx.lookup("EchoBean");EchoHomehome (EchoHome) ref;Echoecho home.create();vii

IntroductionSystem.out.println("Created Echo");System.out.println("Echo.echo('Hello') " echo.echo("Hello"));}}1.3. Notes and WarningsFinally, we use three visual styles to draw attention to information that might otherwise be overlooked.NoteNotes are tips, shortcuts or alternative approaches to the task at hand. Ignoring a note shouldhave no negative consequences, but you might miss out on a trick that makes your life easier.ImportantImportant boxes detail things that are easily missed: configuration changes that only apply tothe current session, or services that need restarting before an update will apply. Ignoring a boxlabeled 'Important' will not cause data loss but may cause irritation and frustration.WarningWarnings should not be ignored. Ignoring warnings will most likely cause data loss.2. FeedbackIf you spot a typo, or if you have thought of a way to make this manual better, we would love tohear from you. Please submit a report in Bugzilla (http://bugzilla.redhat.com/bugzilla/) against thecomponent Documentation-cluster.Be sure to mention the manual's identifier:Virtual Server Administration(EN)-6 (2010-10-14T16:28)By mentioning this manual's identifier, we know exactly which version of the guide you have.If you have a suggestion for improving the documentation, try to be as specific as possible. If you havefound an error, please include the section number and some of the surrounding text so we can find iteasily.viii

Chapter 1.Load Balancer Add-On OverviewThe Load Balancer Add-On is a set of integrated software components that provide Linux VirtualServers (LVS) for balancing the IP load across a set of real servers. The Load Balancer Add-On runson a pair of equally configured computers: one that is an active LVS router and one that is a backupLVS router. The active LVS router serves two roles: To balance the load across the real servers. To check the integrity of the services on each real server.The backup LVS router monitors the active LVS router and takes over from it in case the active LVSrouter fails.This chapter provides an overview of The Load Balancer Add-On components and functions, andconsists of the following sections: Section 1.1, “A Basic Load Balancer Add-On Configuration” Section 1.2, “A Three-Tier Load Balancer Add-On Configuration” Section 1.3, “Load Balancer Add-On Scheduling Overview” Section 1.4, “Routing Methods” Section 1.5, “Persistence and Firewall Marks” Section 1.6, “Load Balancer Add-On — A Block Diagram”1.1. A Basic Load Balancer Add-On ConfigurationFigure 1.1, “A Basic Load Balancer Add-On Configuration” shows a simple Load Balancer Add-Onconfiguration consisting of two layers. On the first layer are two LVS routers — one active and onebackup. Each of the LVS routers has two network interfaces, one interface on the Internet and oneon the private network, enabling them to regulate traffic between the two networks. For this examplethe active router is using Network Address Translation or NAT to direct traffic from the Internet to avariable 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 andpass all public traffic back and forth through the active LVS router. To the outside world, the serversappears as one entity.1

Chapter 1. Load Balancer Add-On OverviewFigure 1.1. A Basic Load Balancer Add-On ConfigurationService requests arriving at the LVS routers are addressed to a virtual IP address, or VIP. This is apublicly-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 serviceconfigured to listen on a specific virtual IP. Refer to Section 4.6, “VIRTUAL SERVERS” for moreinformation on configuring a virtual server using the Piranha Configuration Tool. A VIP addressmigrates from one LVS router to the other during a failover, thus maintaining a presence at that IPaddress (also known as floating IP addresses).VIP addresses may be aliased to the same device which connects the LVS router to the Internet. Forinstance, if eth0 is connected to the Internet, than multiple virtual servers can be aliased to eth0:1.Alternatively, each virtual server can be associated with a separate device per service. For example,HTTP traffic can be handled on eth0:1, and FTP traffic can be handled on eth0:2.Only one LVS router is active at a time. The role of the active router is to redirect service requestsfrom virtual IP addresses to the real servers. The redirection is based on one of eight supported loadbalancing algorithms described further in Section 1.3, “Load Balancer Add-On Scheduling Overview”.The active router also dynamically monitors the overall health of the specific services on the realservers through simple send/expect scripts. To aid in detecting the health of services that requiredynamic data, such as HTTPS or SSL, the administrator can also call external executables. If aservice on a real server malfunctions, the active router stops sending jobs to that server until it returnsto normal operation.The backup router performs the role of a standby system. Periodically, the LVS routers exchangeheartbeat messages through the primary external public interface and, in a failover situation, theprivate interface. Should the backup node fail to receive a heartbeat message within an expectedinterval, it initiates a failover and assumes the role of the active router. During failover, the backuprouter takes over the VIP addresses serviced by the failed router using a technique known as ARPspoofing — where the backup LVS router announces itself as the destination for IP packets addressed2

Data Replication and Data Sharing Between Real Serversto the failed node. When the failed node returns to active service, the backup node assumes its hotbackup role again.The simple, two-layered configuration used in Figure 1.1, “A Basic Load Balancer Add-OnConfiguration” is best for serving data which does not change very frequently — such as staticwebpages — because the individual real servers do not automatically sync data between each node.1.1.1. Data Replication and Data Sharing Between Real ServersSince there is no built-in component in Load Balancer Add-On to share the same data between thereal servers, the administrator has two basic options: Synchronize the data across the real server pool Add a third layer to the topology for shared data accessThe first option is preferred for servers that do not allow large numbers of users to upload or changedata on the real servers. If the configuration allows large numbers of users to modify data, such as ane-commerce website, adding a third layer is preferable.1.1.1.1. Configuring Real Servers to Synchronize DataThere are many ways an administrator can choose to synchronize data across the pool of real servers.For instance, shell scripts can be employed so that if a Web engineer updates a page, the page isposted to all of the servers simultaneously. Also, the system administrator can use programs such asrsync to replicate changed data across all nodes at a set interval.However, this type of data synchronization does not optimally function if the configuration isoverloaded with users constantly uploading files or issuing database transactions. For a configurationwith a high load, a three-tier topology is the ideal solution.1.2. A Three-Tier Load Balancer Add-On ConfigurationFigure 1.2, “A Three-Tier Load Balancer Add-On Configuration” shows a typical three-tier LoadBalancer Add-On topology. In this example, the active LVS router routes the requests from the Internetto the pool of real servers. Each of the real servers then accesses a shared data source over thenetwork.3

Chapter 1. Load Balancer Add-On OverviewFigure 1.2. A Three-Tier Load Balancer Add-On ConfigurationThis configuration is ideal for busy FTP servers, where accessible data is stored on a central, highlyavailable server and accessed by each real server via an exported NFS directory or Samba share.This topology is also recommended for websites that access a central, highly available databasefor transactions. Additionally, using an active-active configuration with Red Hat Cluster Manager,administrators can configure one high-availability cluster to serve both of these roles simultaneously.The third tier in the above example does not have to use Red Hat Cluster Manager, but failing to use ahighly available solution would introduce a critical single point of failure.1.3. Load Balancer Add-On Scheduling OverviewOne of the advantages of using Load Balancer Add-On is its ability to perform flexible, IP-level loadbalancing on the real server pool. This flexibility is due to the variety of scheduling algorithms anadministrator can choose from when configuring Load Balancer Add-On. Load Balancer Add-Onload balancing is superior to less flexible methods, such as Round-Robin DNS where the hierarchicalnature of DNS and the caching by client machines can lead to load imbalances. Additionally, the lowlevel filtering employed by the LVS router has advantages over application-level request forwardingbecause balancing loads at the network packet level causes minimal computational overhead andallows for greater scalability.4

Scheduling AlgorithmsUsing scheduling, the active router can take into account the real servers' activity and, optionally, anadministrator-assigned weight factor when routing service requests. Using assigned weights givesarbitrary priorities to individual machines. Using this form of scheduling, it is possible to create a groupof real servers using a variety of hardware and software combinations and the active router can evenlyload each real server.The scheduling mechanism for Load Balancer Add-On is provided by a collection of kernel patchescalled IP Virtual Server or IPVS modules. These modules enable layer 4 (L4) transport layer switching,which is designed to work well with multiple servers on a single IP address.To track and route packets to the real servers efficiently, IPVS builds an IPVS table in the kernel.This table is used by the active LVS router to redirect requests from a virtual server address to andreturning from real servers in the pool. The IPVS table is constantly updated by a utility called ipvsadm— adding and removing cluster members depending on their availability.1.3.1. Scheduling AlgorithmsThe structure that the IPVS table takes depends on the scheduling algorithm that the administratorchooses for any given virtual server. To allow for maximum flexibility in the types of services youcan cluster and how these services are scheduled, Red Hat Enterprise Linux provides the followingscheduling algorithms listed below. For instructions on how to assign scheduling algorithms refer toSection 4.6.1, “The VIRTUAL SERVER Subsection”.Round-Robin SchedulingDistributes each request sequentially around the pool of real servers. Using this algorithm, allthe real servers are treated as equals without regard to capacity or load. This scheduling modelresembles round-robin DNS but is more granular due to the fact that it is network-connectionbased and not host-based. Load Balancer Add-On round-robin scheduling also does not suffer theimbalances caused by cached DNS queries.Weighted Round-Robin SchedulingDistributes each request sequentially around the pool of real servers but gives more jobs toservers with greater capacity. Capacity is indicated by a user-assigned weight factor, which is thenadjusted upward or downward by dynamic load information. Refer to Section 1.3.2, “Server Weightand Scheduling” for more on weighting real servers.Weighted round-robin scheduling is a preferred choice if there are significant differences in thecapacity of real servers in the pool. However, if the request load varies dramatically, the moreheavily weighted server may answer more than its share of requests.Least-ConnectionDistributes more requests to real servers with fewer active connections. Because it keeps track oflive connections to the real servers through the IPVS table, least-connection is a type of dynamicscheduling algorithm, making it a better choice if there is a high degree of variation in the requestload. It is best suited for a real server pool where each member node has roughly the samecapacity. If a group of servers have different capabilities, weighted least-connection scheduling isa better choice.Weighted Least-Connections (default)Distributes more requests to servers with fewer active connections relative to their capacities.Capacity is indicated by a user-assigned weight, which is then adjusted upward or downwardby dynamic load information. The addition of weighting makes this algorithm ideal when the realserver pool contains hardware of varying capacity. Refer to Section 1.3.2, “Server Weight andScheduling” for more on weighting real servers.5

Chapter 1. Load Balancer Add-On OverviewLocality-Based Least-Connection SchedulingDistributes more requests to servers with fewer active connections relative to their destination IPs.This algorithm is designed for use in a proxy-cache server cluster. It routes the packets for an IPaddress to the server for that address unless that server is above its capacity and has a server inits half load, in which case it assigns the IP address to the least loaded real server.Locality-Based Least-Connection Scheduling with Replication SchedulingDistributes more requests to servers with fewer active connections relative to their destinationIPs. This algorithm is also designed for use in a proxy-cache server cluster. It differs from LocalityBased Least-Connection Scheduling by mapping th

To connect to a remote machine using ssh, type ssh username@domain.name at a shell prompt. If the remote machine is example.com and your username on that machine is john, type ssh john@example.com. The mount -o remount file-system command remounts the named file system. For example, to remount the /home file system, the command is mount -o .