IP | 备注 |
---|---|
192.168.174.128 | 调度器、关闭防火墙、安全规则 |
192.168.174.130 | web端、关闭防火墙、安全规则 |
192.168.174.131 | web端、关闭防火墙、安全规则 |
三台centos7
两台web端搭建ecshop和ecshop1,一台安装ipvsadm实现调度
安装ipvsadm
# yum install -y ipvsadm
调度器执行脚本
#! /bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
ipv=/usr/sbin/ipvsadm
vip=192.168.174.127
rs1=192.168.174.130
rs2=192.168.174.131
#增加一个新网卡
ifconfig eno16777736:2 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev eno16777736:2
$ipv -C
$ipv -A -t $vip:80 -s wrr
#注意映射端口最好一
$ipv -a -t $vip:80 -r $rs1:80 -g -w 1 //-g为dr模式
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1
两台web端执行脚本
#/bin/bash
vip=192.168.174.127
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip 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
最后可ipvsadm -ln查看虚拟服务器及真实服务器
# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.174.127:80 wrr
-> 192.168.174.130:80 Route 1 0 0
-> 192.168.174.131:80 Route 1 0 1
访问虚拟ip