First, the working principle of direct routing load balancing: the client accesses the director machine, and the director machine sends client requests to the Real Server, then, the real server directly responds to the response result of the request to the client. This method can reduce the pressure on director machine and improve efficiency. It is generally applicable to large and medium-sized enterprises. Lab environment: two host servers: 192.168.0.11 and 192.168.0.12 &
First, the working principle of direct routing load balancing: the client accesses the director machine, and the director machine sends client requests to the Real Server, then, the real server directly responds to the response result of the request to the client. This method can reduce the pressure on director machine and improve efficiency. It is generally applicable to large and medium-sized enterprises.
Lab environment: two host servers: 192.168.0.11 and 192.168.0.12
Medium transfer: 192.168.0.13 and 192.168.0.19
Client: 192.168.0.10
(The host name must be consistent with the IP address .)
Tutorial steps:
A. Server:
1. 192.168.0.11
# Yum install-y httpd
# Service httpd start
# Echo "192.168.0.11">/var/www/html/index.html
# Route add default gw 192.168.0.13
# Vim/bin/shutarp
-------------------------------
#! /Bin/bash
VIP = 192.168.0.19
/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
-------------------------------
# Shutarp
2. 192.168.0.12
# Yum install-y httpd
# Service httpd start
# Echo "192.168.0.12">/var/www/html/index.html
# Route add default gw 192.168.0.13
# Vim/bin/shutarp
-------------------------------
#! /Bin/bash
VIP = 192.168.0.19
/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
-------------------------------
# Shutarp
B. Intermediate transfer:
1. Install the ipvs service:
# Yum clean all
# Yum install-y ipvsadm
2. Enable ip Forwarding, disable other services, and set forwarding
# Vim/etc/init. d/lvsDR
---------------------------------
#/Bin/bash
VIP = 192.168.0.19
RIP1 = 192.168.0.11
RIP2 = 192.168.0.12
GW = 192.168.0.254
./Etc/rc. d/init. d/functions
Case "$1" in
Start)
Echo "start LVS of DS"
/Sbin/ifconfig eth0: 0 $ VIP broadcast $ VIP netmask 255.255.255.0 up
/Sbin/route add-host $ VIP dev eth0: 0
/Sbin/ipvsadm-C
/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
;;
Stop)
Echo "close LVS Directorserver"
/Sbin/ipvsadm-C
;;
*)
Echo "Usage: $0 {start | stop }"
Exit 1
Esac
---------------------------------
# Service lvsDR start (Execution script)
# Vim/bin/shutarp
-------------------------------
#! /Bin/bash
VIP = 192.168.0.19
/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
-------------------------------
# Shutarp
C. Client:
Open http: // 192.168.0.19/in the browser. Refresh the page again. If the page is displayed, the experiment is successful !)