LVS + Keepalived solution for high availability and load balancing

Source: Internet
Author: User
Experiment topology: Experiment ip address planning VIP: 192.168.1.200Realserver1: 192.168.1.195Realserver2: 192.168.1.193 heartbeat line: 10.1.1.1, 10.1.1.2DR1: 192.168.1.192DR2: 192.168.1.1.190 implementation process 1: configure LVS [root @ localhost ~] on the master node.

Experiment topology:

Lab ip plan

VIP: 192.168.1.200

Real server1: 192.168.1.195

Real server2: 192.168.1.193

Heartbeat line: 10.1.1.1 and 10.1.1.2

DR1: 192.168.1.192

DR2: 192.168.1.1.190

 

Implementation Process

1. configuration on the master node

First configure LVS

[Root @ localhost ~] #CdTooLs/

[Root @ localhost tools] # ls ipvsadm-1.24.tar.gz

Ipvsadm-1.24.tar.gz

[Root @ localhost tools] # tar zxvf ipvsadm-1.24.tar.gz

[Root @ localhosttools] # cd ipvsadm-1.24

[Root @ localhost ipvsadm-1.24] #Ln-S/usr/src/kernels/2.6.18-164. el5/usr/src/linux/

[Root @ localhost ipvsadm-1.24] # make all & make install

Install and configure keepalivEd

[Root @ localhost tools] # ls keepalived-1.2.2.tar.gz

Keepalived-1.2.2.tar.gz

[Root @ localhost tools] # tar zxvf keepalived-1.2.2.tar.gz

[Root @ localhosttools] # cd keepalived-1.2.2

[Root @ localhost keepalived-1.2.2] # vi keepalived/libipvs-2.6/ip_vs.h

Find the following line:

# INcLude /* For _ beXX types in userland */

Put it under the following line:

# Include

[Root @ localhost keepalived-1.2.2] # make & make install

# Ln-s/usr/local/sbin/keepalived/sbin/

[Root @ localhost ~] # Cd/etc/keepalived/

[Root @ localhost keepalived] #CpKeepalived. conf keepalived. conf. bak // backup

[Root @ localhost keepalived] # vi keepalived. conf // modify the configuration file as follows:

! Configuration File for keepalived

 

Global_defs {

NotifiCatIon_email {

Wethnicity@126.com

38205036@qq.com

}

Notification_email_from AlExAndre. Cassen @ fireWall. Loc

Smtp_server 192.168.1.192

Smtp_connect _TimeOut 30

Router _IdLVS_DEVEL

}

 

Vrrp_instance VI_1 {

StatE MASTER

Interface eth0

Virtual_router_id 51

Priority100

Advert_int 1

Authentication {

Auth_typePASS

Auth_pass 1111

}

Virtual_ipaDdRess {

192.168.1.200

}

}

 

Virtual_server 192.168.1.200 80 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Nat_mask 255.255.255.0

Persistence_timeout 50

ProtoColTCP

 

Real_server 192.168.1.193 80 {

Weight 1

TCP_CHECK {

Connect_timeout 10

Nb_get_reTrY 3

Delay_before_retry 3

}

}

Real_server 192.168.1.195 80 {

Weight 1

TCP_CHECK {

Connect_timeout 10

Nb_get_retry 3

Delay_before_retry 3

}

}

}

The settings on the slave node are basically the same as those on the master node (because the same service is provided). You only need to modify keepalived. con.

Vrrp_instance VI_1 {

State BACKUP // Modification

Interface eth0

Virtual_router_id 51

Priority 80 // Modification

Advert_int 1

Authentication {

Auth_typePASS

Auth_pass 1111

}

Second: settings on the real server (the two real servers are basically the same, so only one is set here)

[Root @ localhost ~] # Cd/var/www/html/

[Root @ localhost html] # vi index.html

It \'s 192.168.1.195 !!

[Root @ localhost html] #/etc/init. d/HttpdStart

[Root @ localhost ~] # Vi/etc/init. d/lvsrs

#! /Bin/bash

VIP = 192.168.1.200

/Sbin/IfconfigLo: 0 $ VIP broadcast $ VIP netmask 255.255.255.255 up

/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

# End

[Root @ localhost ~] #ChmodA + x/etc/init. d/lvsrs

[Root @ localhost ~] #/Etc/init. d/lvsrs start

 

Third: test part (enable real server's apache service)

[Root @ localhost ~] # Ipvsadm

IP Virtual Server version 1.2.1 (size = 4096)

Prot LocalAddress: Port ScheDuLer Flags

-> RemoteAddress: Port Forward Weight ActiveConn InActConn

TCP 192.168.1.200: http rr persistent 50

-> 192.168.1.193: http Route 1 0 0

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.