Linux Advanced tips: Heartbeat+lvs (i)

Source: Internet
Author: User



1.heartbeat A Brief introduction:

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

This cluster solution is built using third-party software, which is more functionally simplified than Redhat's own cluster software. But it is very convenient to build up. And it's a high-speed solution.

Heartbeat's high-availability cluster uses communication methods such as UDP protocol and serial communication. And the heartbeat plug-in technology realizes the serial port, multicast, broadcast and multicast communication between the clusters.

It implements the core function of the HA function-heartbeat, the heartbeat software is installed on both servers at the same time to monitor the status of the system, coordinate the work of the master-slave server. Maintain the availability of the system.   It can detect the server application-level system software, hardware failures, timely fault isolation, recovery, through the system monitoring, service monitoring, IP self-migration, and other technology is not a single point of failure in the entire application today, simple and cost-effective to ensure the continued high availability of important services. Heartbeat adopts the virtual IP address mapping technology to realize the function of client-server switching.

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


2.LVS Brief Introduction

LVS is a shorthand for Linux Virtual Server . Linux Virtual Serveris a virtual 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 took the last form of direct connection.
LVS scheduling algorithm is very important, we must be familiar with them. There are specific explanations on the official site: 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)

Gaze: We use a simpler round-call approach.

3.LdirectordBrief Introduction:

Ldirectord is a kind of health detection mechanism with LVS. The load balancer does not have the ability to detect after the node has been hung out.



The above describesheardbeat, LVS and LdirectordThe basic concept.

Say more than build a service to show you the effect.

4. Build Rhel6.5+lvs+linux-ha+ldirectord Service (HTTP and FTP services available as examples)

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. An additional two nodes provide only Apache and VSFTPD services;
3. The resolution between the four nodes must be done well.
4. Firewall off, time synchronization, the system version number of four is the best.

In the experimental environment. The first console is my real machine. The other four were four nodes for the experiment, the first two installed heartbeat and LVs, and the latter two consoles providing Apache and vsftpd services. Next we'll configure it in chunks.




1. Install Heartbeat:

This is a third-party software. Not Redhat, so we have to download:. Each of these needs:

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

My local VSFTPD service is available and can be found on the http://rpm.pbone.net/.

This three package should be available on all two nodes. Then install them in their own defined location:



If the installation is not successful then be sure to set up your Yum source again:
Vim/etc/yum.repos.d/yum.repo


This is the three configuration file for heartbeat:

, ha.cf Main configuration file
Haresources Resource configuration file
Authkeys Authentication Information

By default the configuration file does not, we have to copy from somewhere else:



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 needs some time to work properly after restarting. This individual "deadtime" option is able to handle this situation.

Its value should be at least twice times that of the usual deadtime.


Udpport 694
Use port694 for bcast and Ucast communication. This is the default. and the port number in the official IANA register.







By default, after replying, you are actively cutting back:



There are two nodes installed heartbeat:



The network used to test the node is interconnected:





The above is a change to the HA.CF configuration file. And then we're going to Authkeys file:



Permission to change files:



Finally we have to change 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.



Installing the HTTPD service on both sides 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 of course the same, because we do but load balance)

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 the other node itself took over the initiative:





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





Summary:

This has the effect of load balancing, but this is simply a heartbeat. We have not yet combined with LVS and are not fully functional. In the next post will be gradually put together. The next post will first make you feel the effect of LVS when used alone, and will eventually combine the two.








Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Linux Advanced tips: Heartbeat+lvs (i)

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.