目录
1、实验准备
2、配置负载调度器(ens33:192.168.80.9 VIP:192.168.80.188)
2.1 配置虚拟ip地址(VIP:192.168.80.188)
2.2 调整proc响应参数
2.3 设置负载分配策略
3、部署共享存储(NFS服务器:192.168.80.10)
4、节点服务器(192.168.223.11、192.168.223.12,web1和web2同等配置)
5、测试,用本机浏览器访问192.1168.80.188
1、实验准备
DR 服务器:192.168.80.9
Web 服务器1:192.168.80.11
Web 服务器2:192.168.80.12
nfs 服务器: 192.168.80.10
客户端:192.168.80.100
vip:192.168.80.188
2、配置负载调度器(ens33:192.168.80.9 VIP:192.168.80.188)
2.1 配置虚拟ip地址(VIP:192.168.80.188)
#关闭防火墙和selinux服务器
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#setenforce 0#加载模块并查看版本
[root@localhost ~]#modprobe ip_vs
[root@localhost ~]#cat /proc/net/ip_vs
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConn#下载ipvsadm工具
[root@localhost ~]#yum -y install ipvsadm
[root@localhost network-scripts]#cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]#cp ifcfg-ens33 ifcfg-ens33:0
#配置虚拟网卡,若为隧道模式ifcfg-tunl0
[root@localhost network-scripts]#vim ifcfg-ens33:0
#删除dns与网关,注意子网
NAME=ens33:0
DEVICE=ens33:0
IPADDR=192.168.91.188
NETMASK=255.255.255.255
[root@localhost network-scripts]#systemctl restart network
[root@localhost network-scripts]#ifup ifcfg-ens33:0
#启动网卡
[root@localhost network-scripts]#ifconfig ifcfg-ens33:0
2.2 调整proc响应参数
#调整/proc响应参数
#对于 DR 群集模式来说,由于 LVS 负载调度器和各节点需要共用 VIP 地址,
关闭 Linux 内核的重定向参数。响应服务器不是一台路由器,那么它不会发送重定向,所以可以关闭该功能
[root@localhost network-scripts]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0[root@localhost network-scripts]#sysctl -p
#刷新配置
2.3 设置负载分配策略
#配置负载分配策略
[root@localhost ~]#modprobe ip_vs
[root@localhost ~]#cat /proc/net/ip_vs#加载模块
[root@localhost network-scripts]#ipvsadm-save >/etc/sysconfig/ipvsadm
[root@localhost network-scripts]#systemctl start ipvsadm.service[root@localhost network-scripts]#ipvsadm -C
#清除原有的策略[root@localhost ~]#ipvsadm -A -t 192.168.80.188:80 -s rr
[root@localhost ~]#ipvsadm -a -t 192.168.80.188:80 -r 192.168.80.11:80 -g
[root@localhost ~]#ipvsadm -a -t 192.168.80.188:80 -r 192.168.80.12:80 -g
#添加真实服务器-a 指定VIP地址及TCP端口-t 指定RIP地址及TCP端口 -r 指定DR模式-g[root@localhost network-scripts]#ipvsadm
#启用策略 [root@localhost network-scripts]#ipvsadm-save >/etc/sysconfig/ipvsadm
#保存设置
3、部署共享存储(NFS服务器:192.168.80.10)
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0yum install nfs-utils rpcbind -y
systemctl start nfs.service
systemctl start rpcbind.service
systemctl enable nfs.service
systemctl enable rpcbind.servicemkdir /opt/lic /opt/zhangbin
chmod 777 /opt/lic /opt/zhangbinvim /etc/exports
/opt/accp 192.168.80.0/24(rw,sync)
/opt/benet 192.168.80.0/24(rw,sync)--发布共享---
exportfs -rv
4、节点服务器(192.168.223.11、192.168.223.12,web1和web2同等配置)
[root@localhost ~]#systemctl stop firewalld.service
[root@localhost ~]#setenforce 0
[root@localhost ~]#yum install httpd -y
[root@localhost ~]#systemctl start httpd
[root@localhost ~]#cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]#cp ifcfg-lo ifcfg-lo:0
[root@localhost ~]#ifconfig lo:0 192.168.80.188 32
[root@localhost ~]#ifconfig lo:0 192.168.80.188 255.255.255.255
[root@localhost network-scripts]#vim ifcfg-lo:0
#修改回环网卡名,IP地址,子网掩码
DEVICE=lo:0
IPADDR=192.168.80.188
NETMASK=255.255.255.255
NETWORK=127.0.0.0
[root@localhost network-scripts]#route add -host 192.168.80.188 dev lo:0
#设置路由
[root@localhost network-scripts]#route -n
#开机执行命令,或者写入 /etc/profile 文件
[root@localhost network-scripts]#vim /etc/rc.d/rc.local
/usr/sbin/route add -host 192.168.80.188 dev lo:0
[root@localhost network-scripts]#chmod +x /etc/rc.d/rc.local
[root@localhost network-scripts]#ll /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 484 11月 17 16:56 /etc/rc.d/rc.local[root@localhost network-scripts]#vim /etc/sysctl.conf
#添加系统只响应目的IP为本地IP的ARP请求
#系统不使用原地址来设置ARP请求的源地址,而是物理mac地址上的IP
[root@localhost network-scripts]#sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2#开启httpd,rpcbind
[root@localhost network-scripts]#systemctl start rpcbind
[root@localhost network-scripts]#systemctl start httpd
#查看共享目录列表
[root@localhost network-scripts]#showmount -e 192.168.80.10
Export list for 192.168.80.10:
/opt/web2 192.168.80.0/24
/opt/web1 192.168.80.0/24#挂载
[root@localhost network-scripts]#mount.nfs 192.168.80.10:/opt/web1 /var/www/html
[root@localhost network-scripts]#df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 50G 3.9G 47G 8% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 18M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 5.0G 179M 4.9G 4% /boot
tmpfs 378M 36K 378M 1% /run/user/0
192.168.80.10:/opt/web1 40G 3.5G 37G 9% /var/www/html[root@localhost network-scripts]#echo "this is web1" >/var/www/html/index.html
[root@localhost network-scripts]#
5、测试,用本机浏览器访问192.1168.80.188
隔一段时间刷新一下,发现两个页面来回切换