1. 程式人生 > >Lvs負載均衡(dr模式)

Lvs負載均衡(dr模式)


1.安裝Lvs  
安裝ipvsadm工具
yum -y install ipvsadm
 




2.先進行儲存再進行啟動
service ipvsadm save
service ipvsadm start
 


3.開啟路由轉發功能,並啟動生效。
vi  /etc/sysctl.conf
 


4.sysctl -P 報錯問題
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
sysctl -P 報錯解決辦法
參見http://www.cnblogs.com/wallis0922/archive/2013/05/23/3094062.html
問題症狀
修改 linux 核心檔案
#vi /etc/sysctl.conf後執行sysctl  -P 報錯
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
 
解決方法如下:
modprobe bridge
         或  lsmod|grep bridge


二.路由伺服器配置


ifconfig eth0:1 192.168.100.101  broadcast 192.168.100.101  netmask 255.255.255.255 up
route add -host 192.168.100.101 dev eth0:1
 


三.realserver配置


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 
cat  /proc/sys/net/ipv4/conf/lo/arp_announce 
cat  /proc/sys/net/ipv4/conf/lo/arp_ignore 


ifconfig lo:0 192.168.100.101  broadcast 192.168.100.101  netmask 255.255.255.255 up
route add -host 192.168.100.101 dev lo:0
ifconfig -a




7.建立測試頁面
cd /var/www/html/
echo "higay~112" > test.html
cat test.html
 


8.開啟httpd
Service httpd start
 




四、配置lvsserver

ipvsadm -A -t 192.168.100.101:80 -s wlc
ipvsadm -a -t 192.168.100.101:80 -g -r 192.168.100.111 -w 1
ipvsadm -a -t 192.168.100.101:80 -g -r 192.168.100.112 -w 2

 

 

ipvsadm -Ln
 


開啟ipvsadm

 


9.測試Lvs負載均衡