LVS配置脚本

 

1.NAT方式负载均衡

 

sudo bash

echo 1 > /proc/sys/net/ipv4/ip_forward

cat /proc/sys/net/ipv4/ip_forward

iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -d 0.0.0.0/0 -o eth0 -j MASQUERADE

ipvsadm -C

ipvsadm -A -t 192.168.137.11:8080 -s rr

ipvsadm -a -t 192.168.137.11:8080 -r 192.168.200.2:8080 -m

ipvsadm -a -t 192.168.137.11:8080 -r 192.168.200.3:8080 -m

ipvsadm -L -n

 

 

 

2.DR方式负载均衡

 

集群情况:

VIP:192.168.137.10

LB:192.168.137.11

RS1:192.168.137.12

RS2:192.168.137.13

RS3:192.168.137.14

RS4:192.168.137.14

RS5:192.168.137.16

 

LB上的脚本(lvs_lb.sh)

 

 

#!/bin/bash

#set ip_forward OFF for vs-dr director (1 on, 0 off)

 

ifconfig  eth0 192.168.137.11 netmask 255.255.255.0 broadcast 192.168.137.255 up

ifconfig  eth0:0 192.168.137.10 netmask 255.255.255.255 broadcast 192.168.137.10 up

 

echo 1 > /proc/sys/net/ipv4/ip_forward

 

ipvsadm -C

ipvsadm -A -t 192.168.137.10:8080 -s rr

ipvsadm -a -t 192.168.137.10:8080 -r 192.168.137.12:8080 -g

ipvsadm -a -t 192.168.137.10:8080 -r 192.168.137.13:8080 -g

ipvsadm -a -t 192.168.137.10:8080 -r 192.168.137.14:8080 -g

ipvsadm -a -t 192.168.137.10:8080 -r 192.168.137.15:8080 -g

ipvsadm -a -t 192.168.137.10:8080 -r 192.168.137.16:8080 -g

ipvsadm

RS1上的脚本(lvs_rs.sh)
#!/bin/bash
ifconfig eth1 192.168.137.12 broadcast 192.168.137.255 netmask 255.255.255.0 up
route add -net 192.168.137.0 netmask 255.255.255.0 dev eth1
ifconfig lo:0 192.168.137.10 broadcast 192.168.137.10 netmask 255.255.255.255 up
route add -host 192.168.137.10 dev lo:0
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce

 

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页