LVS dr+keepalived Implementation HA+LB

Source: Internet
Author: User

4 Servers Required First

2 dir respectively is Dirmaster Dirslave

2 RS run Nginx test service respectively

Dir

192.168.186.129

192.168.186.135

Rs

192.168.186.130

192.168.186.132

    1. First Build LVS-DR Service

      A.dir above installation Ipvsadm

Yum Install Ipvsadm

B. Changing the Ipvsadm configuration file

vim/etc/usr/local/sbin/lvs_dr.sh

#! /bin/bash
echo 1 >/proc/sys/net/ipv4/ip_forward #dir服务器行开启路由转发功能
Ipv=/sbin/ipvsadm
vip=192.168.186.110
rs1=192.168.186.130
rs2=192.168.186.132

#设置vip

Ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
Route add-host $vip Dev eth0:0
$IPV-C
$IPV-A-T $VIP: 80-s RR
$IPV-A-t $vip: 80-r $rs 1:80-g-W 1
$IPV-A-t $vip: 80-r $rs 2:80-g-W 1


Two RS on: vim/usr/local/sbin/lvs_dr_rs.sh
#! /bin/bash
vip=192.168.186.110
Ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
Route Add-host $vip 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

C. Then the director executes: bash/usr/local/sbin/lvs_dr.sh
Performed on two rs: bash/usr/local/sbin/lvs_dr_rs.sh
Windows under Browser test access


When the above is done, the load balance of Rs can be realized, and each request is apportioned according to the weight setting.

However, if a certain RS service is stopped, then the client request will still be directly on the RS that stopped the service.


2. Add keepalived Service


Note: Although we have already configured some operations, but below we use keepaliave operation and previous operation is some conflict, so if previously configured Dr, please do the following first: perform on DR:

$IPV-C
Ifconfig eth0:0 Down

Although the previous LVS have been configured successfully and load balanced, we found that when a real server stopped the Nginx process, the Director would still forward the request to the past, which caused some requests to be abnormal. So there needs to be a mechanism to detect the state of real server, which is keepalived. In addition to detecting the RS State, it can also detect the state of the standby director, that is, keepalived can implement the HA cluster function, of course, also need a standby director.

A. Install the keepalived on both the host and the standby machine

Yum Install-y keepalived

After the installation, edit the configuration file.
vim/etc/keepalived/keepalived.conf//Join as follows:
Vrrp_instance Vi_1 {
State MASTER #备用服务器上为 BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority #备用服务器上为90
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.186.110
}
}
Virtual_server 192.168.186.110 80 {
Delay_loop 6 # (query Realserver status every 10 seconds)
Lb_algo WLC # (LVS algorithm)
Lb_kind DR # (Direct Route)
Persistence_timeout 60 # (connection of the same IP is assigned to the same realserver within 60 seconds)
Protocol TCP # (check realserver status with TCP protocol)

Real_server 192.168.186.100 80 {
Weight 100 # (weight)
Tcp_check {
Connect_timeout 10 # (10 seconds No response timeout)
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
Real_server 192.168.186.101 80 {
Weight 100
Tcp_check {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
}

The above configuration files for the Master director are only required to be modified from the director's profile
State MASTER-State BACKUP
Priority 90
After configuring keepalived, you need to turn on port forwarding (master/slave):
Echo 1 >/proc/sys/net/ipv4/ip_forward
Then, execute the/usr/local/sbin/lvs_dr_rs.sh script on two RS
Finally, the two director starts the Keepalived Service (Guthrie):
/etc/init.d/keepalived start
Also, it is important to note that starting the Keepalived service automatically generates VIP and IPVSADM rules and does not need to execute the/usr/local/sbin/lvs_dr.sh script mentioned above.

This article mainly wrote how to build a service, explain I forwarded an article ~ ~ ~

This article is from the "Cubs blog" blog, make sure to keep this source http://9821177.blog.51cto.com/9811177/1715631

LVS dr+keepalived Implementation HA+LB

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.