实验场景:
| 主机 | 操作系统 | IP地址 | 工具/软件/安装包 |
| 负载均衡器 | CentOS7 | 内网:192.168.137.110、外网:12.0.0.1 | ipvsadm |
| NFS服务器 | CentOS7 | 192.168.137.10 | rpcbind、nfs-utils |
| Web节点服务器1 | CentOS7 | 192.168.137.15 | rpcbind、nfs-utils、httpd |
| Web节点服务器2 | CentOS7 | 192.168.137.20 | rpcbind、nfs-utils、httpd |
| 客户端 | Windows10 | 12.0.0.100 | -------------------- |
- systemctl stop firewalld.service
- systemctl disable firewalld.service
- setenforce 0
-
- yum -y install nfs-utils rpcbind
-
- systemctl start rpcbind.service
- systemctl start nfs.service
-
- systemctl enable nfs.service
- systemctl enable rpcbind.service
-
- mkdir /opt/xiao
- mkdir /opt/da
-
- chmod 777 /opt/xiao
- chmod 777 /opt/da
-
- vim /etc/exports
- /usr/share *(ro,sync)
- /opt/lic 192.168.137.0/24(rw,sync)
- /opt/kiki 192.168.137.0/24(rw,sync)
-
- exportfs -rv #发布共享

- yum -y install nfs-utils rpcbind
-
- systemctl start rpcbind.service
- systemctl start nfs.service
-
- systemctl enable nfs.service
- systemctl enable rpcbind.service


- mkdir /opt/xiao
- mkdir /opt/da
-
- chmod 777 /opt/xiao
- chmod 777 /opt/da

- vim /etc/exports
- /usr/share *(ro,sync)
- /opt/lic 192.168.137.0/24(rw,sync)
- /opt/kiki 192.168.137.0/24(rw,sync)
-
- exportfs -rv #发布共享


192.168.137.15和192.168.137.20进行相同的操作
- systemctl stop firewalld.service
- systemctl disable firewalld.service
- setenforce 0
-
- yum install httpd -y
- systemctl start httpd.service
- systemctl enable httpd.service
-
- yum -y install nfs-utils rpcbind
- showmount -e 192.168.137.10
-
- systemctl start rpcbind
- systemctl enable rpcbind
- systemctl stop firewalld
- systemctl disable firewalld
- setenforce 0

- yum install httpd -y
- systemctl start httpd.service
- systemctl enable httpd.service

2.3安装nfs服务、查看共享目录列表、开启服务- yum -y install nfs-utils rpcbind
- showmount -e 192.168.137.10
- systemctl start rpcbind
- systemctl enable rpcbind


- mount 192.168.137.10:/opt/xiao /var/www/html
- echo 'hello Mr.tree' > /var/www/html/index.html

我们可以在192.168.137.10主机里查看到内容
3.2修改网卡- vim /etc/sysconfig/network-scripts/ifcfg-ens33
- systemctl restart network

重启网卡

- mount.nfs 192.168.137.10:/opt/da /var/www/html
- echo 'hi xiaolaji' > /var/www/html/index.html

我们可以在192.168.137.10主机里查看到内容

- vim /etc/sysconfig/network-scripts/ifcfg-ens33
- systemctl restart network


- systemctl stop firewalld.service
- systemctl disable firewalld.service
- setenforce 0

- vim /etc/sysctl.conf
- net.ipv4.ip_forward = 1
- 或
- echo '1' > /proc/sys/net/ipv4/ip_forward
- sysctl -p
-
- iptables -t nat -F
- iptables -F
- iptables -t nat -A POSTROUTING -s 192.168.137.0/24 -o ens37 -j SNAT --to-source 12.0.0.1


- modprobe ip_vs #加载 ip_vs模块
- cat /proc/net/ip_vs #查看 ip_vs版本信息

yum -y install ipvsadm

启动服务前须保存负载分配策略
- ipvsadm-save > /etc/sysconfig/ipvsadm
- 或
- ipvsadm --save > /etc/sysconfig/ipvsadm
-
- systemctl start ipvsadm.service

- ipvsadm -C #清除原有策略
- ipvsadm -A -t 12.0.0.1:80 -s rr
- ipvsadm -a -t 12.0.0.1:80 -r 192.168.137.15:80 -m
- ipvsadm -a -t 12.0.0.1:80 -r 192.168.137.20:80 -m
- ipvsadm #启用策略
-
- ipvsadm -ln #查看节点状态,Masq代表 NAT模式
- ipvsadm-save > /etc/sysconfig/ipvsadm #保存策略


- cd /etc/sysconfig/network-scripts/
- cp ifcfg-ens33 ifcfg-ens37
- vim ifcfg-ens37


5.8重启网络服务并查看网卡信息
- systemctl restart network
- ifconfig


可以开两个浏览器刷新后可以看到页面会跳转

集群:就是将多台主机作为一个整体,对外提供相同的服务
群集类型有负载均衡 高可用 高性能运算
负载均衡作用:减少响应的延迟,提高并发处理能力
高可用作用:系统的可靠性、稳定性,减少服务中断时间,减少损失
高性能运算作用:高性能运算得能力 分布式 并发
LVS负载均衡三种模式
NAT地址转换:调度器作为网关,是访问请求的入口,也是响应访问的出口,在高并发场景当中负载压力很高,可以提高安全性能
TUN ip隧道:仅访问请求的路口,响应数据不经过调度器。但是需要大量公网ip,还需要专用的ip隧道,数据转发受ip隧道影响
DR直接路由:仅访问请求的入口,响应数据不经过调度器。节点服务器和调度器在同一个物理网络中,数据转发不受额外的影响
负载调度器:通过调度算法确定,以及RIP(真实的ip)发送;节点服务器池:所有服务器用的资源通过;共享存储:提供网站存储资源