LVS + Keepalived usage Summary

Source: Internet
Author: User

LVS + Keepalived usage Summary
I. lvs introduction and recommended MaterialsIi. Installation of lvs and keepalivedIii. lvs vs/DR Mode ConstructionIv. lvs vs/TUN mode EstablishmentV. lvs vs/NAT Mode Construction6. keepalived multiple real server health check instancesVII. lvs persistence principle and Configuration8. lvs data monitoring9. lvs + keepalived troubleshootingI. LVS introduction and recommended Materials

Learn the three documents that must be read by LVS + Keepalived.

1. For the Keepalived authoritative guide, see

2. LVS Manual

3. Red_Hat_Enterprise_Linux-5-Virtual_Server_Administration-zh-CN

These three documents are official documents that introduce most of the principles and basic knowledge. Below I will mainly record some use cases for easy reference.

LVS/DR + Keepalived

LVS + Keepalived achieves layer-4 load and high availability

LVS + Keepalived high-availability server Load balancer cluster architecture Experiment

Heartbeat + LVS build a high-availability server Load balancer Cluster

Build an LVS load balancing test environment

A stress test report for LVS

What do they do?

In the LVS + Keepalived environment, lvs mainly provides scheduling algorithms to schedule client requests on the real Server as needed. The main task of keepalived is to provide a redundancy of The lvs controller, health check is performed on the real Server to remove unhealthy real servers from The lvs cluster. The real Server is only responsible for providing services.

Ii. Installation of lvs and keepalived

Environment Planning

2 * (lvs + keepalived server) + n * real-server. Generally, lvs + keepalived is an architecture like this.

Start Installation

1. download the software package

Package for lvs in http://www.linuxvirtualserver.org/download

Download the keepalived package in the http://www.keepalived.org/

2. Compile and install lvs first, and then install keepalived. To install lvs, the kernel source code is required.

When downloading the lvs source code, you must select the source code package corresponding to your kernel version.

# Uname-r2.6.18-164. el5PAE # yum install kernel-devel-y // install the kernel source package # ln-s/usr/src/kernels/2.6.18-164. el5PAE-i686 // usr/src/linux # wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz // The ipvsadm package is the lvs package, do not think the name is not the same # tar-zxvf ipvsadm-1.24.tar.gz # cd ipvsadm-1.24 # make & make install

Check whether lvs is successfully installed:

# Ipvsadm // check whether output exists

# Lsmod | grep ip_vs // If ipvsadm has output, use this command to check whether the ip_vs module is loaded. If it is loaded, lvs is successfully installed.

2. Compile and install keepalived. keepalive must be installed after lvs is installed.

# Wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz // It is not recommended to select the latest version # tar-zxvf keepalived-1.1.15.tar.gz # cd keepalived-1.1.15 #. /configure -- prefix =/-- mandir =/usr/local/share/man/-- with-kernel-dir =/usr/src/linux/Keepalived version: 1.1.15Compiler: gccCompiler flags: -g-O2Extra Lib:-lpopt-lssl-lcryptoUse IPVS Framework: YesIPVS sync daemon support: YesUse VRRP Framework: YesUse LinkWatch: NoUse Debug flags: Nod

 

If you see the values of yes and no, the configuration is successful. If lvs is no, it proves that your lvs has not been installed successfully. You need to re-install lvs and then install keepalived.

#make && make install

If no error is reported, the installation is successful and check whether the keepalived command is generated.

Iii. lvs vs/DR Mode Construction

Environment Introduction

Host IP Address

Role

Install software

122.225.32.134

Lvs + keepalived MASTER

Ipvsadm keepalived

122.225.32.135

Lvs + keepalived BACKUP

Ipvsadm keepalived

122.225.32.136

Real server

Lvs_real script

122.225.32.20.

Real server

Lvs_real script

122.225.32.142

VIP

 

Note: All machines are in one vswitch and in one CIDR block.

1. Install ipvsadm and keepalived software on 134 and 135.

2. modify the configuration file of keepalived.

122.225.32.134:

# Cat/etc/keepalived. conf! Configuration File for login {icationication_email {lr@isadba.com} login lvs@isadba.com smtp_server route 30 router_id Protocol} vrrp_instance VI_1 {state MASTER interface eth0 Route 51 priority 150 advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {122.225.32.142} virtual_server 122.225.32.142 80 {delay_loop 6 lb_algo rr lb_kind DR nat_mask limit 255.0 persistence_timeout 0 // The value is 0, mainly to facilitate testing, the results of each page refresh will be different from those of protocol TCP real_server limit 80 {weight 1 TCP_CHECK {connect_port 80 connect_timeout 3 nb_get_retry 3 rows 3} real_server limit 80 {weight 1 TCP_CHECK {connect_port 80 connect delay_before_retry 3 }}}

 

122.225.32.135:

The value needs to be deleted compared with 122.225.32.134.State MASTERAnd modifyPriorityThe value is smaller than that of the master.

Real server:

Add the following script to all real servers and run it by name # cat/sbin/lvs_real

#!/bin/bash#description:start realservervip=122.225.32.157source /etc/rc.d/init.d/functionscase $1 instart)        echo "Start Realserver"        /sbin/ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up        echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore        echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce        echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore        echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce;;stop)        echo "Stop Realserver"        /sbin/ifconfig lo:0 down        echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore        echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce        echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore        echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce;;*)        echo "Usage: $0 (start | stop)"exit 1esac

After the script is executed, run the ip add command to check whether the virtual ip address is added to the lo interface.

Of course, real serverworker installs the httpservice and starts, and adds its own IP address in index.html, so that the client can identify which host is accessed during access.

3. After the configuration is complete, start the test:

Use ip add check on 122.225.32.134 and 122.225.32.135. The virtual IP address should be configured on 134.

Test 1 {main test lvs}: whether the virtual IP Address can access the real server and whether the real server is polling

Run the ipvsadm command on the master to view the lvs status.

# ipvsadmIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags  -> RemoteAddress:Port           Forward Weight ActiveConn InActConnTCP  122.225.32.142:http rr  -> 122.225.32.137:http          Route   1      0          0          -> 122.225.32.136:http          Route   1      0          0

Access the virtual IP address 122.225.32.142 on the client to see if it is accessible. Each time you refresh, you should change to a real server. After several threads, use ipvsadm to observe the lvs status.

# ipvsadmIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags  -> RemoteAddress:Port           Forward Weight ActiveConn InActConnTCP  122.225.32.142:http rr  -> 122.225.32.137:http          Route   1      0          6          -> 122.225.32.136:http          Route   1      0          6

Test 2 {mainly test keepalived}: HA of The lvs server. If the keepalived master fails, Will keepalived backup take over the virtual IP address.

Shut down the keepalived process on the master host.

On the backup server, add ip address to check whether a virtual IP address is added, and view the conversion logs through/var/log/message.

 

Test 3 {test backup lvs}: Use the client to access the current virtual ip address and check whether everything is normal.

After the test is complete, enable the keepalived process of the master node. After the virtual ip address is transferred to the master node, access it from the client to check whether the problem exists.

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.