Linux load balancer software lvs-Direct use of LVS

Source: Internet
Author: User

4. Installation Configuration LVS4.1 Preparation work

Address planning:

Server name

IP Address

Gateway

Virtual device Name

Virtual IP

Director Server

192.168.98.75

192.168.98.1

eth0:0

192.168.98.77

Real Server 1

192.168.98.74

192.168.98.1

lo:0

192.168.98.77

Real Server 2

192.168.98.117

192.168.98.1

lo:0

192.168.98.77

Real Server N

...

...

..

..

4.2 Installing the LVS

The implementation of the LVS is done by ipvsadm this program, so to determine whether a system has Ipvs function, only need to see if the IPVSADM program is installed. The simplest way to view the IPVSADM program is to execute command ipvsadm on any path. The following table compares the output of the installation Ipvsadm and the Ipvsadm that are not installed.

Output after execution of Ipvsadm

Ipvsadm not installed

-bash:ipvsadm:command not Foun

Installing Ipvsadm

IP Virtual Server version 1.2.1 (size=4096)

Prot Localaddress:port Scheduler Flags

->remoteaddress:port Forward Weight activeconn inactconn

* all director servers need to install Ipvsadm,real server only to execute the configuration script.

1. Create a connection file whose command is:

[Email protected] ~]# ln–sv/usr/src/kernels/2.6.18-308.el5-x86_64//usr/src/linux

Note Be sure to conform to the current running kernel because there are multiple directories under the/usr/src/kernels directory. If you do not create this connection file, errors will occur at compile time, so you cannot proceed with the installation.

2. Unzip the ipvsadm-1.24.tar.gz package:

[Email protected] ~]# tar zxvf ipvsadm-1.24.tar.gz

3. Compiling the installation

[Email protected] ~]# CD ipvsadm-1.24

[[email protected] ~]# make

[[email protected] ~]# make install

Executable files are installed to/sbin/ipvsadm

L Check if the installation Ipvsadm is properly installed

1. Execute ipvsadm, output as shown in the bottom three of the second column of the table above.

2. Check the currently loaded kernel module to see if the Ip_vs module exists.

[Email protected] ~]# Lsmod|grep Ip_vs

Ip_vs 122112 0

4.3 Configurationand verifying the director Server4.3.1 Configuring the Director Server

#!/bin/bash

vip=192.168.98.77 #虚拟ip (IP for user access)

rip1=192.168.98.74 # Real server IP

rip2=192.168.98.117 #真实服务器 (real server) IP

port=2200 #端口

Case "$" in

Start)

echo "start config LVS Director Server ..."

ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 Up

Route add-host $VIP Dev eth0:0

echo "1" >/proc/sys/net/ipv4/ip_forward

Ipvsadm-c

Ipvsadm-a-T $VIP: $PORT-S RR +

Ipvsadm-a-T $VIP: $PORT-R $RIP 1: $PORT –g #添加real Server, multiple configurable multiple

Ipvsadm- A-t $VIP: $PORT-R $RIP 2: $PORT –g #添加real Server, multiple configurable multiple

Ipvsadm

echo "config LVS Director server success!"

;;

Stop)

echo "Shut down LVS Director Server"

Echo "0" >/proc/sys/net/ipv4/ip_forward

Ipvsadm-c

Ifconfig eth0:0 down

Echo shut down LVS Director Server success!

;;

*)

Echo "usage:$0 {start|stop}"

Exit 1

Esac

Execute:./lvsdr.sh Start Open

Execute:./lvsdr.sh Stop off

* Modify permissions before executing: chmod 755 lvsdr.sh

4.3.2 Verifying the Director server configuration

[Email protected] lvs]# Ipvsadm

IP Virtual Server version 1.2.1 (size=4096)

Prot Localaddress:port Scheduler Flags

Remoteaddress:port Forward Weight activeconn inactconn

TCP 192.168.98.77:2200 WLC

-192.168.98.117:2200 Route 1 0 0

-192.168.98.74:2200 Route 1 0 0

The output of the above information is configured successfully.

