Cluster load balancing--LVS (NAT deployment)

Preface

For those who are not very theoretical, please see the blog
link I wrote before : https://blog.csdn.net/m0_47219942/article/details/108333675 .

One: Experimental configuration

1.1: Experimental environment

  • VMware software
  • One centos7 as LVS gateway, dual network cards
  • Two centos7 as Apache servers
  • A centos7 as NFS storage
  • A win10 as the client

The LVS scheduler is used as the gateway of the web server pool, and the two LVS network cards are connected to the internal and external networks respectively, using the round-robin (rr) scheduling algorithm

1.2: Experimental schematic diagram

Insert picture description here

1.3: Experimental purpose

  • The win7 client accesses the web address of 12.0.0.1, through nat address translation, polling access to Apache1 and

Apache2 host

  • Build nfs network file storage service

1.4: Experimental procedure

1.4.1: Configure NFS server

  • Install nfs service and create mount point
[root@localhost ~]# rpm -q rpcbind   '自带rpcbind'
rpcbind-0.2.0-47.el7.x86_64
[root@localhost ~]# yum install nfs-utils -y
[root@localhost ~]# cd /opt/
[root@localhost opt]# ls
rh
[root@localhost opt]# mkdir kevin benet      
[root@localhost opt]# chmod 777 kevin/ benet/    '改权限'
  • Turn off the firewall
iptables -F
setenforce 0
  • Select host only mode

Insert picture description here

  • Modify network card information
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 
'...省略内容,修改为static'
BOOTPROTO=static
'...省略内容,尾行添加内容'
IPADDR=192.168.100.47
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ifconfig	
  • Set up a shared directory
[root@localhost opt]# vim /etc/exports    '设置共享目录'
/opt/kevin 192.168.100.0/24(rw,sync)
/opt/benet 192.168.100.0/24(rw,sync)
[root@localhost opt]# systemctl start rpcbind
[root@localhost opt]# systemctl start nfs
[root@localhost opt]# exportfs -rv       '查看本机发布的NFS共享目录'
exporting 192.168.100.0/24:/opt/benet
exporting 192.168.100.0/24:/opt/kevin

2.4.2: Configure two Apache servers

  • Install httpd on two Apache servers and turn off the firewall
yum install httpd -y
systemctl stop firewalld.service 
setenforce 0
  • Both select host-only mode
    Insert picture description here

  • Modify the IP addresses of two Apache servers

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 
'...省略内容,修改为static'
BOOTPROTO=static
'...省略内容,尾行添加内容'
IPADDR=192.168.100.52
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ifconfig
[root@localhost ~]# showmount -e 192.168.100.55
Export list for 192.168.100.55:
/opt/benet 192.168.100.0/24
/opt/kevin 192.168.100.0/24
'相同方法修改Apache2'
  • Automatically mount nfs shared directory
[root@localhost ~]# vim /etc/fstab
'尾行添加挂载配置'
192.168.100.55:/opt/kevin               /var/www/html   nfs     defaults        0 0
[root@localhost ~]# mount -a
[root@localhost ~]# df -Th
'相同方法配置Apache2服务器'
192.168.100.55:/opt/benet               /var/www/html   nfs     defaults        0 0
  • Edit homepage file
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# vim index.html
<h1>this is kevin web</h1>
'相同方法配置Apache2服务器'
<h1>this is benet web</h1>

2.4.3: Configure LVS server

  • Turn off the firewall
iptables -F
setenforce 0
  • Load the ip_vs module
[root@localhost ~]# modprobe ip_vs
[root@localhost ~]# cat /proc/net/ip_vs
  • Install ipvsadm tool
[root@localhost ~]# yum install ipvsadm -y
  • Set up dual network cards
    Insert picture description here

  • Modify network card information

[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# cp -p ifcfg-ens33 ifcfg-ens36
[root@localhost network-scripts]# vim ifcfg-ens33
'...省略内容,修改为static'
BOOTPROTO=static
'...省略内容,尾行添加内容'
IPADDR=12.0.0.1
NETMASK=255.255.255.0
[root@lvs network-scripts]# vim ifcfg-ens36
'...省略内容,修改为static'
BOOTPROTO=static
'..省略内容,原本的33改为36'
NAME=ens36
UUID=6ba4ac2f-cb59-454f-9274-b48a6ecadeda	'删除此行 UUID'
DEVICE=ens36    '原本的33改为36'
ONBOOT=yes
IPADDR=192.168.100.1
NETMASK=255.255.255.0     

2.4.4: win7 configuration

  • Modify win7ip address
    Insert picture description here

  • Set host only mode

Insert picture description here

2.4.5: Save the rules and test

  • Configure on the LVS server
vi nat.sh
#!/bin/bash
echo "1" > /proc/sys/net/ipv4/ip_forward  '开启路由转发'
ipvsadm -C
ipvsadm -A -t 12.0.0.1:80 -s rr
ipvsadm -a -t 12.0.0.1:80 -r 192.168.100.48:80 -m	'指向Apache服务器地址'
ipvsadm -a -t 12.0.0.1:80 -r 192.168.100.52:80 -m
ipvsadm
[root@localhost network-scripts]# sh nat.sh 
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  localhost.localdomain:http rr
  -> 192.168.100.52:http          Masq    1      0          0         
  -> 192.168.100.48:http          Masq    1      0          0  
-C:'表示清除缓存'
-A:'添加地址为12.0.0.1:80的虚拟地址,指定调度算法为轮转'
-a: '指定真实服务器,指定传输模式为NAT'
-t:'访问的入口地址,VIP'
rr:'表示轮询'
-m:'指的是NAT模式'

2.5: Client authentication

  • Open win7 and visit 12.0.0.1
    Insert picture description here
    Insert picture description here

  • Has been successful, using a polling algorithm to visit two websites

  • If unsuccessful, you need to try again

Guess you like

Origin blog.csdn.net/m0_47219942/article/details/108327867