1. 程式人生 > >LVS叢集-DR模式(直接路由模式)

LVS叢集-DR模式(直接路由模式)

1. 給realserver繫結vip地址,並設定網路介面幫兄弟介面收發IP包,且忽略arp廣播包。

web30,web40 繫結虛擬IP地址192.168.4.60

[[email protected] ~]# ifconfig lo:1 192.168.4.60/32
[[email protected] ~]# ifconfig lo:1
lo:1: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.4.60  netmask 0.0.0.0
        loop  txqueuelen 0  (Local Loopback)

[[email protected] ~]# ifconfig lo:1 192.168.4.60/32
[[email protected] ~]# ifconfig lo:1
lo:1: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.4.60  netmask 0.0.0.0
        loop  txqueuelen 0  (Local Loopback)

設定arp引數
[

[email protected] ~]# ls /proc/sys/net/ipv4/conf/
all  default  eth0  eth1  eth2  eth3  lo  virbr0  virbr0-nic

[[email protected] ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[[email protected] ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[[email protected]

~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[[email protected] ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

[[email protected] ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[[email protected] ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[[email protected] ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[[email protected] ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

2.給分發器繫結vip地址

[[email protected] ~]# ifconfig eth0:1 192.168.4.60
[[email protected] ~]# ifconfig eth0:1 
eth0:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.4.60  netmask 255.255.255.0  broadcast 192.168.4.255
        ether 54:52:04:09:20:01  txqueuelen 1000  (Ethernet)

3.新增虛擬 服務

[[email protected] ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.4.60:80 wrr
4.新增realserver

[[email protected] ~]# ipvsadm -a -t 192.168.4.60:80 -r 192.168.4.30:80 -w 3 -g

[[email protected] ~]# ipvsadm -a -t 192.168.4.60:80 -r 192.168.4.40:80

[[email protected] ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.4.60:80 wrr
  -> 192.168.4.30:80              Route   3      0          0         
  -> 192.168.4.40:80              Route   1      0          0         
[[email protected] ~]# ipvsadm-save
-A -t 192.168.4.60:http -s wrr
-a -t 192.168.4.60:http -r 192.168.4.30:http -g -w 3
-a -t 192.168.4.60:http -r 192.168.4.40:http -g -w 1

5.測試

[[email protected] ~]# elinks --dump http://192.168.4.60/test.html
   web40
[[email protected] ~]# elinks --dump http://192.168.4.60/test.html
   web30
[[email protected] ~]# elinks --dump http://192.168.4.60/test.html
   web30
[[email protected] ~]# elinks --dump http://192.168.4.60/test.html
   web30
[[email protected] ~]# elinks --dump http://192.168.4.60/test.html
 

[[email protected] ~]# ipvsadm -Ln --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port               Conns   InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
TCP  192.168.4.60:80                     5       30        0     2375        0
  -> 192.168.4.30:80                     3       18        0     1425        0
  -> 192.168.4.40:80                     2       12        0      950        0