Article Directory
Regarding the principle of load balancing, I wrote it in detail in the previous article~~ (probably) ~~ The
link is here: blog address click me
Man of few words!
lab environment
Use VM virtual machine for demonstration
A total of six virtual machines are used:
1. Load balancing scheduler, at the same time as the import and export gateway CentOS7.6
2. Three node servers CentOS7.6
3. One NFS file server CentOS7.6
4. One Each client uses Win10
Purpose
Client 20 accesses the server cluster to verify polling
bring it on! ! Show! ! !
Configure NFS file server
[root@localhost ~]# yum -y install nfs-utils ##安装nfs组件
[root@localhost ~]# yum -y install rpcbind ##RPC服务
Modify the IP address and network card mode. The
NFS service must be in the intranet 192.168.10 segment, and the gateway points to the LAN interface of the LVM configured for a while
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
IPADDR=192.168.10.20 ##IP地址
PREFIX=24 ##子网掩码
GATEWAY=192.168.10.1 ##网关
[root@localhost ~]# systemctl restart network
Set up NFS
[root@localhost ~]# mkdir /NFSshare
[root@localhost ~]# cd /NFSshare/
[root@localhost NFSshare]# mkdir zero one two
[root@localhost NFSshare]# vim /etc/exports ##现网中只要指向一个就可以,因为全部服务器的内容要一样,不会影响使用
/NFSshare/zero 192.168.10.0/24(rw,sync)
/NFSshare/one 192.168.10.0/24(rw,sync)
/NFSshare/two 192.168.10.0/24(rw,sync)
[root@localhost NFSshare]# systemctl start nfs
[root@localhost NFSshare]# systemctl start rpcbind
[root@localhost NFSshare]# showmount -e
Export list for localhost.localdomain:
/NFSshare/one 192.168.10.0/24
/NFSshare/zero 192.168.10.0/24
/NFSshare/two 192.168.10.0/24
Configure node server
We configure Apache to verify that
HTTPD is installed on all three servers and turn off the firewall
[root@5centos ~]# yum -y install httpd
[root@5centos ~]# setenforce 0
[root@5centos ~]# iptables -F
Configure the IP as 192.168.10 and the network segments
are 192.168.10.21
192.168.10.22
192.168.10.23 respectively
[root@5centos ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
IPADDR=192.168.10.21 ##另外两条如上面的配置
PREFIX=24
GATEWAY=192.168.10.1
[root@5centos ~]# systemctl restart network
Check if NFS is successful
[root@5centos ~]# showmount -e 192.168.10.20
Export list for 192.168.10.20:
/NFSshare/two 192.168.10.0/24
/NFSshare/one 192.168.10.0/24
/NFSshare/zero 192.168.10.0/24
Set up automatic mounting, three shared folders to three node servers
[root@5centos ~]# vim /etc/fstab
节点 一
192.168.10.20:/NFSshare/zero /var/www/html nfs defaults 0 0
[root@5centos ~]# mount -a ##测试挂载
节点 二
[root@localhost ~]# vim /etc/fstab
192.168.10.20:/NFSshare/one /var/www/html nfs defaults 0 0
[root@localhost ~]# mount -a
节点 三
[root@7CentOS ~]# vim /etc/fstab
192.168.10.20:/NFSshare/two /var/www/html nfs defaults 0 0
[root@7CentOS ~]# mount -a
Configure the Apache home page file on the NFS server
[root@localhost NFSshare]# echo "<h1>This is ZERO.</h1> " > /NFSshare/zero/index.html
[root@localhost NFSshare]# echo "<h1>This is ONE.</h1> " > /NFSshare/one/index.html
[root@localhost NFSshare]# echo "<h1>This is TWO.</h1> " > /NFSshare/two/index.html
Three nodes enable HTTP service
[root@5centos ~]# systemctl start httpd
Configure LVS
LVS
[root@4CentOS ~]# modprobe ip_vs ##加载 ip_vs 模块
[root@4CentOS ~]# 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
Install management tools
[root@4CentOS ~]# yum -y install ipvsadm
Set up dual network cards and set the IP address
[root@4CentOS ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE="ens33"
ONBOOT="yes"
IPADDR="20.0.0.1"
PREFIX="24"
GATEWAY="20.0.0.1"
[root@4CentOS ~]# cd /etc/sysconfig/network-scripts/
[root@4CentOS network-scripts]# cp ifcfg-ens33 ifcfg-ens34 ##为新网卡增加配置文件
[root@4CentOS network-scripts]# vim ifcfg-ens34
##删除 UUID
NAME="ens34"
DEVICE="ens34"
ONBOOT="yes"
IPADDR="192.168.10.1"
PREFIX="24"
GATEWAY="192.168.10.1"
[root@4CentOS network-scripts]# systemctl restart network
[root@4CentOS network-scripts]# ip a s
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:99:ce:e5 brd ff:ff:ff:ff:ff:ff
inet 20.0.0.1/24 brd 20.0.0.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe99:cee5/64 scope link
valid_lft forever preferred_lft forever
5: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:99:ce:ef brd ff:ff:ff:ff:ff:ff
inet 192.168.10.1/24 brd 192.168.10.255 scope global noprefixroute ens34
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe99:ceef/64 scope link
valid_lft forever preferred_lft forever
Make LVS-NAT
[root@4CentOS /]# echo "1" > /proc/sys/net/ipv4/ip_forward ##开启地址转发
[root@4CentOS /]# ipvsadm -C ##清除缓存
[root@4CentOS /]# ipvsadm -A -t 20.0.0.1:80 -s rr ##-A指向 Vip,-t tcp协议,rr 轮询,-m nat
[root@4CentOS /]# ipvsadm -a -t 20.0.0.1:80 -r 192.168.10.21:80 -m ##-a 指向调度 -r 节点IP
[root@4CentOS /]# ipvsadm -a -t 20.0.0.1:80 -r 192.168.10.22:80 -m
[root@4CentOS /]# ipvsadm -a -t 20.0.0.1:80 -r 192.168.10.23:80 -m
[root@4CentOS /]# ipvsadm ##启动 LVS 功能
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 4CentOS:http rr
-> 192.168.10.21:http Masq 1 0 0
-> 192.168.10.22:http Masq 1 0 0
-> 192.168.10.23:http Masq 1 0 0
Verification experiment
Set the IP address of the client Win 10
Use a browser to access 20.0.0.1
Note: About 20 seconds to access, otherwise the web cache will be opened