Experiment-how to build LVS-NAT load balancing cluster

1. Experiment preparation

One scheduler: Configure dual network cards VM1: 192.168.100.21
NAT network card: 20.0.0.21
Two WEB server cluster pools: 192.168.100.22, 192.168.100.23
Here the gateway must point to the address 192.168.100.21
One NFS shared server: 192.168 .100.24

Second, the steps

2.1 Scheduler settings (192.168.100.21)

2.1.1 Basic settings

'###虚拟机添加网卡###'
一块网卡NAT配置DHCP模式
[root@localhost ~]# nmcli connection
NAME                UUID                                  TYPE      DEVICE 
ens33               45a23a13-7c7c-4535-893a-5cda88b35616  ethernet  ens33  
virbr0              b746477f-6012-40a1-88aa-fa768ce5f621  bridge    virbr0 
Wired connection 1  58d1aa03-0f23-3fdc-b121-8fee0f982981  ethernet  e[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens36
[root@localhost network-scripts]# vi ifcfg-ens36ns36
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens36
UUID=58d1aa03-0f23-3fdc-b121-8fee0f982981
DEVICE=ens36
ONBOOT=yes
IPADDR=192.168.100.21
NETMASK=255.255.255.0
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# cd ~
[root@localhost ~]# yum -y install ipvsadm
[root@localhost ~]# ipvsadm -v
ipvsadm v1.27 2008/5/15 (compiled with popt and IPVS v1.2.1)
[root@localhost ~]# modprobe ip_vs       ###确认内核对LVS的支持
[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 InActCon

2.1.2 Create a virtual server

[root@localhost ~]# ipvsadam -A -t 20.0.0.21:80 -s rr

2.1.3 Add server node

[root@localhost ~]# ipvsadm -a -t 20.0.0.21:80 -r 192.168.100.22:80 -m
[root@localhost ~]# ipvsadm -a -t 20.0.0.21:80 -r 192.168.100.23:80 -m

2.1.4 Save LVS strategy

[root@localhost ~]# ipvsadm-save > /opt/ipvsadm
[root@localhost ~]# cat /opt/ipvsadm 
-A -t localhost.localdomain:http -s rr
-a -t localhost.localdomain:http -r 192.168.100.22:http -m -w 1
-a -t localhost.localdomain:http -r 192.168.100.23:http -m -w 1

2.1.5 Enable the routing and forwarding function of the dispatch server

[root@localhost ~]# vi /etc/sysctl.conf
'###添加以下内容###'
net.ipv4.ip_forward = 1
[root@localhost ~]# sysctl -p         ###开启路由转发
net.ipv4.ip_forward = 1

2.2 Storage server configuration (192.168.100.24)

[root@localhost ~]# rpm -q nfs-utils       ###如果没装,yum -y install nfs-utils
nfs-utils-1.3.0-0.61.el7.x86_64
[root@localhost ~]# rpm -q rpcbind        ###如果没装,yum -y install rpcbind
rpcbind-0.2.0-47.el7.x86_64
[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# systemctl restart 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 ~]# echo "this is www.51xit.top" > /opt/51xit/index.html
[root@localhost ~]# echo "this is www.52xit.top" > /opt/52xit/index.html

2.3 WEB1 server configuration (192.168.100.22)

'防火墙和和核心防护关闭'
[root@localhost ~]# yum -y install nfs-utils       ###必须要安装nfs-utils,否则mount不识别nfs格式
[root@localhost ~]# showmount -e 192.168.100.24        ###查看共享
Export list for 192.168.100.24:
/opt/52xit 192.168.100.0/24
/opt/51xit 192.168.100.0/24
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# mount 192.168.100.24:/opt/51xit /var/www/html         ###临时挂载
[root@localhost ~]# vi /etc/fstab       ###永久挂载
192.168.100.24:/opt/51xit /var/www/html nfs defaults,_netdev 0 0       ###开机自动挂载,注意格式对齐
[root@localhost ~]# init 6      ###记得重启,要不然不生效(如果没有临时挂载)
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

2.4 WEB2 server configuration (192.168.100.23)

[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# mount 192.168.100.24:/opt/52xit /var/www/html/
[root@localhost ~]# ll /var/www/html/
total 4
-rw-r--r-- 1 root root 22 Sep 21 20:13 index.html
[root@localhost ~]# vi /etc/fstab       ###永久挂载
192.168.100.24:/opt/52xit /var/www/html nfs defaults,_netdev 0 0       ###开机自动挂载,注意格式对齐
[root@localhost ~]# init 6      ###记得重启,要不然不生效(如果没有临时挂载)
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

Three, test

Enter the following on the web page:
192.168.100.22
Insert picture description here
192.168.100.23
Insert picture description here
20.0.0.21
Insert picture description here
Refresh the web page again and the
Insert picture description here
test is successful

Guess you like

Origin blog.csdn.net/ZG_66/article/details/108708785