LVS load balancing-NAT (Address Translation) mode cluster experimental configuration + troubleshooting

Don’t say much, go directly to the experiment

Topology

Insert picture description here

Network Configuration

One scheduler: configure dual network card VM1: 192168.100.23 bridged network card: 20.0.0.23
Two WEB server cluster pools: 192.168.100:24, 192.168.100:25 The gateway here must point to the address 192.168.100.23
An NFS shared server: 192.168.100:21

The following is the notebook VM1 network card setting only host The
Insert picture description here
following is the notebook VM8 network card setting nat
Insert picture description here

How to bind dual network cards on the VM?
Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here
Choose from definition and choose your network card

#看清楚除了ens33外的网卡,我这里是ens36,我们复制36的UUID
[root@localhost network-scripts]# nmcli connection
NAME              UUID                        TYPE            DEVICE
ens33             49511b41-e51a-41f0-a43e-d13274d3ce10 ethernet    ens33
virbr0           1816178ee-807e-3499-9d19-20507cbb8ad3 ethernet    ens36

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost ~]# cp ifcfg-ens33 ifcfg-ens36
[root@localhost ~]#  vi ifcfg-ens36

UUID 改一下
ens33换成36

#IPADDR上面的内容修改就行   下面的内容只需要下面两个就可以了
IPADDR=192.168.100.23
NETMASK=255.255.255.0


#查看一下三台的网关
yum -y install net-tools      最小安装需要

#192.168.100.23的主机:
route -n
Kernel IP routing table
Destination       Gateway      Genmask         Flags   Metric  Ref    Use  Iface
20.0.0.0        0.0.0.0       255.255.255.0   U         102     0        0  ens33
192.168.100.0   0.0.0.0       255.255.255.0   U         101     0        0  ens36

###192.168.100.24的主机:
[root@localhost ~]# route -n
Kernel IP routing table
Destination         Gateway      Genmask        Flags   Metric   Ref     Use  Iface
0.0.0.0         192.168.100.23  0.0.0.0         UG      100      0        0  ens33
192.168.100.0       0.0.0.0     255.255.255.0    U      100      0        0  ens33
192.168.122.0       0.0.0.0     255.255.255.0    U      0        0        0  virbr0

###192.168.100.25的主机:
[root@localhost ~]# route -n
Kernel IP routing table
Destination        Gateway          Genmask           Flags   Metric   Ref    Use Iface
0.0.0.0          192.168.100.23    0.0.0.0            UG      100        0     0 ens33
192.168.100.0    0.0.0.0           255.255.255.0      U       100        0     0 ens33

The network environment is set up and the experiment is started

Start server configuration

###LVS主机192.168.100.23的配置
[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
[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 InActConn

#创建虚拟服务器(注意:NAT模式要两块网卡,调度器的地址是外网口地址)
群集的VIP地址为20.0.0.23,针对TCP80端口提供负载分流服务,使用的轮询调度算法。对于负载均衡调度器来说,VIP必须是本机实际已启用的IP地址
[root@localhost ~]# ipvsadm -A -t 20.0.0.23:80 -s rr

2)添加服务器节点
[root@localhost ~]# ipvsadm -a -t 20.0.0.23:80 -r 192.168.100.24:80 -m
[root@localhost ~]# ipvsadm -a -t 20.0.0.23:80 -r 192.168.100.25:80 -m 


3)保存LVS策略并查看
[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.24:http -m -w 1
-a -t localhost.localdomain:http -r 192.168.100.25:http -m -w 1


4)开启调度服务器路由转发功能
[root@localhost ~]# vi /etc/sysctl.conf 
net.ipv4.ip_forward = 1

##查看是否开启
[root@localhost ~]# sysctl -p
net.ipv4.ip_forward = 1
#存储服务器192.168.100.21 配置#

rpm -q nfs-utils  ###如果没装,yum -y install nfs-utils
rpm -q rpcbind  ###如果没装,yum  -y install rpcbind

[root@localhost~ ]# systemctl start nfs
[root@localhost ~]# systemctl start rpcbind

##创建挂载点内容
[root@localhost ~]# mkdir /opt/51xit /opt/52xit
[root@localhost ~]# echo "51是我" > /opt/51xit/index.html
[root@localhost ~]# echo "我是52" > /opt/51xit/index.html

##宣告挂载什么内容
[root@localhost ~]# vi /etc/exports
/opt/51xit 192.168.100.0/24(rw,sync)
/opt/52xit 192.168.100.0/24(rw,sync)

##查看一下
[root@localhost ~]# showmount -e
Export list for localhost.localdomain:
/opt/52xit 192.168.100.0/24
/opt/51xit 192.168.100.0/24


[root@localhost~]# systemctl restart nfs
[root@localhost~]# systemctl restart rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbind

#NAT轮询主机1:192.168.100.24的配置#

#必须要装nfs-untils否则mount不识别nfs格式,系统最小化安装带要装
[root@localhost~]# yum -y install nfs-utils rpcbind  

#如果还没发布,请到存储服务器发布下exportfs -rv 
[root@localhost~]# showmount -e 192.168.100.21      
Export list for 192.168.100.21:
/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.21:/opt/51xit /var/www/html/

#永久挂载,注意格式对齐
[root@localhost~]# vi /etc/fstab
192.168.100.21:/opt/51xit/   /var/www/html/  nfsdefaults,_netdev 0 0

[root@localhost ~]# systemctl start httpd
[root@localhost~] systemctl enable httpd
#NAT轮询主机2:192.168.100.25的配置#
[root@localhost~]# yum -y install nfs-utils rpcbind      
[root@localhost~]# showmount -e 192.168.100.21      

Export list for 192.168.100.21:
/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.21:/opt/52xit /var/www/html/

[root@localhost~]# vi /etc/fstab
192.168.100.21:/opt/52xit/   /var/www/html/  nfsdefaults,_netdev 0 0                

[root@localhost ~]# systemctl start httpd
[root@localhost~]#  systemctl enable httpd

test

Open the webpage and visit 20.0.0.23.
Insert picture description here
Close this webpage, clear the history and visit again. The
Insert picture description here
configuration is successful.

Pit pit experience

1#当你配置完两台192.168.100.24与192.168.100.25时,用你的笔记本浏览器分别访问一下
#看看是否能正常访问

2#或者直接访问不了宣告的外网接口地址时(20.0.0.23)
#检查防火墙,检查网络配置,注意调度器两台都无需配网关

3#当你轮询不起来的时候,首先排查上面的问题1,第二步检查网络,第三步查看ipvsadm查看宣告是否正确

Guess you like

Origin blog.csdn.net/weixin_48190891/article/details/108743784