4.3.3 Configuring Ipvsadm as a boot startup script

LvsDR_auto.sh:Director Server Configuration Script

Where Vip,rip1,rip2,port should be modified according to actual needs

#!/bin/bash

vip=192.168.98.77 #虚拟ip (IP for user access)

rip1=192.168.98.74 #Real Server IP

rip2=192.168.98.117 #Real Server IP

port=2200 #端口

echo "start config LVS Director Server ..."

Ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up

Route add-host $VIP Dev eth0:0

echo "1" >/proc/sys/net/ipv4/ip_forward

Ipvsadm-c

Ipvsadm-a-T $VIP: $PORT-S WLC

Ipvsadm-a-T $VIP: $PORT-R $RIP 1: $PORT-G

Ipvsadm-a-T $VIP: $PORT-R $RIP 2: $PORT-G

Ipvsadm

echo "config LVS Director Server success!"

Exit 1

LvsRS_auto.sh:Real Server Configuration Script

Where the VIP should be the same as the VIP configured by the Director server

#!/bin/bash

vip=192.168.98.77 #虚拟ip (IP for user access)

echo "start config LVs Real Server ..."

Ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

Route add-host $VIP Dev lo:0

echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

echo "config LVs Real Server success!"

Exit 1

First the script file is placed on the server and you need to add Execute permissions:

[Email protected] ~]# chmod 755 lvsdr_auto.sh

[Email protected] ~]# chmod 755 lvsrs_auto.sh

Director Server :

[email protected] ~]# CP lvsdr_auto.sh/etc/init.d/

[Email protected] ~]# ln-s/etc/init.d/lvsdr_auto.sh/etc/rc.d/rc3.d/s99lvsdr_auto

[Email protected] ~]# ln-s/etc/init.d/lvsdr_auto.sh/etc/rc.d/rc5.d/s99lvsdr_auto

Real Server :

[email protected] ~]# CP lvsrs_auto.sh/etc/init.d/

[Email protected] ~]# ln-s/etc/init.d/lvsrs_auto.sh/etc/rc.d/rc3.d/s99lvsrs_auto

[Email protected] ~]# ln-s/etc/init.d/lvsrs_auto.sh/etc/rc.d/rc5.d/s99lvsrs_auto

4.4 Configuring and verifying real Server4.4.1 configuration real Server

#!/bin/bash

vip=192.168.98.77 #虚拟ip (IP for user access)

Case "$" in

Start

echo "start config LVs Real Server ..."

Ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

Route add-host $VIP Dev lo:0

echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

echo "config LVs Real Server success!"

;;

Stop

echo "Shutting down LVS Real server ..."

Ifconfig lo:0 Down

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce

echo "Shut down LVS Real server success!"

;;

*)

echo "usage:$0 {start|stop}"

Exit 1

Esac

Execute:./lvsrs.sh Start Open

Execute:./lvsrs.sh Stop off

* Modify permissions before executing: chmod 755 lvsrs.sh

4.4.2 VerificationRESL Server Configuration

[[Email protected] ~]# IP add

1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 Qdisc noqueue

Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00

inet 127.0.0.1/8 Scope host Lo

inet 192.168.98.77/32 BRD 192.168.98.77 Scope Global lo:0

INET6:: 1/128 Scope Host

Valid_lft Forever Preferred_lft Forever

2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast Qlen 1000

Link/ether 00:50:56:91:14:81 BRD FF:FF:FF:FF:FF:FF

inet 192.168.98.118/24 BRD 192.168.98.255 Scope Global eth0

Inet6 FE80::250:56FF:FE91:1481/64 Scope link

Valid_lft Forever Preferred_lft Forever

3:sit0: <NOARP> MTU 1480 Qdisc NoOp

Link/sit 0.0.0.0 BRD 0.0.0.0

As can be seen from the output, lo0:0 The VIP address we specified is indeed bound.

Filed under: http://www.cnblogs.com/llhua/p/4195337.html

Linux load balancer software lvs-Direct use of LVS

Related Article

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.