标签:_for 搭建 port ngx 网关 war ddr one sch
LVS DR模式负载均衡的搭建(单网段)实验需要五台虚拟机,都是centos7
客户端 | 路由器 | lvs服务器 |
---|---|---|
172.22.144.188 | 1接口172.22.144.17 2接口192.168.49.5 | 172.22.144.17 192.168.49.5 |
rs1服务器 | rs2服务器 |
---|---|
192.168.49.3 | 192.168.49.4 |
**客户端的配置**
vim /etc/sysconfig/nerwork-scripts/ifcfg-ens33
DEVICE=ens33
NAME=ens33
BOOTPROTO=static
IPADDR=172.22.144.188
PREFIX=16
ONBOOT=yes
GATEWAY=172.22.144.17
由于客户端IP与VIP不在一个网段,所以网关需要指向路由器
路由器的配置
vim /etc/sysconfig/nerwork-scripts/ifcfg-ens33
DEVICE=ens33
NAME=ens33
BOOTPROTO=static
IPADDR=172.22.144.17
ONBOOT=yes
PREFIX=16
路由器配置1接口网卡 连接外网
vim /etc/sysconfig/nerwork-scripts/ifcfg-ens37
DEVICE=ens37
IPADDR=192.168.49.5
PREFIX=24
路由器配置2接口网卡 连接内网
vim /sysctl.conf
net.ipv4.ip_forward=1
在路由配置文件加入这一行
sysctl -p
启动路由转接服务
lvs的配置
vim /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE=ens33
NAME=ens33
BOOTPROTO=static
IPADDR=192.168.49.2
PREFIX=24
ONBOOT=yes
GATEWAY=192.168.49.5
将lvs的ip网关指向路由器2接口
rs服务器配置
DEVICE=ens33
NAME=ens33
BOOTPROTO=static
IPADDR=192.168.49.3
PREFIX=24
ONBOOT=yes
GATEWAY=192.168.49.5
将rs服务1,2的网关全部指向路由器2接口
vs一键安装脚本
vim lvs_dr_vs.sh
#!/bin/bash
#Author:wangxiaochun
#Date:2017-08-13
vip=‘192.168.49.100‘
iface=‘lo:1‘
mask=‘255.255.255.255‘
port=‘80‘
rs1=‘192.168.49.3‘
rs2=‘192.168.49.4‘
scheduler=‘wrr‘
type=‘-g‘
rpm -q ipvsadm &> /dev/null || yum -y install ipvsadm &> /dev/null
case $1 in
start)
ifconfig $iface $vip netmask $mask #broadcast $vip up
iptables -F
ipvsadm -A -t ${vip}:${port} -s $scheduler
ipvsadm -a -t ${vip}:${port} -r ${rs1} $type -w 1
ipvsadm -a -t ${vip}:${port} -r ${rs2} $type -w 1
echo "The VS Server is Ready!"
;;
stop)
ipvsadm -C
ifconfig $iface down
echo "The VS Server is Canceled!"
;;
*)
echo "Usage: $(basename $0) start|stop"
exit 1
;;
esac
rs1服务器一键安装脚本
#!/bin/bash
#Author:wangxiaochun
#Date:2017-08-13
vip=192.168.49.100
mask=‘255.255.255.255‘
dev=lo:1
rpm -q httpd &> /dev/null || yum -y install httpd &>/dev/null
service httpd start &> /dev/null && echo "The httpd Server is Ready!"
echo "<h1>rs1</h1>" > /var/www/html/index.html
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
ifconfig $dev $vip netmask $mask #broadcast $vip up
#route add -host $vip dev $dev
echo "The RS Server is Ready!"
;;
stop)
ifconfig $dev down
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
echo "The RS Server is Canceled!"
;;
*)
echo "Usage: $(basename $0) start|stop"
exit 1
;;
esac
rs2服务器一键安装脚本
#!/bin/bash
#Author:wangxiaochun
#Date:2017-08-13
vip=192.168.49.100
mask=‘255.255.255.255‘
dev=lo:1
rpm -q httpd &> /dev/null || yum -y install httpd &>/dev/null
service httpd start &> /dev/null && echo "The httpd Server is Ready!"
echo "<h1>rs2</h1>" > /var/www/html/index.html
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
ifconfig $dev $vip netmask $mask #broadcast $vip up
#route add -host $vip dev $dev
echo "The RS Server is Ready!"
;;
stop)
ifconfig $dev down
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
echo "The RS Server is Canceled!"
;;
*)
echo "Usage: $(basename $0) start|stop"
exit 1
;;
esac
bash lvs_dr_rs.sh start/stop
这是这三个脚本的启动,停止的命令!
启动所有脚本后在 客户端测试!
while true;do curl 192.168.49.100;sleep 0.5;done
111
lvyao
111
lvyao
111
lvyao
111
lvyao
111
lvyao
.....
DR模式负载均衡的搭建(单网段)大功告成!!!!!!!!!!!
标签:_for 搭建 port ngx 网关 war ddr one sch
原文地址:https://blog.51cto.com/14234525/2399850