lvs dr模式安裝
環境:centos5.5 註:測試環境均為centos5.5,在虛擬機器上虛擬三個centos系統)
vip 192.168.3.169
lb真是ip192.168.3.168
server1 ip:192.168.10.2
server1 ip:192.168.10.3
rpm包安裝ipvsadmin
I lb上邊配置
1 複製網卡ifcfg-eth0:1
DEVICE=eth0:1
BOOTPROTO=none
IPADDR=192.168.3.169
NETMASK=255.255.0.0
ONBOOT=yes
2 開啟路由轉寄功能 vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
3添加指令碼
#!/bin/sh
ipvsadm -C
ipvsadm -A -t 192.168.3.169:80 -s wlc
ipvsadm -a -t 192.168.3.169:80 -r 192.168.10.2 -g
ipvsadm -a -t 192.168.3.169:80 -r 192.168.10.3 -g
II server上邊配置
1 cp換回介面 ifcfg-lo:1
DEVICE=lo:1
IPADDR=192.168.3.169
NETMASK=255.255.255.255
NETWORK=192.168.3.169
ONBOOT=yes
ARP=no
2開啟路由轉寄 vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
添加
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
使用sysctl -p 儲存
兩台伺服器同樣的配置
III 在lb上啟動ipvsadm
service ipvsadm start
Clearing the current IPVS table: [確定]
Applying IPVS configuration: /etc/init.d/ipvsadm: line 62: /etc/sysconfig/ipvsadm: 沒有那個檔案或目錄
[失敗]
出現這樣的錯誤service ipvsadm save 然後再重啟
運行剛才的指令碼
查看狀態
ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.3.169:80 wlc
-> 192.168.10.3:80 Route 1 0 28
-> 192.168.10.2:80 Route 1 0 27