Lvs/keepalived of LB clusters

Source: Internet
Author: User


On the basis of the previous experiment, LVS/DR

(Nta,dr HA is operated with Nginx service, eliminating the installation of Nginx installation configuration)

Although the LVS have been successfully configured and load balanced, we found that when a real server stopped the httpd process, the Director would then forward the request to the past, causing some requests to be unhealthy. So there needs to be a mechanism to detect the state of real server, which is keepalived. Its role in addition to detecting the RS State, can also detect the state of the standby director, that is, keepalived (set ha+lb in one) can realize the function of HA cluster, of course, also need a standby director.

Experimental environment: Three virtual machines, 10.72.4.48 (Dir/master), 10.72.4.39 (Rs2&slave), 10.72.4.37 (RS2)


[Email protected] ~]# ipvsadm-c #清空之前的规则

[email protected] ~]# Yum install-y keepalived #安装keepalived


[Email protected] ~]# vim/etc/keepalived/keepalived.conf

State MASTER #备用服务器上为 BACKUP

Interface eth0

VIRTUAL_ROUTER_ID 51

Priority #备用服务器上为90

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 1111

}

virtual_ipaddress {

10.72.4.100

}

}


Virtual_server 10.72.4.100 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 10.72.4.37 {

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 10.72.4.39 80 {

Weight 100

Tcp_check {

Connect_timeout 10

Nb_get_retry 3

Delay_before_retry 3

Connect_port 80

}

}

}


------------------------------------------------

[Email protected] ~]# scp/etc/keepalived/keepalived.conf 10.72.4.39:/etc/keepalived/keepalived.conf #拷贝到从上


[Email protected] ~]# vim/etc/keepalived/keepalived.conf #只改以下两处, no need to change anywhere else

Vrrp_instance Vi_1 {

State backup #备用服务器上为 backup

Interface eth0

VIRTUAL_ROUTER_ID 51

Priority #备用服务器上为90

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 1111

}

virtual_ipaddress {

10.72.4.100

}

}

------------------------------------------

[[Email protected]dir ~]#/etc/init.d/keepalived start

Starting keepalived: [ OK ]


[Email protected]rs2 ~]#/etc/init.d/keepalived start

Starting keepalived: [ OK ]


[Email protected]rs1 ~]vim/usr/local/sbin/lvs_nat.sh #编译脚本

#! /bin/bash
vip=650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/ Zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>10.72.4.100
Ifconfig lo:0 $VIP broadcast $VIP netmask 650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd; "alt=" spacer.gif "/>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


[Email protected] ~]sh/usr/local/sbin/lvs_nat.sh #执行脚本


[Email protected]rs2 ~]vim/usr/local/sbin/lvs_nat.sh #编译脚本

#! /bin/bash
vip=650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/ Zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>10.72.4.100
Ifconfig lo:0 $VIP broadcast $VIP netmask 650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd; "alt=" spacer.gif "/>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


[Email protected]rs2 ~]sh/usr/local/sbin/lvs_nat.sh #执行脚本


[[email protected] ~]# vim/usr/local/sbin/lvs_dr.sh Port forwarding script on the #编译打开dir

#! /bin/bash

Echo 1 >/proc/sys/net/ipv4/ip_forward


[Email protected] ~]# sh/usr/local/sbin/lvs_dr.sh #执行脚本



650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/8B/E3/wKiom1hbjuzwpibmAAHW6vTCe6Y599.jpg "title=" k1.jpg "alt=" Wkiom1hbjuzwpibmaahw6vtce6y599.jpg "/>


[Email protected]rs2 ~]#/etc/init.d/nginx stop #停掉 the Nginx on the RS2,

stopping nginx: [OK]

After the nginx on the #停掉rs2, IE refreshes 10.72.4.100, no more content on the RS2 will appear. And the primary server will also rs2 the IP kick, restart the rs2 on the Nginx service, will return to normal.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/8B/E4/wKiom1hbktPwiO3SAABwghf6mTQ492.jpg "title=" k2.jpg "alt=" Wkiom1hbktpwio3saabwghf6mtq492.jpg "/>

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M00/8B/E0/wKioL1hbk3uwwq3nAACJR-5QdzU311.jpg "title=" k3.jpg "alt=" Wkiol1hbk3uwwq3naacjr-5qdzu311.jpg "/>


--------------------------------------------------------

[[email protected] ~]#/etc/init.d/keepalived stop #停掉主dir上的 keepalived, rs2 from the keepalived will start, instead of Dir into the main, continue to work.

stopping keepalived: [OK]

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/8B/E0/wKioL1hblt7in9yxAALR7LWQvWo458.jpg "title=" k6.jpg "alt=" Wkiol1hblt7in9yxaalr7lwqvwo458.jpg "/>

Restarting the main keepalived again will revert to the previous state.

This article is from the "Cbo#boy_linux Road" blog, make sure to keep this source http://20151213start.blog.51cto.com/9472657/1885165

Lvs/keepalived of LB clusters

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.