LVS + Keepalived for high-availability Load Balancing

Source: Internet
Author: User

Although LVS implements load balancing, it cannot solve a serious problem. When a RealServer is on the machine, it cannot direct subsequent requests allocated to the server to other surviving servers.

$ Sudo apt-get install ipvsadm keepalived
You can directly modify keepalived. conf without configuring ipvsadm.

$ Sudo vim/etc/keepalived. conf

Global_defs {
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 {
192.168.1.100
}
}

Virtual_server 192.168.1.100 80 {
Delay_loop 1 # query RealServer status every 1 second
Lb_algo wrr # LVS Algorithm
Lb_kind DR # Direct Route
# Persistence_timeout 60 # the same IP address is allocated to the same RealServer within 60 seconds.
Protocol TCP # Use the TCP protocol to check the RealServer status

Real_server 192.168.1.10 80 {
Weight 3 # weight
TCP_CHECK {
Connect_timeout 10 # No response timeout in 10 seconds
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}

Real_server 192.168.1.20 80 {
Weight 3
TCP_CHECK {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
}}
Start the keepalived service.

$ Sudo service keepalived start
Check ipvsadm settings.

$ Sudo ipvsadm-ln

IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddress: Port sched1_flags
-> RemoteAddress: Port Forward Weight ActiveConn InActConn
TCP 192.168.1.100: 80 wrr
-> 192.168.1.10: 80 Route 3 0 0
-> 192.168.1.20: 80 Route 3 0 0
Add configuration information to all RealServer/etc/rc. local and restart.

$ Sudo vim/etc/rc. local

#! /Bin/sh-e
#
# Rc. local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# Value on error.
#
# In order to enable or disable this script just change the execution
# Bits.
#
# By default this script does nothing.

Ifconfig lo: 0 192.168.1.100 netmask 255.255.255.255 broadcast 192.168.1.100 up
Route add-host 192.168.1.100 dev lo: 0

Echo "0">/proc/sys/net/ipv4/ip_forward
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

Exit 0
Then we can use a browser to test the load effect. Shut down a RealServer and you will find that the request is forwarded to another RealServer. After the "damaged" server is restarted, the Server Load balancer returns to normal.

(Check the firewall settings. I have been depressed for a long time)

Lab environment: Ubuntu Server 10.04

------------ Separator ------------

In fact, we should also find a server to perform hot backup on the LVS server (see Keepalived dual-host Hot Backup). This is the real high-availability solution.

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.