Lvs-dr achieve mode (rip dip on a network segment)

Lvs-dr achieve mode (rip dip on a network segment)

Network topology

mark

Operating on the client

Configuration Client ⽹ network address off point route 172

root@client:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.1.100    0.0.0.0         UG    0      0        0 eth0
172.16.0.0      0.0.0.0         255.255.248.0   U     0      0        0 eth0
root@client:~# 

Operating on the route

Open the route between routing and forwarding

root@route:~#  echo 1 > /proc/sys/net/ipv4/ip_forward

Operations on director

Perform script configuration VS

root@director:~# bash lvs_dr_vs.sh  start
The VS Server is Ready!

Script content

#!/bin/bash
vip='192.168.1.200'
iface='lo:1'
mask='255.255.255.255'
port='80'
rs1='192.168.1.103'
rs2='192.168.1.104'
scheduler='wrr' 
type='-g' 
dpkg-query -l ipvsadm &>/dev/null ||apt-get install ipvsadm &>/dev/null
case $1 in
start)
	ifconfig $iface $vip netmask $mask #broadcast $vip up 
	iptables -F
	ipvsadm -A -t ${vip}:${port} -s $scheduler
	ipvsadm -a -t ${vip}:${port} -r ${rs1} $type -w 1
	ipvsadm -a -t ${vip}:${port} -r ${rs2} $type -w 1
	echo "The VS Server is Ready!"
	;;
stop)    
	ipvsadm -C  
	ifconfig $iface down
	echo "The VS Server is Canceled!" 
	;;
*)
	echo "Usage: $(basename $0) start|stop"
	exit 1
	;; 
esac 

RS, respectively, on two points ⽹ off route of RIP2

root@rs1:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.102   0.0.0.0         UG    0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.248.0   U     0      0        0 eth0
root@rs2:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.102   0.0.0.0         UG    0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.248.0   U     0      0        0 eth0

On-rs

Execute scripts on rs

root@rs1:~# bash lvs_dr_rs.sh  start
The apache Server is Ready!
The RS Server is Ready!

Here is the script content

#!/bin/bash
vip=192.168.1.200
mask='255.255.255.255'
dev=lo:1
dpkg-query -l apache2 &> /dev/null|| apt-get -y install  apache2 >/dev/null  && echo "The apache Server is Ready!"
echo "<h1>`hostname`</h1>" > /var/www/html/index.html 
 
case $1 in
start)
	echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
	echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
	echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
	echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
	ifconfig $dev $vip netmask $mask #broadcast $vip up     #route add -host $vip dev $dev
	echo "The RS Server is Ready!"
	;; 
stop)
	ifconfig $dev down
	echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
	echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
	echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
	echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
	echo "The RS Server is Canceled!" 
	;;
*)     
	echo "Usage: $(basename $0) start|stop"    
	exit 1    
    ;; 
esac 
Published 62 original articles · won praise 7 · views 1249

Guess you like

Origin blog.csdn.net/qq_36801585/article/details/105031087