High-availability LVS Based on Keepalived dual-Master Model

Source: Internet
Author: User

High-availability LVS Based on Keepalived dual-Master Model

Background:

Keepalived: the purpose of Keepalived is to check the status of the web server. If a web server crashes or a job fails, Keepalived will detect it, and remove the faulty web server from the system. When the web server works normally, Keepalived automatically adds the web server to the server group. All these tasks are completed automatically without manual interference, only the web servers that need to be manually repaired.

LVS: LVS is short for Linux Virtual Server. It is a Virtual Server cluster system.

Experimental System: CentOS 6.6 _ x86_64

Prerequisites: Prepare the compiling environment in advance, and disable both firewall and selinux.

Tutorial Description: In this experiment, there are four hosts, of which keep1 and keep2 are two front-end keepalived servers. real1 and real2 are the realservers in LVS, And the IP addresses correspond to the topology.

Experimental software: httpd-2.2.15 keepalived-1.2.19

Tutorial topology:

1. Configure realserver

1. Install httpd:

Yum-y install httpd

2. Configure kernel parameters:

Echo 1>/proc/sys/net/ipv4/conf/lo/arp_ignore // respond only when the requested address is configured on the interface of the Request Message
Echo 1>/proc/sys/net/ipv4/conf/all/arp_ignore
Echo 2>/proc/sys/net/ipv4/conf/lo/arp_announce // the address of the directly connected network interface is advertised.
Echo 2>/proc/sys/net/ipv4/conf/all/arp_announce

3. Add the test page and configure the VIP:

On real1:

Ifconfig lo: 0 192.168.19.150 netmask 255.255.255.255 broadcast 192.168.19.150 up // configure VIP
Ifconfig lo: 1 192.168.19.151 netmask 255.255.255.255 broadcast 192.168.19.151 up
Route add-host 192.168.19.150 dev lo: 0 // configure the route
Route add-host 192.168.19.151 dev lo: 1
Vim/var/www/html/index.html
---------------------------------------------
<H1> realserver1 ---------------------------------------------
Service httpd start

On real2:


Ifconfig lo: 0 192.168.19.150 netmask 255.255.255.255 broadcast 192.168.19.150 up
Ifconfig lo: 1 192.168.19.151 netmask 255.255.255.255 broadcast 192.168.19.151 up
Route add-host 192.168.19.150 dev lo: 0
Route add-host 192.168.19.151 dev lo: 1
Vim/var/www/html/index.html
---------------------------------------------
<H1> realserver2 ---------------------------------------------
Service httpd start

Ii. install and configure keepalived

1. Compile and install keepalived and operate on keep1 and keep2:

Wget http://www.keepalived.org/software/keepalived-1.2.19.tar.gz
Tar xf keepalived-1.2.19.tar.gz
Cd keepalived-1.2.19
./Configure -- prefix =/usr/local/keepalived
Make & make install
Cp-p/usr/local/keepalived/etc/rc. d/init. d/keepalived/etc/init. d/
Chkconfig -- add keepalived
Chkconfig keepalived on
Ln-sv/usr/local/keepalived/etc/sysconfig/keepalived
Cp-p/usr/local/keepalived/sbin/keepalived/usr/sbin/keepalived
Ln-sv/usr/local/keepalived/etc/keepalived
Yum-y install ipvsadm // install LVS


Copy code

2. Configure keepalived:

Keep1:

Vim/etc/keepalived. conf
----------------------------------------------------
Vrrp_instance VI_1 {
State MASTER
Interface eth0
Virtual_router_id 31
Priority100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass abcd
}
Virtual_ipaddress {
192.168.19.150
}
}

Vrrp_instance VI_2 {
State BACKUP
Interface eth0
Virtual_router_id 41
Priority 99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass abcd
}
Virtual_ipaddress {
192.168.19.151
}
}

Virtual_server 192.168.19.150 80 {
Delay_loop 6
Lb_algo rr // LVS Algorithm
Lb_kind DR // scheduling type
Protocol TCP

Real_server 192.168.19.29 {
Weight 1
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}

Real_server 192.168.19.34 {
Weight 1
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}

Virtual_server 192.168.19.151 80 {
Delay_loop 6
Lb_algo rr
Lb_kind DR
Protocol TCP

Real_server 192.168.19.29 {
Weight 1
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}

Real_server 192.168.19.34 {
Weight 1
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}

On keep2:

Vim/etc/keepalived. conf
----------------------------------------------

Vrrp_instance VI_1 {
State BACKUP
Interface eth0
Virtual_router_id 31
Priority 99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass abcd
}
Virtual_ipaddress {
192.168.19.150
}
}

Vrrp_instance VI_2 {
State MASTER
Interface eth0
Virtual_router_id 41
Priority100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass abcd
}
Virtual_ipaddress {
192.168.19.151
}
}

Virtual_server 192.168.19.150 80 {
Delay_loop 6
Lb_algo rr
Lb_kind DR
Protocol TCP

Real_server 192.168.19.29 {
Weight 1
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}

Real_server 192.168.19.34 {
Weight 1
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}

Virtual_server 192.168.19.151 80 {
Delay_loop 6
Lb_algo rr
Lb_kind DR
Protocol TCP

Real_server 192.168.19.29 {
Weight 1
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}

Real_server 192.168.19.34 {
Weight 1
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}

3. Start keepalived on two machines:

Service keepalived start
Ipvsadm-L-n // run keepalived with LVS Tool
Ip addr show // view VIP

The LVS rules take effect on both machines, and the two VIPs run on two nodes:

Keep1:

On keep2:

Open the test page to test:

When any node is stopped, resources are automatically transferred:

Now, the demo is complete. Thank you!

Haproxy + Keepalived + Apache configuration notes in CentOS 6.3

Haproxy + KeepAlived WEB Cluster on CentOS 6

Keepalived + Haproxy configure high-availability Load Balancing

Haproxy + Keepalived build high-availability Load Balancing

Configure LVS + Keepalived + ipvsadm on CentOS 7

Keepalived high-availability cluster Construction

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

Keepalived build highly available LVS Cluster

For more information about Keepalived, click here.
Keepalived: click here

This article permanently updates the link address:

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.