Linux Advanced tips: Heartbeat+lvs

Source: Internet
Author: User

Linux Advanced tips: Heartbeat+lvs

The Heartbeat project is an integral part of the LINUX-HA project, which implements a highly available cluster system. Heartbeat service and cluster communication are two key components of a highly available cluster, and in the Heartbeat project, these two functions are implemented by the Heartbeat module ...

AD:2014WOT Global Software Technology Summit Beijing Station course video release

November 21-22nd with WOT technology Conference Shenzhen now Rob Tickets

1.heartbeat Introduction:

The Heartbeat project is an integral part of the LINUX-HA project, which implements a highly available cluster system. Heartbeat service and cluster communication are two key components of a highly available cluster, and in the Heartbeat project, these two functions are implemented by the Heartbeat module.

This cluster solution is built using third-party software, which is simpler to function than Redhat's own cluster software, but it is very convenient to build up. And it's a quick solution.

Heartbeat's high-availability cluster uses UDP protocol and serial communication, and heartbeat plug-in technology realizes serial, multicast, broadcast and multicast communication between clusters. It realizes the core function of HA function-heartbeat, installs the heartbeat software on two servers simultaneously, monitors the state of the system, coordinates the work of the master-slave server, and maintains the system availability. It can detect the server application-level system software, hardware failures, timely fault isolation, recovery, through the system monitoring, service monitoring, IP automatic migration and other technologies to achieve no single point of failure in the entire application, simple and cost-effective to ensure the continued high availability of important services. Heartbeat uses virtual IP address mapping technology to realize the function of the client-server switching to transparent to clients.

But a single heartbeat is not able to provide robust services, so we use LVS in the background to load balance.

2.LVS Introduction

LVS is a shorthand for Linux virtual Server, that is, a virtualized server cluster system. Founded by Dr. Zhangwensong.

IPVS

Speaking of LVS, we have to mention that Ipvs,ipvs is the core software of the LVS cluster system, which is installed on the Load Balancer and forwards the request destined for Virtual IP to the Real Server. There are three load-balancing mechanisms in IPVS, where the IP tunneling mechanism is used:

    • ? Virtual Server via NAT
    • ? Virtual Server via IP tunneling
    • ? Virtual Server via Direct Routing

Our experiment is based on the last direct-link approach.

LVS scheduling algorithm is very important, we must be familiar with them. There is a detailed explanation on the official website: http://zh.linuxvirtualserver.org/

There are 10 types of load scheduling algorithms in IPVS:

    • Call (Round Robin)
    • Weighted round call (Weighted Round Robin)
    • Minimum link (Least Connections)
    • Weighted least link (Weighted Least Connections)
    • Minimal links based on locality (locality-based Least Connections)
    • Local least-link with replication (locality-based Least Connections with Replication)
    • Destination Address hash (Destination Hashing)
    • Source Address hash (source Hashing)
    • Shortest expected delay (shortest expected delay)
    • No queue wait (never queue)

Note : We use a simpler round-call approach.

3.ldirectord Introduction:

Ldirectord is a kind of health detection mechanism with LVS, or the function that the load balancer still does not detect after the node is hung off.

The basic concepts of heardbeat, LVS and Ldirectord are described above. Say more than build a service to show you the effect.

4. Build Rhel6.5+lvs+linux-ha+ldirectord Service (HTTP and FTP service as an example)

Attention:

1. System: redhat6.5;

2. Node: A total of four virtual machines are used as nodes, of which two are installed heartbeat and LVS, the other two nodes only provide Apache and VSFTPD services;

3. The resolution between the four nodes must be done well;

4. Firewall off, time synchronization, four-machine version of the system is the best.

Experimental environment shows that the first console is my real machine, the other four for the experiment of four nodes, the first two installed heartbeat and LVS, the latter two consoles to provide Apache and VSFTPD services. Next we'll configure it in chunks.

1. Install Heartbeat:

This is a third-party software, not redhat comes with, so we have to download:, respectively, need:

    1. heartbeat-3.0.4-2.el6.x86_64.rpm
    2. heartbeat-devel-3.0.4-2.el6.x86_64.rpm
    3. heartbeat-libs-3.0.4-2.el6.x86_64.rpm

I have on the local VSFTPD service, can also be found on the http://rpm.pbone.net/.

This three package should be available on all two nodes. Then install them in a custom location:


If the installation is not successful then be sure to reset your yum Source:

    1. Vim/etc/yum.repos.d/yum.repo

This is the three configuration file for heartbeat:

    1. HA.CF Main configuration file
    2. Haresources Resource configuration file
    3. Authkeys Authentication Information

By default the configuration file does not, we have to copy from other places:

Vim HA.CF:

KeepAlive 2

Set the time interval between heartbeat to 2 seconds.

Warntime 10

The time, in seconds, to wait before issuing a "late heartbeat" warning in the log.

Deadtime 30

The node is declared dead after 30 seconds.

Initdead 120

In some configurations, the network takes some time to function properly after a reboot. This individual "deadtime" option can handle this situation. Its value should be at least twice times that of the usual deadtime.

