Deploy LVS (DR) + Keepalived in RHEL5.4 to achieve high-performance and high-availability Load Balancing

Source: Internet
Author: User
I. Introduction to the functions implemented by LVS + Keepalived: Use the LVS controller master/slave mode to avoid spof and automatically delete the faulty WEB server node and add it to the cluster after it is restored. Topology: 2. System Environment System Platform: RHEL5.4LVS version: ipvsadm-1.24keepalived version: keepalived-1.1.15 3. installation 1. Install lvs, ke on two lvsservers

I. Introduction

Functions implemented by LVS + Keepalived: Use the Master/Slave Mode of The LVS controller to avoid spof and automatically delete the faulty WEB server node and add it to the cluster after it is restored.

Topology:

Ii. System Environment

System Platform: RHEL 5.4

LVS version: ipvsadm-1.24

Keepalived version: keepalived-1.1.15

Iii. Installation

1. Install LVS and keepalived software (LVS_MASTER & LVS_BACKUP) on two lvs servers)
Lvs install -------------

[Root @ LVS-MASTER ~] # Wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz

[Root @ LVS-MASTER ~] # Ln-s/usr/src/kernels/2.6.18-194. el5-i686 // usr/src/linux/

[Root @ LVS-MASTER ~] # Tar zxvf ipvsadm-1.24.tar.gz

[Root @ LVS-MASTER ~] # Cd ipvsadm-1.24

[Root @ LVS-MASTER ipvsadm-1.24] # make & make install

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

[Root @ LVS-MASTER ~] # Wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz

[Root @ LVS-MASTER ~] # Tar zxvf keepalived-1.1.15.tar.gz

[Root @ LVS-MASTER ~] # Cd keepalived-1.1.15

[Root @ LVS-MASTER keepalived-1.1.15] #./configure & make install

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

[Root @ LVS-MASTER ~] # Cp/usr/local/etc/rc. d/init. d/keepalived/etc/init. d/

[Root @ LVS-MASTER ~] # Cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/

[Root @ LVS-MASTER ~] # Mkdir/etc/keepalived/

[Root @ LVS-MASTER ~] # Cp/usr/local/etc/keepalived. conf/etc/keepalived/

[Root @ LVS-MASTER ~] # Cp/usr/local/sbin/keepalived/usr/sbin/

[Root @ LVS-MASTER ~] # Service keepalived start | stop

2. keepalived Configuration

################### MASTER ###################

! Configuration File for keepalived

Global_defs {
Notification_email {
Root@linux.tang.chao
Mchina_tang@qq.com
}
Notification_email_from Alexandre.Cassen@firewall.loc
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}

Vrrp_instance VI_1 {
State MASTER
Interface eth0
Virtual_router_id 51
Priority100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {
10.0.0.148
}
}

Virtual_server 10.0.0.148 80 {
Delay_loop 6
Lb_algo rr
Lb_kind DR
Persistence_timeout 50
Protocol TCP

Real_server 10.0.0.20.80 {
Weight 3
TCP_CHECK {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
Real_server 10.0.0.139 80 {
Weight 3
TCP_CHECK {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
}

 

#################### BACKUP ###################

! Configuration File for keepalived

Global_defs {
Notification_email {
Root@linux.tang.chao
Mchina_tang@qq.com
}
Notification_email_from Alexandre.Cassen@firewall.loc
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}

Vrrp_instance VI_1 {
State BACKUP
Interface eth0
Virtual_router_id 51
Priority 99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {
10.0.0.148
}
}

Virtual_server 10.0.0.148 80 {
Delay_loop 6
Lb_algo rr
Lb_kind DR
Persistence_timeout 50
Protocol TCP

Real_server 10.0.0.20.80 {
Weight 3
TCP_CHECK {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
Real_server 10.0.0.139 80 {
Weight 3
TCP_CHECK {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
}

3. Run the realserver. sh script on the two Web servers to bind lo: 0 to the VIP address 10.0.0.148 and suppress ARP broadcast.

[Root @ web1 ~] # Cat realserver. sh
#! /Bin/bash
# Description: Config realserver

VIP = 10.0.0.148
 
/Etc/rc. d/init. d/functions
 
Case "$1" in
Start)
/Sbin/ifconfig lo: 0 $ VIP netmask 255.255.255.255 broadcast $ VIP
/Sbin/route add-host $ VIP dev lo: 0
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
Sysctl-p>/dev/null 2> & 1
Echo "RealServer Start OK"
;;
Stop)
/Sbin/ifconfig lo: 0 down
/Sbin/route del $ VIP>/dev/null 2> & 1
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 "RealServer Stoped"
;;
*)
Echo "Usage: $0 {start | stop }"
Exit 1
Esac
 
Exit 0

[Root @ web1 ~] # Sh realserver. sh start

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.