规划:
节点1:192.168.200.100
节点2:192.168.200.101
节点3:192.168.200.102
节点1:192.168.200.100
#安装Ipvsadm内核管理工具
yum install -y ipvsadm
#添加vip
ip a a 192.168.200.200/28 dev ens33
#添加对外提供的服务ip
ipvsadm -A -t 192.168.200.200:80 -s rr
#[参数说明]
-A 添加规则
-t TCP 指定分发器VIP
-s 指定调度算法
rr 代表轮询round-robin
#在虚拟服务器中添加后端服务器
ipvsadm -a -t 192.168.200.200:80 -r 192.168.200.101:80 -g
ipvsadm -a -t 192.168.200.200:80 -r 192.168.200.102:80 -g
#[参数说明]
-a 添加real-server地址
-r 指定real-server地址
-m 以NAT模式分配
-g 以DR模式分配
-w 指定权值
#查看规则
ipvsadm -ln
节点2:192.168.200.101
#安装nginx
yum -y install nginx
systemctl start nginx
systemctl enable nginx
#备份原有默认页面
mv /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.bak
#创建新字段
echo "This is PACS-web1 192.168.200.101" > /usr/share/nginx/html/index.html
#关闭ARP宣告,和ARP转发,这里有两种方法,临时关闭与永久关闭.
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/ens33/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/ens33/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
#[永久关闭]
[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.conf.ens32.arp_ignore=1
net.ipv4.conf.ens32.arp_announce=2
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
#加载生效
[root@localhost ~]# sysctl -p
#添加vip
ip a a 192.168.200.200/28 dev ens33
节点3:192.168.200.102
yum -y install nginx
systemctl start nginx
systemctl enable nginx
#备份原有默认页面
mv /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.bak
echo "This is PACS-web2 192.168.200.102" > /usr/share/nginx/html/index.html
#关闭ARP宣告,和ARP转发,这里有两种方法,临时关闭与永久关闭.
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/ens33/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/ens33/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
#[永久关闭]
[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.conf.ens32.arp_ignore=1
net.ipv4.conf.ens32.arp_announce=2
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
#添加vip
ip a a 192.168.200.200/28 dev ens33
验证:
本次搭建使用虚拟机部署,采用nat模式配置网卡因此在cmd中访问效果正常