Load Balancing with LVS (DR) and ldirectord in CentOS

Source: Internet
Author: User

LVS (DR) + ldirectord for Load Balancing
Waynewu 2009-10-28
MSN: waynewush@yahoo.com.cn Email: waynewush@gmail.com
I. Environment Introduction
Test the apache load balancing on two machines. A total of three machines are used.
Dispatcher: 192.168.1.238
Vip1: 192.168.1.230
Realip: 192.168.1.235
Readip: 192.168.1.236
System: RHEL 5.3
Ii. installation and configuration process
1. install and configure the scheduling machine lvs
1. The LVS installation software has been included in the RHEL5 disc and can be found directly in the Cluster of the disc.
# Rpm-ivh ipvsadm-1.24-8.1.i386.rpm
2. Check whether the lvs module has been loaded.
Lsmod | grep ip_vs
Ip_vs 77313 0
If the preceding description is successfully loaded
3. Configure lvs and edit the script lvsdr. sh.
[Root @ ddmap ~] # Cat lvsdr. sh
#! /Bin/bash
RIP1 = 192.168.1.235
RIP2 = 192.168.1.236
VIP1 = 192.168.1.230
/Sbin/ifconfig eth0: 0 $ VIP1 broadcast $ VIP1 netmask 255.255.255.255 up
/Sbin/route add-host $ VIP1 dev eth0: 0
Echo "1">/proc/sys/net/ipv4/ip_forward
/Sbin/ipvsadm-C
# Set LVS apache
/Sbin/ipvsadm-A-t $ VIP1: 80-s rr
/Sbin/ipvsadm-a-t $ VIP1: 80-r $ RIP1: 80-g
/Sbin/ipvsadm-a-t $ VIP1: 80-r $ RIP2: 80-g
4. Execute the script. The scheduler rule such as sh lvsdr. sh has been enabled and can be viewed using ipvsadmin-l.
[Root @ ddmap ~] # Ipvsadm-l
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddress: Port sched1_flags
-> RemoteAddress: Port Forward Weight ActiveConn InActConn
TCP 192.168.1.230: http rr
-> 192.168.1.236: http Route 1 0 0
-> 192.168.1.235: http Route 1 0 0
5. You can save the ipvs rule to/etc/sysconfig/ipvsadm. You can use server ipvsadm to start
Ipvsadm-save>/etc/sysconfig/ipvsadm
2. install and configure ldirectord. The above LVS is only responsible for distribution, but not for health check. Therefore, when the next machine crashes, it is possible to continue to allocate requests, ldirectord can be used to automatically remove the suspended machine.
Ldirectord is a part of heartbeat. When we install heartbeat, it carries ldirectord.
1. Configure an available source for ldirectord and heartbeat installation.
[Root @ ddmap ~] # Cat/etc/yum. repos. d/ha-clustering.repo
Server_ha-clustering
Name = High Availability/Clustering server technologies (CentOS_5)
# Type = rpm-md
Base url = http://download.opensuse.org/repositories/server:/ha-clustering/CentOS_5/
Gpgcheck = 1
Gpgkey = http://download.opensuse.org/repositories/server:/ha-clustering/CentOS_5/repodata/repomd.xml.key
Enabled = 1
2. Install ldirectord
# Yum install ldirectord
3. Configure ldirectord
# Cp/usr/share/doc/ldirectord-1.0/ldirectord. cf/etc/ha. d /.
# Vim/etc/ha. d/ldirectord. cf
# Global ctictives
Checktimeout = 3
Checkinterval = 1
# Fallback = 127.0.0.1: 80
Autoreload = yes
Logfile = "/var/log/ldirectord. log"
# Logfile = "local0"
# Emailalert = "admin@x.y.z"
# Emailalertfreq= 3600
# Emailalertstatus = all
Quiescent = no
# Sample for an http virtual service
Virtual = 192.168.1.230: 80
Real = 192.168.1.235: 80 gate
Real = 192.168.1.236: 80 gate
Fallback = 127.0.0.1: 80 gate
Service = http
Scheduler = rr
# Persistent = 600
# Netmask = 255.255.255.255.255
Protocol = tcp
Checktype = negotiate
Checkport = 80
Request = "index.html"
# Receive = "Test Page"
# Virtualhost = www. x. y. z
4. Start ldirectord
Service ldirectord start
3. Configure the second realserver 235/236

1. Create an execution script lvsrl. sh
#! /Bin/bash
VIP1 = 192.168.1.230
/Sbin/ifconfig lo: 0 $ VIP1 broadcast $ VIP1 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
2. Execute lvsrl. sh on two machines respectively.
Test and verification
1. The next two real servers start apache respectively, and write some tags in index. heml for recognition.
2. Enter http: // 192.168.1.230 in the browser and press F5 to check whether the page is changed. The polling method we selected above is rr.
3. Do not enable ldirectord first. The next machine will disable http or restart. Simulate the host and check whether it will be allocated to the mounted machine when pressing F5.
4. Enable ldirectord first, and the next machine simulates the current machine. At this time, it should not be allocated to the current machine.
4. Some articles on the network for reference and reference

  • Http://blog.163.com/herod_xiao/blog/static/87188399200991635444342/

  • Http://sery.blog.51cto.com/10037/54645

  • Http://zh.linuxvirtualserver.org/book/export/html/95

  • Ldirectord parameter description: http://blog.freebug.org/archives/337.html

  • Ipvsadm command details: http://zh.linuxvirtualserver.org/node/5


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.