Lvs + keepalived for load balancing and troubleshooting (DR Mode)

Source: Internet
Author: User
Tags reflector

Http://antsw.blog.51cto.com/936097/214975 this article from the "mountain twist" blog

Node1: 192.168.1.253
Node2: 192.168.1.254
VIP: 192.168.1.250
 
Environment centos5.2 (I used two machines here)
1. Install ipvsadm
Yum-y install ipvsadm
 
2. Install keepalived
[Root @ node1 ~] # Wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
[Root @ node1 ~] # Tar zxvf keepalived-1.1.15.tar.gz
[Root @ node1 ~] # Cd keepalived-1.1.15
[Root @ node1 keepalived-1.1.15] #. /configure -- prefix =/-- mandir =/usr/local/share/man/-- with-kernel-dir =/usr/src/kernels/2.6.18-92. el5-i686/
The result is entered correctly after configure.
Keepalived configuration
------------------------
Keepalived version: 1.1.15
Compiler: gcc
Compiler flags:-g-O2
Extra Lib:-lpopt-lssl-lcrypto
Use IPVS Framework: Yes # support for lvs
S sync daemon support: Yes
Use VRRP Framework: Yes
Use LinkWatch: No
Use Debug flags: No
 
[Root @ node1 keepalived-1.1.15] # make & make install
At this point, the installation of lvs + keepalived is complete. However, you cannot use the lvs function. Next, configure lvs + keepalived in dr mode.
 
3. [root @ node1 ~] # Cd/etc/keepalived/
[Root @ node1 keepalived] # vim keepalived. conf
! Configuration File for keepalived
Global_defs {
Notification_email {
Shanswei@gmail.com
}
Notification_email_from shanswei@gmail.com
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}
 
Vrrp_instance VI_1 {
State MASTER # Set master lvs to MASTER
Interface eth0
Virtual_router_id 51
Priority 102 # Set From lvs to 99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {
192.168.1.250 # if multiple VIPs exist, enter the new line.
}
}
Virtual_server 192.168.1.250 80 {
Delay_loop 6
Lb_algo wlc
Lb_kind DR
Persistence_timeout 50
Protocol TCP
 
Real_server 192.168.1.253 80 {
Weight 3
TCP_CHECK {
Connect_port 80
Connect_timeout 30
}
}
Real_server 192.168.1.254 80 {
Weight 1
TCP_CHECK {
Connect_port 80
Connect_timeout 30
}
}
 
Now, the keepalived configuration is complete.
Start keepalived
[Root @ node1 ~] #/Etc/init. d/keepalived start
If you want to start with the system, run chkconfig -- add keepalived
Chkconfig keepalived on
 
4. Configure the Real Server. Use the script here (this script is only executed on the WEB machine. I use two machines now. Servers act as both lvs and web servers)
[Root @ node1 keepalived] # vim realserver
#! /Bin/bash
# Description: start realserver
VIP = 192.168.1.250
/Etc/rc. d/init. d/functions
Case "$1" in
Start)
Echo "start LVS of REALServer"
/Sbin/ifconfig lo: 0 $ VIP broadcast $ VIP netmask 255.255.255.255 up
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
;;
Stop)
/Sbin/ifconfig lo: 0 down
Echo "close LVS Directorserver"
Echo "0">/proc/sys/net/ipv4/conf/lo/arp_ignore
Echo "0">/proc/sys/net/ipv4/conf/lo/arp_announce
Echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore
Echo "0">/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
Echo "Usage: $0 {start | stop }"
Exit 1
Esac
[Root @ node1 keepalived] # chmod + x realserver
[Root @ node1 keepalived] #./realserver start
 
5. Start keepalived (with startup log)
[Root @ node1 ~] #/Etc/init. d/keepalived start (Master LVS)
Oct 15 13:59:36 vmtest Keepalived: Starting Keepalived v1.1.15 (10/15, 2009)
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Using MII-BMSR NIC polling thread...
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Netlink reflector reports IP 192.168.1.253 added
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Netlink reflector reports IP 10.0.0.253 added
Oct 13:59:36 vmtest Keepalived_healthcheckers: Registering Kernel netlink reflector
Oct 13:59:36 vmtest Keepalived_healthcheckers: Registering Kernel netlink command channel
Oct 13:59:36 vmtest Keepalived_healthcheckers: Opening file/etc/keepalived. conf.
Oct 13:59:36 vmtest Keepalived_healthcheckers: Configuration is using: 11891 Bytes
Oct 13:59:36 vmtest Keepalived_healthcheckers: Activating healtchecker for service [192.168.1.253: 80]
Oct 13:59:36 vmtest Keepalived_healthcheckers: Activating healtchecker for service [192.168.1.254: 80]
Oct 15 13:59:36 vmtest Keepalived: Starting Healthcheck child process, pid = 28419
Oct 15 13:59:36 vmtest Keepalived_vrrp: Using MII-BMSR NIC polling thread...
Oct 15 13:59:36 vmtest Keepalived_vrrp: Netlink reflector reports IP 192.168.1.253 added
Oct 15 13:59:36 vmtest Keepalived: Starting VRRP child process, pid = 28420
Oct 13:59:36 vmtest Keepalived_vrrp: Netlink reflector reports IP 10.0.0.253 added
Oct 13:59:36 vmtest Keepalived_vrrp: Registering Kernel netlink reflector
Oct 13:59:36 vmtest Keepalived_vrrp: Registering Kernel netlink command channel
Oct 13:59:36 vmtest Keepalived_vrrp: Registering gratutious ARP shared channel
Oct 13:59:36 vmtest Keepalived_vrrp: Opening file/etc/keepalived. conf.
Oct 13:59:36 vmtest Keepalived_vrrp: Configuration is using: 36278 Bytes
Oct 15 13:59:36 vmtest Keepalived_vrrp: VRRP sockpool: [ifindex (2), proto (112), fd ()]
Oct 15 13:59:37 vmtest Keepalived_vrrp: VRRP_Instance (VI_1) Transition to MASTER STATE
Oct 13:59:38 vmtest Keepalived_vrrp: VRRP_Instance (VI_1) Entering MASTER STATE
Oct 13:59:38 vmtest Keepalived_vrrp: VRRP_Instance (VI_1) setting protocol VIPs.
Oct 13:59:38 vmtest Keepalived_vrrp: VRRP_Instance (VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.250
Oct 13:59:38 vmtest Keepalived_healthcheckers: Netl

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.