Udpport 694

Use port 694 for bcast and ucast communication. This is the default and is officially registered in the IANA port number.


Default Auto-failback after reply:

There are two nodes installed heartbeat:

The network that is used to test the node is interconnected:

The above is the modification of the HA.CF configuration file, and then we want to authkeys the file:

To modify access permissions for a file:

Finally, we will modify the haresources, we want to add an Apache service, but we have to give it a virtual IP (this IP must not be occupied by others), let these two nodes for its search.

On both sides of the HTTPD service is installed as a test, in order to differentiate, we write different content in their index.html (in fact the content of both in the production environment is certainly the same, because we are doing load balancing)

After completing the above content, open the heartbeat service on both sides:

Then we'll pass the Firefox test effect:

We then let the current node heartbeat shut down and found that another node was automatically taken over:

Then let the heartbeat of that node just turn on, because it is the Master node (server101.example.com), so take it back again:

Summary:

This is the effect of load balancing, but this is only a simple heartbeat, we have not combined with LVS, in the function is not perfect, in the next post will gradually combine the two, the next post will first let us feel the effect of the LVS alone when used, Finally, we will combine the two together.

The previous post introduced the use of heartbeat alone, and today we first introduce the individual use of LVS, and finally combine the two together. To provide a comprehensive service.

Three load balancing technologies for 1.LVS:

Fortunately, the kernel 2.6x has built in the LVs module, and in the REDHAT6 version there is the LVS installation package Ipvsadm.

Below we compare three load balancing technologies for LVS:

1. Implementing a virtual server via NAT (Vs/nat):

Due to the increasing tension and security of IP address space in IPV4, many networks use reserved IP addresses. These addresses are not used on the Internet, but are reserved exclusively for the internal network. When hosts in the internal network are accessing the Internet or are being accessed by the Internet, they need to use network address translation (translation, referred to as NAT) to convert the internal address to an external address available on Internets. When the external network accesses the service, it actually accesses the IP that can communicate with the outside world, but the content of the access is load balanced on the nodes of the intranet. The principle is as follows:

2. Implementing Virtual Server (Vs/tun) via IP tunneling:

Its connection scheduling and management is the same as in Vs/nat, but its message forwarding method is different. According to the load situation of each server, the scheduler chooses a server dynamically, encapsulates the request message in another IP packet, forwards the encapsulated IP message to the selected server, and the server receives the message, the message is first unpacked to obtain the original target address of the VIP message, The server discovers that the VIP address is configured on the local IP tunneling device, so it processes the request and then returns the response message directly to the client based on the routing table.

Remember that it differs from NAT in that it is possible to establish a link directly with the client. The principle is as follows:

3. Implementing a virtual server via direct routing (VS/DR):

Both the scheduler and the server group must physically have a network card that is connected via a disconnected LAN, such as through a high-speed switch or hub. VIP address for Dispatcher and server group sharing, dispatcher configuration VIP address is externally visible, used to receive virtual service request message; All servers configure VIP addresses on their non-arp network devices, which are not visible to the outside, but only for the purpose of handling network requests with the VIP address.

This model is what we do today, each node has a virtual IP (control node and the Real Service Node (RS)), where the scheduling is done by the controller (RR round called algorithm), the service will not be active to provide services. As with Tun, they can also communicate directly with the client. Principle:

Installation and configuration of 2.LVS:

First, let's open up the familiar console:

Install Ipvsadm:

There are currently no scheduling lists:

To add a virtual IP as a public access IP:

We add the virtual IP to the port of the HTTPD service and use the round-call algorithm (RR):

Allow server106 and server107 httpd services to be called nodes:

Install the HTTPD service separately on serevr106 and server107:

Then we have to do the following things:

1.server106 and server107 to be able to identify 192.168.2.110 this virtual IP, so they also want to add this virtual network card.

2. In order to reflect the effect of the round, we write different content in the default publishing directory of both to show the difference.


Now that the control node and the node that provides the real service are able to identify the VIP (192.168.2.110), then we want to add a policy on the node that provides the service, which is similar to the firewall, but to install an additional software:

There are no policy settings at this time:

Add a policy, discard all the packages that come in directly to access 192.168.2.110, and let the packets from 192.168.2.110 go out of 192.168.2.106 (192.168.2.107 the same).

Save Policy:

Now we repeatedly access the 192.168.2.110 through the browser (make sure the service node's httpd service is on) and refresh several times:

This is the information that we control the node record before the visit:

After 32 visits, we found that two nodes were called 16 times, but the IP access was virtual IP (192.168.2.110), which is the LVS scheme in direct connection.

And the content of the Web page is also changing round-robin:


3. Summary:

This post first introduced the LVS three kinds of load balancing technology, and then we personally built the direct-attached case of LVS, then in the next thread we will combine LVS and heartbeat together to form a robust service.

Original link: http://blog.csdn.net/linux_player_c/article/details/38277173, http://blog.csdn.net/linux_player_c/article/ details/38294319

"Editor's recommendation"

Linux Advanced tips: Heartbeat+lvs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.