Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Linux Cluster with LVS Software under Linux

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to use LVS software under Linux to achieve Linux cluster. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

This paper introduces the cluster software LVS under Linux, and gives an example to introduce the detailed process of installation and implementation of cluster (cluster) under Linux.

Today, with the widespread application of a variety of network services, with the improvement of network speed and the increase of users, in some busy occasions, a single machine can no longer handle all network requests. To solve this problem, many users use a set of cluster (clusters) instead of a single machine. Cluster can connect multiple computers to work together to provide various services, such as Apache, FTP, Mail and so on.

The most common and probably the most widely used cluster scheme on Linux is LVS (Linux Virtual).

Server), I'm glad that LVS is also an open source project created and developed by the Chinese. LVS has been a relatively mature technical project since 1998. There are many well-known websites and organizations that use cluster built by LVS, such as www.linux.com, sourceforge.net, www.real.com and so on.

Let's start to introduce how the author uses LVS to set up a group of cluster to provide Apache and FTP services.

Install the operating system

The author chose Red Hat 9.0 as the operating system for some cluster director machines and all real server machines. RH installation process is brief, the author according to the actual needs, only installed a small number of packages. For batch installation of Linux, it is recommended to try Kickstart to enter the batch installation.

Compile kernels that support LVS

LVS has modified and added Linux's kernel, so you need to recompile linux kernel. We first download the kernel patch from http://www.linuxvirtualserver.org to LVS, update the original kernel source code, and then recompile Linux's kernel.

When downloading the kernel patch of LVS, it should be noted that the patch version should be consistent with the kernel version. For RH9.0, the Linux core version is 2.4.20, so the corresponding kernel patch should be http://www.linuxvirtualserver.org/software/kernel-2.4/linux-2.4.20-ipvs-1.0.9.patch.gz.

There is also a patch to solve the problem that the ARP protocol does not work in some cases, which can be downloaded from http://www.ssi.bg/~ja/hidden-2.4.20pre10-1.diff.

Copy the two patches downloaded above to the / usr/src directory and execute the following command:

Cd / usr/src

Gzip-cd linux-2.4.20-ipvs-1.0.9.patch.gz

Cd / usr/src/linux

Patch-p1 <.. / linux-2.4.20-ipvs-1.0.9.patch

Patch-p1 <.. / hidden-2.4.20pre10-1.diff

Make mrproper

Make menuconfig

When we execute make menuconfig, we will enter a graphical interface where we can set up the Linux Kernel in detail. The kernel options related to LVS are in "Networking options". If you enter "Networking options", you can view the "IP: Virtual Server Configuration" option and select all other sub-options:

< M > virtual server support (EXPERIMENTAL)

[*] IP virtual server debugging

12) IPVS connection table size (the Nth power of 2)

-IPVS scheduler

< M > round-robin scheduling

< M > weighted round-robin scheduling

< M > least-connection scheduling scheduling

< M > weighted least-connection scheduling

< M > locality-based least-connection scheduling

< M > locality-based least-connection with replication scheduling

< M > destination hashing scheduling

< M > source hashing scheduling

< M > shortest expected delay scheduling

< M > never queue scheduling

-IPVS application helper

< M > FTP protocol helper

In addition, all subitems of the options in "IP: Netfilter Configuration" in "Networking options" can be selected except for the following two items:

< > ipchains (2.2-style) support

< > ipfwadm (2.0-style) support

Also, there are some options about the network in "Networking options", so be careful to choose according to your own needs:

< * > Packet socket

[] Packet socket: mmapped IO

< * > Netlink device emulation

[*] Network packet filtering (replaces ipchains)

[*] Network packet filtering debugging

[*] Socket Filtering

< * > Unix domain sockets

[*] TCP/IP networking

[*] IP: multicasting

[*] IP: advanced router

[*] IP: policy routing

[] IP: use netfilter MARK value as routing key

[] IP: fast network address translation

< M > IP: tunneling

For other options for kernel, you can choose according to your needs. The configuration of kernel is a task that requires experience, care and patience. Improper configuration may lead to errors in the compilation process or problems such as the new kernel can not drive the original device.

Exit the save and continue with the following command:

Make dep

Make clean

Make bzImage

Make modules

Make modules_install

The above steps may take some time. If something goes wrong, please re-check your kernel configuration, and if there are no errors, continue to execute the following command:

Depmod-a

Cp arch/i386/boot/bzImage / boot/vmlinuz-lvs

Cp System.map / boot/System.map-lvs

Cd / boot

Rm System.map

Ln-s System.map-lvs System.map

Then modify your lilo.conf to start with a new kernel, such as in lilo.conf to add the following lines to add startup entries for the new LVS-enabled kernel:

P_w_picpath=/boot/vmlinuz-lvs

Label=lvs

Read-only

Root=/dev/sda1

Note: if you use Grub as the boot loader, please modify it yourself to add the startup entry for the new kernel that supports LVS.

Restart Linux and select the lvs entry to enter Linux.

Install ipvsadm

If it starts normally, start installing the IP virtual server software ipvsadm. Because we are using RH, we download the RPM package directly to install it. Download the RPM package from the following address:

Http://www.linuxvirtualserver.org/software/kernel-2.4/ipvsadm-1.21-7.src.rpm

Install ipvsadm with the following command:

Rpmbuild-- rebuild ipvsadm-1.21-7.src.rpm

Rpm-ivh / usr/src/redhat/RPMS/i386/ipvsadm-1.21-7.i386.rpm

