LVS use finishing (1)

Source: Internet
Author: User

Start installing LVS

1) Download the relevant software package

Mkdir-p/home/tools/
cd/home/tools/
wget http://www.linuxvirtualserver.org/software/kernel-26/ipadm-1.26.tar.gz

2) Installing the LVS command

Lsmod |grep Ip_vs
Cat/etc/redhat-release
Uname-r
Ln-s/usr/src/kernels/2.6.18-/usr/src/linux
Special attention:
1) The path of this ln command corresponds to the kernel version of the uname-r output result.
2) If there is no/usr/src/kernels/2.6, it is because the kernel-devel-2.6.18 package is missing. Can be installed via yum install kernel-devel-y.
3) ln This command can also not execute, directly specify kernel parameter compilation.

Tar zxvf ipvsadm-1.26.tar.gz
Make
Make install
Lsmod |grep Ip_vs
Tips:
1. At this point the Ipvs module is not loaded, you can execute the IPVSADM command will ip_vs load into the system kernel or execute commands modprobe Ip_vs can also load Ip_vs module into the kernel. Then perform the lsmod-l |grep Ip_vs should see the Ip_vs module listed.

Need to install a dependency package
Yum install libnl* popt*-y.

-----

Load Balancer Configuration

Configuring the alias Card

Ifconfig eth0:1 192.168.1.181 netmask 255.255.255.0 up #<= alias Way

④ manually perform configuration add LVS server and increase two RS

Ipvsadm-c
Ipvsadm--set 30 5 60
Ipvsadm-a-T 192.168.1.181:80-s wrr-p 20
Ipvsadm-a-T 192.168.1.181:80-r 192.168.1.178:80-g-W 1
Ipvsadm-a-T 192.168.1.181:80-r 192.168.1.179:80-g-W 1

[Delete method]

ipvsadm-d-T 192.168.1.181:80-s WRR
ipvsadm-d-T 192.168.1.181:80-r 192.168.1.178:80

[Related parameter description]

Ipvsadm-help
--clear-c Clear the whole table
--add-service-a add virtual service with options
--tcp-service-t service-address service-address is host[:p ort]
--scheduler-s Scheduler One of RR|WRR|LC|WLC|LBLC|LBLCR|DH|SH|SED|NQ
--add-server-a add real server with options
--real-server-r server-address server-addres S is host (and port)
--masquerading-m masquerading (NAT)
--gatewaying-g gatewaying (Direct routing) (default)
--delete-server-d Delete Real Server
--persistent-p [Timeout] Persistent server (session hold function)
--set TCP tcpfin UDP set connection timeout values
--weight-w weight capacity of real server
Hint: More parameters please ipvsadm-help self-view

⑤ command execution process and check configuration execution results

Ipvsadm-c
Ipvsadm--set 30 5 60
Ipvsadm-a-T 192.168.1.181:80-s wrr-p 20
Ipvsadm-a-T 192.168.1.181:80-r 192.168.1.178:80-g-W 1
Ipvsadm-a-T 192.168.1.181:80-r 192.168.1.179:80-g-W 1
Ipvsadm-l-N--sort
ipvsadm-d-T 192.168.1.181:80-r 192.168.1.178:80
Ipvsadm-l-N--sort
Ipvsadm-a-T 192.168.1.181:80-r 192.168.1.178:80
Ipvsadm-l-N--sort

Manually binding the VIP on the RS side

Ifconfig lo:181.168.1.181 netmask 255.255.255.255 up
Route add-host 192.168.1.181 Dev Lo

The VIP address is bound on the loopback interface (LO) device of each cluster node (its broadcast address is itself, Subnet mask 255.255.255.255, the use of a variable mask to divide the network segment into only one host address to avoid IP address conflicts) allows the cluster nodes in the LVS-DR cluster to receive packets sent to the VIP address, there is a very serious problem occurs, the real server inside the cluster will try to reply from the request Request the VIP client's ARP broadcast, so that all the real servers will claim that they own the VIP address, then the client will send the packet directly to the real server, thereby destroying the Dr cluster method. Therefore, you must suppress the ARP broadcast of the real server.

Manually suppressing ARP response at the RS end

The ⑦ suppresses ARP response in the following ways:

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

Take RS179 as an example to demonstrate the following procedure:

Ifconfig lo:181 192.168.1.181 netmask 255.255.255.255 up
Route add-host 192.168.1.181 Dev Lo
Cat/proc/sys/net/ipv4/conf/lo/arp_ignore
Cat/proc/sys/net/ipv4/conf/all/arp_ignore
Cat/proc/sys/net/ipv4/conf/all/arp_ignore
Cat/proc/sys/net/ipv4/conf/lo/arp_announce

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

ARP sound quality technical parameter description

Arp_ignore-integer

0 Default value:

Check manual configuration Results

Using http://192.168.1.178{179} (181)

Configuring the LVS Load balancer server side using scripts

#!/bin/bash

. /etc/init.d/functions
vip=192.168.1.181
Subnet=eth0: ' Echo $VIP |cut-d.-f4 '
Port=80
gw=192.168.1.1

#w =3
Rip1= (
192.168.1.178
)
#w =1
Rip2= (
192.168.1.179
)
Ifconfig=/sbin/ifconfig
Route=/sbin/route
Ipvsadm=/sbin/ipvsadm
Arping=/sbin/arping

#functions
function usage () {
Local Script_name
Script_name=$1
echo "Usgae: $script _name [Start | Stop | Restart] "
echo ""
Return 1
}

function Checkcmd () {
if [!-F $]; Then
echo "Can ' t find" $
Return 1
Fi
}

function Checksubnet () {
$IFCONFIG |grep "$" |wc-l
}

function Ipvsstart () {
#judge if $SUBNET is exist.
If [$ (checksubnet $SUBNET)-ne 0]; Then
$IFCONFIG $SUBNET Down
Fi
Local RS
# $IFCONFIG $SUBNET $VIP broadcast $VIP netmask 255.255.255.255 up
$IFCONFIG $SUBNET $VIP broadcast $VIP netmask 255.255.255.0 up
# $ROUTE add-host $VIP Dev $SUBNET
$IPVSADM-C
$IPVSADM-A-T $VIP: $PORT-S Wrr-p 60

for (i=0; i< ' echo ${#RIP1 [*]} '; i++)]
Do
$IPVSADM-A-t $VIP: $PORT-R ${rip1[$i]}: $PORT-G-W 1
Done

for (i=0; i< ' echo ${#RIP2 [*]} '; i++)]
Do
$IPVSADM-A-t $VIP: $PORT-R ${rip2[$i]}: $PORT-G-W 1
Done
Rs=$?
$IPVSADM >/tmp/oldboy.log

# Update MAC
netif=$ (Echo ${subnet}|awk-f ":" ' {print $} ')
$ARPING-C 1-i ${netif}-S $VIP $GW >>/tmp/oldboy.log
[$rs-eq 0] && action "ipvsadm start."/bin/true
Return $rs
}

function Ipvsstop () {
Local RS
Rs=1
#clean Ipvs
$IFCONFIG $SUBNET Down
$IPVSADM-C
$IPVSADM-Z

Rs=$?
# $ROUTE del $VIP
$ARPING-C 1-i ${netif}-S $VIP $GW >/dev/null 2>&1
[$rs-eq 0] && action "Ipvsadm stoped."/bin/true
Return $rs
}

Main ()
{
#judge argv num by Oldboy
If [$#-ne 1]; Then
Usage
Fi

Case "$" in
Start
Ipvsstart
;;
Stop
Ipvsstop
;;
Restart
Ipvsstop
Ipvsstart
;;
*)
Usage
;;
Esac
}

#start operating
Main $*

Development Script Configuration LVs RS Real Server processing script

#!/bin/bash
# Description:config Realserver lo and apply Noarp
Vip= (
192.168.1.181
)

. /etc/rc.d/init.d/functions

Case "$" in
Start
for (i=0; i< ' echo ${#VIP [*]} '; i++)]
Do
Interface= "Lo: ' echo ${vip[$i]}|awk-f. ' {print $4} ' '
/sbin/ifconfig $interface ${vip[$i]} broadcast ${vip[$i]} netmask 255.255.255.255 up
Done
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
Action "Start LVS of Rearserver.by Old1boy"
;;
Stop
for (i=0; i< ' echo ${#VIP [*]} '; i++)]
Do
Interface= "Lo: ' echo ${vip[$i]}|awk-f. ' {print $4} ' '
/sbin/ifconfig $interface ${vip[$i]} broadcast ${vip[$i]} netmask 255.255.255.255 down
Done
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
Action "Close LVS of Rearserver.by Old2boy"
;;
*)
echo "Usage: $ {start|stop}"
Exit 1
Esac

One script for automatic culling and adding RS

The Curl method is good.

#!/bin/bash

port= "80"
vip=192.168.1.181

Rip= (
192.168.1.178
192.168.1.179
)

function Check_url ()
{

for (i=0; i< ' echo ${#RIP [*]} '; i++)]
Do
Judge= ($ (curl-i-S http://${rip[$i]}|head-1|tr "\ r" "\ n"))
if [["${judge[1]}" = = ' && "${judge[2]}" = = ' OK ']
Then
If [' Ipvsadm-l-n|grep ' ${rip[$i]} "|wc-l '-ne 1]
Then
Ipvsadm-a-T $VIP: $PORT-R ${rip[$i]}: $PORT
Fi

Else
If [' Ipvsadm-l-n|grep ' ${rip[$i]} "|wc-l '-eq 1]
Then
Ipvsadm-d-T $VIP: $PORT-R ${rip[$i]}: $PORT
Fi
Fi
Done
}

While True
Do
Check_url
Sleep 5
Done

LVs Use Grooming (1)

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.