HTTP Load Balancing through LVS

Source: Internet
Author: User

HTTP Load Balancing through LVS


1. Summary

This article does not consider dual-host mutual backup. Http load balancing is achieved through scripts and LVS, and clusters are used in the actual production environment.


2. Installation

1) Prepare the Software Package

Ipvsadm-1.26.tar.gz

Httpd-2.2.23.tar.gz


2) Configure Director Server

A. Check whether the kernel supports the ipvs module of LVS.

# Modprobe-L | grep ipvs

Kernel/NET/Netfilter/S/ip_vs.ko

Kernel/NET/Netfilter/ipvs/ip_vs_rr.ko

Kernel/NET/Netfilter/ipvs/ip_vs_wrr.ko

Kernel/NET/Netfilter/ipvs/ip_vs_lc.ko

Kernel/NET/Netfilter/ipvs/ip_vs_wlc.ko

Kernel/NET/Netfilter/ipvs/ip_vs_lblc.ko

Kernel/NET/Netfilter/ipvs/ip_vs_lblcr.ko

Kernel/NET/Netfilter/ipvs/ip_vs_dh.ko

Kernel/NET/Netfilter/ipvs/ip_vs_sh.ko

Kernel/NET/Netfilter/ipvs/ip_vs_sed.ko

Kernel/NET/Netfilter/S/ip_vs_nq.ko

Kernel/NET/Netfilter/S/ip_vs_ftp.ko

Kernel/NET/Netfilter/ipvs/ip_vs_pe_sip.ko


B. Install LVS on Director Server

# Ln-S/usr/src/kernels/2.6.32-431. el6.x86 _ 64 // usr/src/Linux # kernel cannot be found for ipvsadm

# Yum install-y libnl *

# Yum install-y popt *

# Rpm-IVH popt-static-1.13-7.el6.x86_64.rpm # The first three steps are to resolve the software package for installing ipvsadm-1.26 errors

# Tar zxvf ipvsadm-1.26.tar.gz

# Cd ipvsadm-1.26

# Make

# Make install

# Ipvsadm -- help # The ipvsadm help prompt indicates that ipvsadm has been installed successfully.


C. LVS start/stop scripts

Vim/etc/init. d/lvsdr

#! /Bin/sh

# Description: Start LVS of Director Server

VIP = 10.0.2.200

Rip1 = 10.0.2.203

Rip2 = 10.0.2.204

Chmod 755/etc/rc. d/init. d/functions

/Etc/rc. d/init. d/functions

Case "$1" in

Start)

Echo "Start LVS of Director server"

# Set the virtual IP address and sysctl Parameter

/Sbin/ifconfig eth0: 0 $ VIP broadcast $ VIP netmask 255.255.255.255 up

/Sbin/route add-host $ VIP Dev eth0: 0

Echo "1">/proc/sys/NET/IPv4/ip_forward

# Clear ipvs table

/Sbin/ipvsadm-C

# 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

# Run LVS

/Sbin/ipvsadm

;;

Stop)

Echo "Close LVS directorserver"

Echo "0">/proc/sys/NET/IPv4/ip_forward

/Sbin/ipvsadm-C

/Sbin/route del-host $ VIP Dev eth0: 0

/Sbin/ifconfig eth0: 0 down

;;

*)

Echo "Usage: $0 {START | stop }"

Exit 1

Esac

# Chmod 755/etc/init. d/lvsdr

#/Etc/init. d/lvsdr start

# Service ipvsadm save # Save the LVS record to/etc/sysconfig/ipvsadm

# Service ipvsadm start


3) configure the Real Server

A. Install the HTTP service

# Tar-zxvf httpd-2.2.23.tar.gz

# Cd httpd-2.2.23

#./Configure -- prefix =/usr/local/Apache

# Make & make install


B. Configure httpd

# Cp/usr/local/Apache/bin/apachectl/etc/init. d/httpd

# Vim/etc/init. d/httpd

Modify the file, in the file '#! Add the following two rules after/bin/Sh:

#! /Bin/sh

#

# Chkconfig: 2345 85 15

# Description: Apache is a World Wide Web Server

#

# Chkconfig -- add httpd

# Chkconfig -- list httpd

# Service httpd start


C. Configure VIP and ARP

# Vim/etc/init. d/lvsrs

#! /Bin/bash

# Description: Start Real Server

VIP = 10.0.2.200

/Etc/rc. d/init. d/functions

Case "$1" in

Start)

Echo "Start LVS of Real Server"

/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/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

Sysctl-P

;;

Stop)

/Sbin/ifconfig lo: 0 down

/Sbin/route del-host $ VIP Dev lo: 0

Echo "Close LVS Director server"

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

# Chmod 755/etc/init. d/lvsrs

#/Etc/init. d/lvsrs start


This article is from the "kimileonis" blog, please be sure to keep this source http://kimileonis.blog.51cto.com/5531747/1538839

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.