软件开发: 10 2009存档
主要参考:http://www.clusting.com/cluster/load_balancing/LVS_1.html
但我的配置和他稍有不同,所以班门弄斧,补充修订一下:
一台load balancer机器:10.254.2.251,三台real server机器:10.254.2.[252-254]
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.eth0.send_redirects = 1
然后执行下面的命令是对内核修改的参数立即生效:
sysctl -p
配置VIP地址:
sudo ifconfig eth0:0 10.254.2.201 broadcast 10.254.2.201 netmask 255.255.255.255 up
(注:我的load balancer实际ip是251,但如果直接用真实地址,走不通,于是我特意分配了新ip地址 10.254.2.201,broadcast必须和这个设成一样,netmask也必须是全255)
sudo route add -host 10.254.2.201 dev eth0:0
清除ipvsadm表:
sudo ipvsadm -C
使用ipvsadm安装LVS服务:
sudo ipvsadm -A -t 10.254.2.201:8080 -s rr (注:8080是我web服务的端口)
增加realserver:
#forward http to realserver using direct routing with weight 1
sudo ipvsadm -a -t 10.254.2.201:8080 -r 10.254.2.202:8080 -g -w 1
sudo ipvsadm -a -t 10.254.2.201:8080 -r 10.254.2.203:8080 -g -w 1
sudo ipvsadm -a -t 10.254.2.201:8080 -r 10.254.2.204:8080 -g -w 1
(2) 在real server上的配置主要是参考上文,只有一处不一样,就是配置虚ip地址:
sudo ifconfig lo:0 10.254.2.201 broadcast 10.254.2.201 netmask 255.255.255.255 up
sudo route add -host 10.254.2.201 dev lo:0
但我的配置和他稍有不同,所以班门弄斧,补充修订一下:
一台load balancer机器:10.254.2.251,三台real server机器:10.254.2.[252-254]
(1) 在load balancer上:
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.eth0.send_redirects = 1
然后执行下面的命令是对内核修改的参数立即生效:
sysctl -p
配置VIP地址:
sudo ifconfig eth0:0 10.254.2.201 broadcast 10.254.2.201 netmask 255.255.255.255 up
(注:我的load balancer实际ip是251,但如果直接用真实地址,走不通,于是我特意分配了新ip地址 10.254.2.201,broadcast必须和这个设成一样,netmask也必须是全255)
sudo route add -host 10.254.2.201 dev eth0:0
清除ipvsadm表:
sudo ipvsadm -C
使用ipvsadm安装LVS服务:
sudo ipvsadm -A -t 10.254.2.201:8080 -s rr (注:8080是我web服务的端口)
增加realserver:
#forward http to realserver using direct routing with weight 1
sudo ipvsadm -a -t 10.254.2.201:8080 -r 10.254.2.202:8080 -g -w 1
sudo ipvsadm -a -t 10.254.2.201:8080 -r 10.254.2.203:8080 -g -w 1
sudo ipvsadm -a -t 10.254.2.201:8080 -r 10.254.2.204:8080 -g -w 1
(2) 在real server上的配置主要是参考上文,只有一处不一样,就是配置虚ip地址:
sudo ifconfig lo:0 10.254.2.201 broadcast 10.254.2.201 netmask 255.255.255.255 up
sudo route add -host 10.254.2.201 dev lo:0