- 配置调度器
- 配置虚拟IP地址(VIP)
采用虚接口的方式(ens33:0),为网卡ens33绑定VIP,以此访问群集。
配置结果ens33 172.16.16.173/24 ens33:0 172.16.16.172/24
[root@localhost yum.repos.d]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vim ifcfg-ens33:0
[root@localhost network-scripts]# vim ifcfg-ens33 #不用删除uuid
[root@localhost network-scripts]# ifup ens33
成功激活的连接(D-Bus 激活路径:/org/freedesktop/NetworkManager/ActiveConnection/2)
[root@localhost network-scripts]# ifup ens33:0
[root@localhost network-scripts]# ifconfig ens33:0
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.16.172 netmask 255.255.0.0 broadcast 172.16.255.255
ether 00:0c:29:0e:76:34 txqueuelen 1000 (Ethernet)
2)调整/proc响应参数
Lvs和节点都需要共用vip,应该关闭内核的重定向响应。
[root@localhost network-scripts]# vim /etc/sysctl.conf
[root@localhost network-scripts]# sysctl -p
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
3)配置负载均衡策略
[root@localhost network-scripts]# yum -y install ipvsadm
[root@localhost network-scripts]#
[root@localhost network-scripts]# ipvsadm -C
[root@localhost network-scripts]# ipvsadm -A -t 172.16.16.172:80 -s rr
[root@localhost network-scripts]# ipvsadm -a -t 172.16.16.172:80 -r 172.16.16.177 -g -w 1
[root@localhost network-scripts]# ipvsadm -a -t 172.16.16.172:80 -r 172.16.16.178 -g -w 1
[root@localhost network-scripts]# ipvsadm-save
-A -t localhost.localdomain:http -s rr
-a -t localhost.localdomain:http -r 172.16.16.177:http -g -w 1 #-g:dr模式
-a -t localhost.localdomain:http -r 172.16.16.178:http -g -w 1
[root@localhost network-scripts]# systemctl enable ipvsadm
- 配置节点服务器
1)为节点服务器配置VIP设置在虚接口上,但不是物理网卡上的虚接口,是ifcfg-lo的虚接口。
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vim ifcfg-lo:0
[root@localhost network-scripts]# cat ifcfg-lo:0
DEVICE=lo:0
IPADDR=172.16.16.172
NETMASK=255.255.255.255
# 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)
ONBOOT=yes
NAME=loopback:0
[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig lo:0
lo:0: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 172.16.16.172 netmask 255.255.255.255
loop txqueuelen 1 (Local Loopback)
[root@localhost network-scripts]# route add -host 172.16.16.172 dev lo:0
#添加一跳路由,防止节点访问VIP出现混乱,这样访问就会发送到虚接口上。
2)调整/proc参数
[root@localhost network-scripts]# route add -host 172.16.16.172 dev lo:0
[root@localhost network-scripts]# vim /etc/sysctl.conf
[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
3)安装httpd,修改访问目录。(搭建两台httpd)
[root@localhost network-scripts]# yum -y install httpd
[root@localhost network-scripts]# echo "web1" >> /var/www/html/index.html
[root@localhost network-scripts]# systemctl start httpd
#如上述在搭建一台httpd即可
设置一个同网段的测试机测试即可。
在负载调度器查看连接负载
4)节点服务器设置统一的网站目录,nfs。
[root@localhost ~]# yum -y install nfs-utils rpcbind
[root@localhost ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# mkdir -pv /opt/wwwroot
mkdir: 已创建目录 "/opt/wwwroot"
[root@localhost ~]# vim /etc/exports
[root@localhost ~]# cat /etc/exports
/opt/wwwroot *(rw,sync,no_root_squash)
[root@localhost ~]# cat /opt/wwwroot/index.html #共享目录内容
nfs
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
在所有节点服务器设置:
[root@localhost network-scripts]# showmount -e 172.16.16.179
Export list for 172.16.16.179:
/opt/wwwroot *
[root@localhost network-scripts]# mount 172.16.16.179:/opt/wwwroot /var/www/html/
测试: