A detailed analysis of the CentOS of LVs Dr

Source: Internet
Author: User
Tags centos

About LVs DR (Direct Root) mode

DR mode requires Director and realserver on the same network segment, the user through the VIP to access our services, Director received the user's request, will be the request of the target Mac to one of the realserver above, So realserver receive the request processing directly after the content returned to the user, no longer walk directorserver.

Machine Preparation

directserver:192.168.1.200
realserver1:192.168.1.202
realserver2:192.168.1.203
vip:192.168.1.200

Two realserver above all configured static IP, set up a LNMP, how to configure static IP and structure and the focus of this article does not have much relationship, for the moment press not table.

Installation LVs

The code is as follows Copy Code

wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
TAR-ZXVF ipvsadm-1.24.tar.gz
CD ipvsadm-1.24
Ln-s/usr/src/kernels/2.6.32-431.11.2.el6.x86_64//usr/src/linux #一定一定要加这么个软链, otherwise the Linux kernel will not be able to find the error when compiling
Make

Make install
After the installation is complete, knock the command Ipvsadm

Description of the installation was successful and properly
Configure Director
Create a file/etc/init.d/lvsdr and give execution permissions:

The code is as follows Copy Code
#!/bin/sh
&NBSP
vip=192.168.1.201
rip1=192.168.1.203
rip2=192.168.1.202
./etc/rc.d/init.d/functions
Case "$" in
Start)
  echo "Start lvs  of Directorserver"
  # Set the virtual  IP address
   ifconfig eth3:0 $VIP/24
   #/sbin/route add-host $VIP Dev eth3:0
   #Clear Ipvs Table
  /sbin/ipvsadm-c
  #set LVS
 /sbin/ipvsadm-a-T $VIP: 80-s RR # (if session is required to stay Tim Plus-P defaults to remain 300 seconds)
 /sbin/ipvsadm-a-T $VIP: 80-r $RIP 1:80-g
 /sbin/ipvsadm-a-T $VIP: 80-r $RIP 2:80-g< br>   #/sbin/ipvsadm-a-T $VIP: 80-r $RIP 3:80–g
  #Run LVS
 /sbin/ipvsadm
  #end
;;
Stop)
 echo "Close LVS directorserver"
/sbin/ipvsadm-c
;;
*)
Echo "Usage: $ {start|stop}"
Exit 1
Esac


Execution:/ETC/INIT.D/LVSDR start

And then ifconfig look at the eth3. Two ip:192.168.1.200 and 192.168.1.201 have been tied up.

Configure Realserver
Create new file/etc/init.d/realserver and give execution permissions

The code is as follows Copy Code
#!/bin/sh
vip=192.168.1.201

. /etc/rc.d/init.d/functions
Case "$" in
Start
echo "Start LVS of Realserver"
Echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
Echo 2 >/proc/sys/net/ipv4/conf/eth2/arp_announce
Echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
Echo 1 >/proc/sys/net/ipv4/conf/eth2/arp_ignore
Service Network restart
Ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
Route add-host $VIP Dev lo:0

#end
;;
Stop
echo "Close LVS realserver"
Service Network restart
;;
*)
echo "Usage: $ {start|stop}"
Exit 1
Esac
/etc/init.d/realserver

Start, ifconfig look at Lo's network card has been the virtual IP to tie up!

Test

Place different content on each realserver, then access via VIP: http://192.168.1.201

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.