Keepalived + LVS high-availability Load Balancing

Source: Internet
Author: User

 

1. Install keepalived on two scheduling servers)
Vim/etc/yum. repo. d/rhel. repo
[Local-cdrom]
Name = local from cdrom
Baseurl = file: // mnt/
Enable = 1
Gpgcheck = 0

Yum-y install kernel-devel openssl-devel popt-devel
Rpm-ivh/mnt/Packgets/ipvsadm-1.25-9.el6.i686.rpm
Tar zxvf keepalived-1.2.2.tar.gz-C/usr/src/
Cd/usr/src/keepalived-1.2.2/
./Configure -- prefix =/-- with-kernel-dir =/usr/src/kernels/2.6.32-131.0.15.el6.i686
Make & make install
Chkconfig -- add keepalived
Chkconfig keepalived on
2. Configure the scheduler master: 192.168.13.95, slave: 192.168.13.96, drifting ip: 192.168.13.100) web Server pool Node 1: 192.168.13.41, node 2: 192.168.13.47)
1) configure the master HA scheduling Server
Cd/etc/keepalived/
Cp keepalived. conf keepalived. conf. bak
Vi/etc/keepalived. conf
################# Global configuration ################## 33
Global_defs {
Router_id LVS_HA_R1
}
################## HA settings ##############
Vrrp_instance VI_1 {
State MASTER
Interface eth0
Virtual_route_id 1
Priority100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 123123
}
Virtual_ipaddress {
192.168.13.100
}
}
################### Server pool configuration ################# #####
Virtual_server 192.168.13.100 80 {
Delay_loop 15
Lb_algo rr
Lb_kind DR
Protocol TCP
Real_server 192.168.13.41 80 {
Weight 1
TCP_CHECK {
Connect_port 80
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 4
}
}
Real_server 192.168.13.41 80 {
Weight 1
TCP_CHECK {
Connect_port 80
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 4
}
}
}

Modprobe ip_vs
Lsmod | grep ip_vs
Echo "modprobe ip_vs">/etc/rc. local
/Etc/init. d/keepalived restart
Chkconfig ipvsadm off
Ip addr show dev eth0
2) configure the HA slave scheduling Server
Cd/etc/keepalived/
Cp keepalived. conf keepalived. conf. bak
Vi/etc/keepalived. conf
################# Global configuration ################## 33
Global_defs {
Router_id LVS_HA_R2
}
################## HA settings ##############
Vrrp_instance VI_1 {
State SLAVE
Interface eth0
Virtual_route_id 1
Priority 99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 123123
}
Virtual_ipaddress {
192.168.13.100
}
}
################### Server pool configuration ################# #####
Virtual_server 192.168.13.100 80 {
Delay_loop 15
Lb_algo rr
Lb_kind DR
Protocol TCP
Real_server 192.168.13.41 80 {
Weight 1
TCP_CHECK {
Connect_port 80
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 4
}
}
Real_server 192.168.13.47 80 {
Weight 1
TCP_CHECK {
Connect_port 80
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 4
}
}
}

Modprobe ip_vs
Lsmod | grep ip_vs
Echo "modprobe ip_vs">/etc/rc. local
/Etc/init. d/keepalived restart
Chkconfig ipvsadm off
Ip addr show dev eth0
###### Set the firewall and selinux here for testing )#########
Iptables-F
Setenforce 0

3. Configure the DR working mode of the Web node server and make the following settings on the node server respectively)
Cd/etc/sysconfig/network-script/
Cp ifcfg-lo: 0
Vi ifcfg-lo: 0
DEVICE = lo: 0
IPADDR = 192.168.13.100
NETMASK = 255.255.255.255.255
ONBOOT = yes

Echo "route add-host 192.168.13.100 dev lo: 0">/etc/rc. local
Route add-host 192.168.13.100 dev lo: 0
Ip addr show dev lo

Vi/etc/sysctl. conf
Net. ipv4.conf. all. arp_ignore = 1
Net. ipv4.conf. all. arp_announce = 2
Net. ipv4.conf. default. arp_ignore = 1
Net. ipv4.conf. default. arp_announce = 2
Net. ipv4.conf. lo. arp_ignore = 1
Net. ipv4.conf. lo. arp_announce = 2

Sysctl-p
Yum install-y httpd
Vi/var/www/html/index.html
Test page !!!!

/Etc/init. d/httpd start
Chkconfig httpd on
Iptables-F
Setenforce 0

4. Test the high-availability cluster of lvs + Keepalived
When the client browser accesses 192.168.13.100, the scheduling server may be broken down, and at least one node server must be good.
Use the/var/log/message log File to track the Failover process. Use ipvsadm-Ln to view LVS.

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.