部署LVS-DR集群

部署LVS-DR集群

使用LVS实现DR模式的集群调度服务器,为用户提供Web服务:
客户端IP地址为192.168.4.10
LVS调度器VIP地址为192.168.4.15
LVS调度器DIP地址设置为192.168.4.5
真实Web服务器地址分别为192.168.4.100、192.168.4.200
使用加权轮询调度算法,web1的权重为1,web2的权重为2

说明:
CIP是客户端的IP地址;
VIP是对客户端提供服务的IP地址;
RIP是后端服务器的真实IP地址;
DIP是调度器与后端服务器通信的IP地址(VIP必须配置在虚拟接口)。

使用4台虚拟机,1台作为客户端、1台作为Director调度器、2台作为Real Server,拓扑结构如图-2所示。实验拓扑结构主机配置细节如表-4所示。

说明:
CIP是客户端的IP地址;
VIP是对客户端提供服务的IP地址;
RIP是后端服务器的真实IP地址;
DIP是调度器与后端服务器通信的IP地址(VIP必须配置在虚拟接口)。

步骤一:配置实验网络环境
1)设置Proxy代理服务器的VIP和DIP
注意:为了防止冲突,VIP必须要配置在网卡的虚拟接口!!!
------------------------------------------------------------------------------
proxy上操作:

# cd /etc/sysconfig/network-scripts/
# ls ifcfg-eth*
ifcfg-eth0 ifcfg-eth1 ifcfg-eth3

# cp ifcfg-eth0{,:0}
# ls ifcfg-eth*
ifcfg-eth0 ifcfg-eth0:0 ifcfg-eth1 ifcfg-eth3

# vim /etc/sysconfig/network-scripts/ifcfg-eth0:0
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0:0
DEVICE=eth0:0
ONBOOT=yes
IPADDR=192.168.4.15
PREFIX=24


# 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.4.5:80 wrr
-> 192.168.2.100:80 Masq 2 0 0
-> 192.168.2.200:80 Masq 1 0 0

# ipvsadm -C
# ipvsadm -Ln

# ipvsadm -A -t 192.168.4.15:80 -s wrr

# ipvsadm -a -t 192.168.4.15:80 -r 192.168.4.100 -g
# ipvsadm -a -t 192.168.4.15:80 -r 192.168.4.200 -g
# 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.4.15:80 wrr
-> 192.168.4.100:80 Route 1 0 0
-> 192.168.4.200:80 Route 1 0 0
-----------------------------------------------------
web1上操作:

之前已经给eth0配了IP是192.168.4.100,然后给禁用了。
# nmcli connection up eth0
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/6)

# cd /etc/sysconfig/network-scripts/
# ls ifcfg-*
ifcfg-eth0 ifcfg-eth1 ifcfg-lo

# cp ifcfg-lo{,:0}

# ls ifcfg-*
ifcfg-eth0 ifcfg-eth1 ifcfg-lo ifcfg-lo:0

# vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.4.15
NETMASK=255.255.255.255 #记住web1和web2的子网掩码都是32!!!
NETWORK=192.168.4.15 #只能是本机的IP!!!
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=192.168.4.15 #只能是本机的IP!!!
ONBOOT=yes
NAME=loopback
-----------------------------------------------------
web2上操作:

# nmcli connection modify eth0 ipv4.method manual ipv4.addresses "192.168.4.200/24" connection.autoconnect yes
# nmcli connection up eth0
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/6)

# cd /etc/sysconfig/network-scripts/
# ls ifcfg-*
# cp ifcfg-lo{,:0}

# vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.4.15
NETMASK=255.255.255.255 #记住web1和web2的子网掩码都是32!!!
NETWORK=192.168.4.15 #只能是本机的IP!!!
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=192.168.4.15 #只能是本机的IP!!!
ONBOOT=yes
NAME=loopback
-------------------------------------------------
# vim /etc/sysctl.conf

追加写入:
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2

# sysctl -p

页面显示:
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2

# systemctl restart network

# ifconfig lo:0
lo:0: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 192.168.4.15 netmask 255.255.255.255
---------------------------------------
grep -q 是不显示输出结果

sleep 1 代表1秒
usleep 1 代表1毫秒(时间太短了)

 

posted @ 2019-04-29 00:40  安于夏  阅读(251)  评论(0编辑  收藏  举报