负载均衡

 

 2台服务器做负载均衡需要3ip .  一个vip: 192.168.0.4  2个真实ip: 192.168.0.2

,192.168.0.3

具体操作步距:

 

1.       安装ipvsadm    yum install ipvsadm

 

 2. 服务器端 修改配置文件  /etc/sysctl.conf

   

     加入:net.ipv4.ip_forward = 1

           net.ipv4.conf.all.send_redirects = 1

           net.ipv4.conf.default.send_redirects = 1

           net.ipv4.conf.eth0.send_redirects = 1

         net.ipv4.conf.lo.arp_ignore=1

net.ipv4.conf.lo.arp_announce = 2

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

 

然后下 sysctl -p

 

   客户机端修改配置文件  /etc/sysctl.conf

 

          net.ipv4.ip_forward = 1

         net.ipv4.conf.lo.arp_ignore=1

net.ipv4.conf.lo.arp_announce = 2

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

 

然后下 sysctl -p

 

3.服务器端配置网卡

  

  Eth0  192.168.0.2

  ifconfig eth0:0 192.168.0.4 broadcast 192.168.0.4 netmask 255.255.255.255 up

route add -host 192.168.0.4 dev eth0:0

  客户端配置网卡

 

  Eth0  192.168.0.3

  ifconfig lo:0 192.168.0.4 broadcast 192.168.0.4 netmask 255.255.255.255 up

route add -host 192.168.0.4 dev lo:0

 

 

4.配置lvs

 

 ipvsadm -A -t 192.168.0.4:25 -s rr

 ipvsadm -a -t 192.168.0.4:25 -r 192.168.0.2:25 -g -w 1

 ipvsadm -a -t 192.168.0.4:25 -r 192.168.0.3:25 -g -w 1