Use ipvsadm + ldirectord in CentOS to implement high-availability clusters

Source: Internet
Author: User

There are four servers: 192.168.0.34, 192.168.0.35, 192.168.0.36, and 192.168.0.37.
192.168.0.37 is an e-mail service running on nas, 35, and 36.
A scheduler was created on port 37 to allocate services with ports 80, 25, and 110 to ports, 35, and 36.

Specific Configuration:
On server 37, an rpm package of ipvsadm is installed first.
Yum install ipvsadm # obtains the ipvsadm software, which is responsible for load balancing and requests to backend services.
And then the tutorial
Reference written by others. The direct routing mode is used.
#! /Bin/bash
VIP = 192.168.0.38
RIP1 = 192.168.0.34
RIP2 = 192.168.0.35
RIP3 = 192.168.0.36
GW = 192.168.0.33
# Clear IPVS table
/Sbin/ipvsadm-C
/Sbin/ifconfig eth0: 0 $ VIP broadcast $ VIP netmask 255.255.255.255 up
/Sbin/route add-host $ VIP dev eth0: 0
# Set LVS
/Sbin/ipvsadm-A-t $ VIP: 80-s rr
/Sbin/ipvsadm-a-t $ VIP: 80-r $ RIP1: 80-g
/Sbin/ipvsadm-a-t $ VIP: 80-r $ RIP2: 80-g
/Sbin/ipvsadm-a-t $ VIP: 80-r $ RIP3: 80-g
/Sbin/ipvsadm-A-t $ VIP: 25-s rr
/Sbin/ipvsadm-a-t $ VIP: 25-r $ RIP1: 25-g
/Sbin/ipvsadm-a-t $ VIP: 25-r $ RIP2: 25-g
/Sbin/ipvsadm-a-t $ VIP: 25-r $ RIP3: 25-g
/Sbin/ipvsadm-A-t $ VIP: 110-s rr
/Sbin/ipvsadm-a-t $ VIP: 110-r $ RIP1: 110-g
/Sbin/ipvsadm-a-t $ VIP: 110-r $ RIP2: 110-g
/Sbin/ipvsadm-a-t $ VIP: 110-r $ RIP3: 110-g
# Run LVS
/Sbin/ipvsadm
# End
The content is 192.168.0.38, which is the virtual address 192.168.0.34, 35, 36 is the real server. Load ports 80, 25, and 110.
34,35, 36 respectively/home/test. sh tutorial
#! /Bin/bash
VIP = 192.168.0.38
/Sbin/ifconfig lo: 0 $ VIP broadcast $ VIP netmask 255.255.255.255 up
/Sbin/route add-host $ VIP dev lo: 0
Echo 1>/proc/sys/net/ipv4/conf/all/arp_filter
Echo 1>/proc/sys/net/ipv4/conf/lo/arp_filter
Sysctl-p
# End
This script is used to filter arp packets, or edit/etc/sysctl. conf to modify system variables.
Net. ipv4.conf. lo. arp_ignore = 1
Net. ipv4.conf. lo. arp_announce = 2
Net. ipv4.ip _ forward = 1
Sysctl-p # configuration takes effect

Http://www.vergenet.net/linux/ldirectord/
Downloading lddirectord is a monitoring software.

You can download it in the following way 07 years ago and it is no longer valid.
{Cvs-d: pserver: guest@cvs.linux-ha.org:/home/cvs/linux-ha login
Cvs-z3-d: pserver: guest@cvs.linux-ha.org:/home/cvs/linux-ha co linux-ha /}

Current (20090906) Available Link
Http://hg.linux-ha.org/lha-2.1/archive/STABLE-2.1.4.tar.bz2


Then a configuration file is written.
Ldirectord. cf
Checktimeout = 3
Checkinterval = 1
# Fck = 127.0.0.1: 80 allback = 127.0.0.1: 80
Autoreload = yes
# Logfile = "/var/log/ldirectord. log"
# Logfile = "local0"
Quiescent = yes
# A sample virual with a fallback that will override the gobal setting
Virtual = 192.168.0.38: 80
Real = 192.168.0.34: 80 gate
Real = 192.168.0.35: 80 gate
Real = 192.168.0.36: 80 gate
Fallback = 127.0.0.1: 80
Service = http
Request = "test.html"
Receive = "Test Page"
Virtualhost = www.shiming.gov.cn
Scheduler = rr
Perpersistent = 600
Netmask = 255.255.255.255.255
Protocol = tcp
Virtual = 192.168.0.38: 25
Real = 192.168.0.34: 25 gate
Real = 192.168.0.35: 25 gate
Real = 192.168.0.36: 25 gate
Fallback = 127.0.0.1: 25
Service = smtp
Scheduler = rr
Perpersistent = 600
Protocol = tcp
Virtual = 192.168.0.38: 110
Real = 192.168.0.34: 110 gate
Real = 192.168.0.35: 110 gate
Real = 192.168.0.36: 110 gate
Fallback = 127.0.0.1: 110
Service = pop
Scheduler = rr
Login = "testemail"
Passwd = "emailtest"
Perpersistent = 600
Protocol = tcp

This is the result of monitoring.
Ldirectord/etc/ldirectord. cf start
Ldirectord/etc/ldirectord. cf stop
Tail-f/var/log/ldirectord. log. This is log

Check whether the lvs service is normal
Watch ipvsadm-l-n

Every 2.0 s: ipvsadm-l-n Sun Sep 6 19:39:51 2009

IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddress: Port sched1_flags
-> RemoteAddress: Port Forward Weight ActiveConn InActConn
TCP 192.168.0.105: 80 rr
-> 192.168.0.104: 80 Route 1 0 0
-> 192.168.0.103: 80 Route 1 0 0
TCP 192.168.0.105: 3306 rr
-& Gt; 192.168.0.104: 3306 Route 1 0 0
-> 192.168.0.103: 3306 Route 1 0 0

Refer:
Http://bbs.chinaunix.net/viewthread.php? Tid = 1148139
Http://www.linuxvirtualserver.org/

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.