Deploy LVS (NAT) + keepalived in centos 6.3 to achieve high-performance and high-availability load balancing]

Source: Internet
Author: User
Tags failover

I. Introduction

VS/NAT schematic:

II,System Environment

Tutorial topology:

System Platform: centos 6.3

Kernel: 2.6.32-279. el6.i686

LVS version: ipvsadm-1.26

Keepalived version: keepalived-1.2.4

Iii. Installation

0. Before LVS is installed, the system must install popt-static, kernel-devel, make, GCC, OpenSSL-devel, lftp, libnl *, and popt *

1. Configure LVS + keepalived on the two ctor servers respectively.

LVS install -------------

[[Email protected] _ Master ~] # Wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz

[[Email protected] _ Master ~] # Ln-S/usr/src/kernels/2.6.32-279. el6.i686 // usr/src/Linux/

[[Email protected] _ Master ~] # Tar zxvf ipvsadm-1.26.tar.gz

[[Email protected] _ Master ~] # Cd ipvsadm-1.26

[[Email protected] _ Master ipvsadm-1.26] # Make & make install

Keepalived install -------------

[[Email protected] _ Master ~] # Wget http://www.keepalived.org/software/keepalived-1.2.4.tar.gz

[[Email protected] _ Master ~] # Tar zxvf keepalived-1.2.4.tar.gz

[[Email protected] _ Master ~] # Cd keepalived-1.2.4

[[Email protected] _ Master keepalived-1.2.4] #./configure & make install

######## Make keepalived a startup service for convenient management ##########

[[Email protected] _ Master ~] # Cp/usr/local/etc/rc. d/init. d/keepalived/etc/init. d/

[[Email protected] _ Master ~] # Cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/

[[Email protected] _ Master ~] # Mkdir/etc/keepalived/

[[Email protected] _ Master ~] # Cp/usr/local/etc/keepalived. CONF/etc/keepalived/

[[Email protected] _ Master ~] # Cp/usr/local/sbin/keepalived/usr/sbin/

[[Email protected] _ Master ~] # Service keepalived START | stop

2. Enable route forwarding

[[Email protected] _ Master ~] # Vim/etc/sysctl. conf
Net. ipv4.ip _ forward = 1
[[Email protected] _ Master ~] # Sysctl-P

3. Configure keepalived

[[Email protected] _ Master ~] # Less/etc/keepalived. conf

! Configuration File for keepalivedglobal_defs {   router_id LVS_MASTER            #BACKUP上修改为LVS_BACKUP}vrrp_instance VI_1 {    state MASTER                   #BACKUP上修改为BACKUP    interface eth0    virtual_router_id 51    priority 100                   #BACKUP上修改为80    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        10.0.0.227    }}vrrp_instance LAN_GATEWAY {    state MASTER                   #BACKUP上修改为LVS_BACKUP    interface eth1    virtual_router_id 52    priority 100                   #BACKUP上修改为80    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        192.168.10.10    }}virtual_server 10.0.0.227 80 {    delay_loop 6    lb_algo rr    lb_kind NAT#   persistence_timeout 5    protocol TCP    real_server 192.168.10.4 80 {        weight 3        TCP_CHECK {            connect_timeout 3            nb_get_retry 3            delay_before_retry 3            connect_port 80        }    }        real_server 192.168.10.5 80 {        weight 3        TCP_CHECK {            connect_timeout 3            nb_get_retry 3            delay_before_retry 3            connect_port 80        }    }}

The backup server is configured in the same way as above. First install LVS and then install keepalived, and then configure/etc/keepalived. conf. You only need to change the annotation part.

4. Set gateways on two real servers respectively

Set all gateways to 192.168.10.10.

5. Configure HTTP in two realservers

[[Email protected] ~] # Yum-y install httpd
[[Email protected] ~] # Cd/var/www/html/
[[Email protected] HTML] # Cat index.html
<H1> web1/192.168.10.4 [[Email protected] HTML] #/etc/init. d/httpd start
The configuration of another machine is the same, and the process is omitted.

6. Run service keepalived start on CentOS-LVS_MASTER and CentOS-LVS_BACKUP respectively to start keepalived to realize load balancing and high availability cluster;

[[Email protected] _ Master keepalived] # service keepalived start

Iv. Test

#### High availability test ####

Simulate a fault, stop the keepalived service on the CentOS-LVS_MASTER, and then observe the log on the CentOS-LVS_BACKUP, the information is as follows

The log shows that after the host fails, the slave immediately detects that the slave is changed to the master role and takes over the virtual IP Address Resources of the host, finally, bind the virtual IP address to the etho device.

The log status of the CentOS-LVS_MASTER after the keepalived service on the CentOS-LVS_BACKUP is turned on.

The log shows that after the slave detects that the host is restored to normal, the virtual IP resource is released and becomes the backup role again.

#### Failover test ####

Failover is to test whether the keepalived monitoring module can detect and block faulty nodes in time when a node fails, and transfer the server to a normal node for execution.

Disable the service of the web2 node. If the node fails, the logs of the master and slave nodes are as follows:

As can be seen from the above, the keepalived monitoring module detects the failure of the host 192.168.10.5 and removes web2 from the cluster system. Access http: // 10.0.0.227 and only web1 is displayed)

Restart the service on the web2 node. The log information is as follows:

After the keepalived monitoring module detects that the host 192.168.10.5 is back to normal, it adds the node to the cluster system and can access the web2 page again)

 

 

Deploying LVS (DR) + keepalived in RHEL 5.4 to achieve high-performance and high-availability Load Balancing

Http://www.cnblogs.com/mchina/archive/2012/05/23/2514728.html

Classification: Linux Server tags: Nat, LVS, keepalived, high-performance, high-availability, and load balancing

Deploy LVS (NAT) + keepalived in centos 6.3 to achieve high-performance and high-availability load balancing]

Related Article

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.