#Linux LVS 负载均衡

1.环境

Director: 192.168.1.186

Web1: 192.168.1.161

Web2: 192.168.1.185

 

2.Director配置vip

[root@localhost ~]# ip add add 192.168.1.189/32 dev eth0

 

3.web1和web2配置

(1)配置系统参数(web1和web2都需要配置)

#!/bin/bash
case $1 in
        start)
                echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
                echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
                echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
                echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
;;
        stop)
                echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
                echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
                echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
                echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
;;
esac

(2)web1.web2配置vip (web1,和web2都需要配置)

[root@master ~]# ifconfig lo:0 192.168.1.189 netmask 255.255.255.255 up
[root@master
~]# route add 192.168.1.189 dev lo:0

 

4.Director配置ipvsadm

ipvsadm -A -t 192.168.1.189:80 -s rr                         #rr 轮询 round robin

ipvsadm
-a -t 192.168.1.189:80 -r 192.168.1.161:80 -g -w 1 #-w
权重 ,rr模式不需要加,当调度模式为 ipvsadm -A -t 192.168.1.189:80 -s wrr 加强权重模式的时候,
ipvsadm -a -t 192.168.1.189:80 -r 192.168.1.185:80 -g -w 2

 #其他命令

ipvsadm -C      #清除配置

 

 

5.测试rr模式的时候

Last login: Thu Oct 19 19:38:41 2017 from 192.168.1.140
root@ubuntu:~# curl http://192.168.1.189/1.html
161
root@ubuntu:~# curl http://192.168.1.189/1.html
185
root@ubuntu:~# curl http://192.168.1.189/1.html
161
root@ubuntu:~# curl http://192.168.1.189/1.html
185

#

 

posted @ 2017-10-26 17:21  陈奕迅-可以了  阅读(206)  评论(0编辑  收藏  举报