At this point, the installation of LVS is half complete. That is, now that Linux has the ability to implement LVS, the next problem is if you use LVS to build a set of cluster. To implement a set of cluster, we need to use the ipvsadm tool for configuration, and before we start to use ipvsadm for configuration, we need to know some basic knowledge of LVS, especially the following three key points: the structure of LVS, the three packet forwarding modes of LVS, and the eight scheduling algorithms of LVS. Only with this knowledge can we figure out how to use ipvsadm for configuration. Here is a brief introduction to these three main points of LVS:

1. The structure of LVS

LVS cluster can be divided into two parts structurally: the front-end load balancer (called director) and the back-end real server (called real server). The director at the front end of cluster dispatches requests from the outside to different real server at the back end of cluster for execution. Real server is responsible for providing all kinds of application services, such as Web, FTP, Mail and so on. The quantity of real server can be increased or decreased according to the actual demand.

2. Three packet forwarding methods of LVS

LVS provides three packet forwarding methods: NAT (Network address Mapping), IP Tunneling (IP Tunnel), and Direct Routing (Direct routing). Different forwarding modes determine the network structure of different cluster. Here are three forwarding methods:

NAT (Network address Mapping)

NAT can support any operating system, as well as private networks, and only one Internet IP address is needed, but the performance of the whole system is limited. Because every time you need to rewrite the package in the execution of NAT, there is a certain delay; in addition, 80% of the data in most applications flows from the server to the client, that is, the user's request is very short, and the response of the server is very large, which creates a lot of pressure on the load balancer and becomes a new bottleneck.

IP Tunneling (IP Tunnel)

Director assigns requests to different real server. The real server responds directly to the user after processing the request, so the director load balancer handles only half of the connection between the client and the server. IP Tunneling technology not only greatly improves the scheduling capacity of director, but also greatly increases the maximum number of nodes that the system can hold, which can be more than 100nodes. Real server can run on any LAN or WAN, which means allowing geographical distribution, which is important in disaster recovery. The server must have a formal IP address for direct communication with the client, and all servers must support the IP tunneling protocol.

Direct Routing (direct routing)

Similar to IP Tunneling, the load balancer handles only half of the connections, avoiding new performance bottlenecks and increasing the scalability of the system. Compared with IP Tunneling, Direct Routing does not have the overhead of IP encapsulation, but due to the use of physical layer (modify MAC address) technology, all servers must be on a physical network segment.

3. Eight scheduling algorithms for LVS

LVS has implemented the following eight scheduling algorithms:

1. Round-robin scheduling (Round-Robin Scheduling)

two。 Weighted round robin scheduling (Weighted Round-Robin Scheduling)

3. Minimum connection scheduling (Least-Connection Scheduling)

4. Weighted minimum connection scheduling (Weighted Least-Connection Scheduling)

5. Locality-based minimum links (Locality-Based Least Connections Scheduling)

6. Locality-based minimum links with replication (Locality-Based Least Connections with Replication Scheduling)

7. Destination address hash scheduling (Destination Hashing Scheduling)

8. Source address hash scheduling (Source Hashing Scheduling)

Note: if you want to know the technical details of the above points, check the LVS home page. The home page of LVS is:

Http://www.LinuxVirtualServer.org/

Http://www.linux-vs.org/

After understanding the three main points of LVS, let's configure a cluster that uses Direct Routing packet forwarding and weighted minimum connection scheduling algorithm.

We know that Direct Routing packet forwarding is to send the request to real server by rewriting the MAC address of the request message. The director machine in the foreground only needs to receive and dispatch external requests and is not responsible for returning the feedback results of these requests. Both the director machine and real server have a network card connected to the same physical network segment. So we give the following network topology diagram:

The following configuration is required on the director machine:

Set up the IP:192.168.2.1 of this machine

Then execute the following command:

Ifconfig lo:0 192.168.2.254 netmask 255.255.255.255 broadcast

192.168.2.254 up

Route add-host 192.168.2.254 dev lo:0

Echo 1 > / proc/sys/net/ipv4/ip_forward

Echo 1 > / proc/sys/net/ipv4/conf/all/hidden

Ipvsadm-C

Ipvsadm-A-t 192.168.2.254 ipvsadm 80-s wlc

Ipvsadm-a-t 192.168.2.254purl 80-r 192.168.2.2-g

Ipvsadm-a-t 192.168.2.254purl 80-r 192.168.2.3-g

.

Ipvsadm-A-t 192.168.2.254 21-s wlc

Ipvsadm-a-t 192.168.2.254purl 21-r 192.168.2.2-g

Ipvsadm-a-t 192.168.2.254purl 21-r 192.168.2.3-g

.

The following configuration is required on the real server machine:

For the first real server (RS1), set up the native IP:192.168.2.2 and execute the following command:

Ifconfig lo:0 192.168.2.254 netmask 255.255.255.255 broadcast

192.168.2.254 up

Route add-host 192.168.2.254 dev lo:0

Make similar settings for other real server:RS2, RS3 and RS4.,.

After the above settings are completed, all access to port 80 of 192.168.2.254 will be assigned to the following real server through the director machine, and the result of real server processing will be directly fed back to the customer. So far, we have completed an example of cluster. With this example, I believe you can also easily set up a set of cluster using Linux. In fact, after cluster is set up here, it can not meet the requirements of formal application, and there are still some problems to be solved in practical application, such as installing monitoring software, monitoring the operation of the cluster, finding the faults of real server in time and adjusting the list of real server accordingly. There are also some problems such as data consistency of background real server nodes. These have been well solved in some commercial cluster software products, and there are also some non-commercial software in the network, such as mon is such a system resource monitoring program, which can monitor network service availability, server problems and so on. The most important thing is that mon provides a framework that users can define and expand. Please refer to other articles for these contents.

After reading the above, do you have any further understanding of how to implement Linux cluster with LVS software under Linux? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report