本文共 3819 字,大约阅读时间需要 12 分钟。
实验需要五台虚拟机,都是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-ens33DEVICE=ens33NAME=ens33BOOTPROTO=staticIPADDR=172.22.144.188PREFIX=16ONBOOT=yesGATEWAY=172.22.144.17由于客户端IP与VIP不在一个网段,所以网关需要指向路由器
路由器的配置vim /etc/sysconfig/nerwork-scripts/ifcfg-ens33DEVICE=ens33NAME=ens33BOOTPROTO=staticIPADDR=172.22.144.17ONBOOT=yesPREFIX=16路由器配置1接口网卡 连接外网vim /etc/sysconfig/nerwork-scripts/ifcfg-ens37DEVICE=ens37IPADDR=192.168.49.5PREFIX=24路由器配置2接口网卡 连接内网vim /sysctl.confnet.ipv4.ip_forward=1在路由配置文件加入这一行sysctl -p启动路由转接服务
lvs的配置vim /etc/sysconfig/network-scripts/ifcfg-ens33DEVICE=ens33NAME=ens33BOOTPROTO=staticIPADDR=192.168.49.2PREFIX=24ONBOOT=yesGATEWAY=192.168.49.5将lvs的ip网关指向路由器2接口
rs服务器配置DEVICE=ens33NAME=ens33BOOTPROTO=staticIPADDR=192.168.49.3PREFIX=24ONBOOT=yesGATEWAY=192.168.49.5将rs服务1,2的网关全部指向路由器2接口
vs一键安装脚本vim lvs_dr_vs.sh #!/bin/bash#Author:wangxiaochun#Date:2017-08-13vip='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/nullcase $1 instart) 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-13vip=192.168.49.100mask='255.255.255.255'dev=lo:1rpm -q httpd &> /dev/null || yum -y install httpd &>/dev/nullservice httpd start &> /dev/null && echo "The httpd Server is Ready!"echo "rs1
" > /var/www/html/index.htmlcase $1 instart) 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-13vip=192.168.49.100mask='255.255.255.255'dev=lo:1rpm -q httpd &> /dev/null || yum -y install httpd &>/dev/nullservice httpd start &> /dev/null && echo "The httpd Server is Ready!"echo "rs2
" > /var/www/html/index.htmlcase $1 instart) 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;done111lvyao111lvyao111lvyao111lvyao111lvyao.....DR模式负载均衡的搭建(单网段)大功告成!!!!!!!!!!!
转载于:https://blog.51cto.com/14234525/2399850