负载均衡----LVS

系统:Ubuntu11.0

 VS Server:
Eth0:192.168.8.135/255.255.255.0/192.168.8.255
Eth0:1:192.168.8.155/ 255.255.255.255 (VIP)
 
Real Server A:
Eth0:192.168.8.134/255.255.255.0/192.168.8.255
Lo:0:192.168.8.155/ 255.255.255.255 (VIP)
 
 
RealServer B:
Eth0:192.168.8.131/255.255.255.0/192.168.8.255
Lo:0:192.168.8.155/ 255.255.255.255 (VIP)

安装LVS

apt-get install ipvsadm

负载服务器:

#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward

echo "0" >/proc/sys/net/ipv4/conf/all/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/default/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/default/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/eth0/send_redirects
 
IPVSADM='/sbin/ipvsadm'
VIP=192.168.8.155
RS1=192.168.8.134
RS2=192.168.8.131
 
ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up
route add -host $VIP dev eth0:1
#route del -host $VIP dev eth0:1
 
$IPVSADM -C
$IPVSADM -A -t $VIP:8080 -s lc -p 600
$IPVSADM -a -t $VIP:8080 -r $RS1:8080 -g -w 1
$IPVSADM -a -t $VIP:8080 -r $RS2:8080 -g -w 1

RealServer,两台一样:

#!/bin/bash

echo 1 > /proc/sys/net/ipv4/ip_forward
VIP=192.168.8.155
 
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 "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


route add default gw $VIP

sysctl -p

相关推荐