• LVS负载均衡群集-NAT模式实例


    一、NAT模式LVS负载均衡群集部署

    实验场景:

    主机操作系统IP地址工具/软件/安装包
    负载均衡器CentOS7内网:192.168.137.110、外网:12.0.0.1ipvsadm
    NFS服务器CentOS7192.168.137.10rpcbind、nfs-utils
    Web节点服务器1CentOS7192.168.137.15rpcbind、nfs-utils、httpd
    Web节点服务器2CentOS7192.168.137.20rpcbind、nfs-utils、httpd
    客户端Windows1012.0.0.100--------------------

    二、LVS-NAT访问数据流向

    1、部署共享存储(NFS服务器:192.168.137.10)

    1. systemctl stop firewalld.service
    2. systemctl disable firewalld.service
    3. setenforce 0
    4. yum -y install nfs-utils rpcbind
    5. systemctl start rpcbind.service
    6. systemctl start nfs.service
    7. systemctl enable nfs.service
    8. systemctl enable rpcbind.service
    9. mkdir /opt/xiao
    10. mkdir /opt/da
    11. chmod 777 /opt/xiao
    12. chmod 777 /opt/da
    13. vim /etc/exports
    14. /usr/share *(ro,sync)
    15. /opt/lic 192.168.137.0/24(rw,sync)
    16. /opt/kiki 192.168.137.0/24(rw,sync)
    17. exportfs -rv #发布共享

    1.1关闭防火墙和增强机制

    1.2安装nfs的俩个安装包,并启动

    1. yum -y install nfs-utils rpcbind
    2. systemctl start rpcbind.service
    3. systemctl start nfs.service
    4. systemctl enable nfs.service
    5. systemctl enable rpcbind.service

    1.3在/opt目录下创建俩个共享目录xiao和da并赋权

    1. mkdir /opt/xiao
    2. mkdir /opt/da
    3. chmod 777 /opt/xiao
    4. chmod 777 /opt/da

     1.4在/etc/exports里面写入共享策略,发布共享

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

    2、配置节点服务器(192.168.137.15、192.168.137.20)

    192.168.137.15和192.168.137.20进行相同的操作

    1. systemctl stop firewalld.service
    2. systemctl disable firewalld.service
    3. setenforce 0
    4. yum install httpd -y
    5. systemctl start httpd.service
    6. systemctl enable httpd.service
    7. yum -y install nfs-utils rpcbind
    8. showmount -e 192.168.137.10
    9. systemctl start rpcbind
    10. systemctl enable rpcbind

    2.1关闭防火墙 

    1. systemctl stop firewalld
    2. systemctl disable firewalld
    3. setenforce 0

     2.2安装httpd并开启

    1. yum install httpd -y
    2. systemctl start httpd.service
    3. systemctl enable httpd.service

     2.3安装nfs服务、查看共享目录列表、开启服务

    1. yum -y install nfs-utils rpcbind
    2. showmount -e 192.168.137.10
    3. systemctl start rpcbind
    4. systemctl enable rpcbind

     3、在192.168.137.15机器上

    3.1进行内容挂载

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

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

     3.2修改网卡

    1. vim /etc/sysconfig/network-scripts/ifcfg-ens33
    2. systemctl restart network

    重启网卡 

    4、在192.168.137.20机器上 

    4.1进行内容挂载

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

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

     4.2修改网卡

    1. vim /etc/sysconfig/network-scripts/ifcfg-ens33
    2. systemctl restart network

     5、配置负载调度器(内网关 ens33:192.168.137.110,外网关ens37:12.0.0.1)

    5.1关闭防火墙和增强机制

    1. systemctl stop firewalld.service
    2. systemctl disable firewalld.service
    3. setenforce 0

    5.2配置SNAT转发规则

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

    5.3加载LVS内核模块

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

    5.4安装ipvsadm管理工具

    yum -y install ipvsadm

    启动服务前须保存负载分配策略

    1. ipvsadm-save > /etc/sysconfig/ipvsadm
    2. ipvsadm --save > /etc/sysconfig/ipvsadm
    3. systemctl start ipvsadm.service

    5.5配置负载分配策略(NAT模式只要在服务器上配置,节点服务器不需要特殊配置 )

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

    5.6添加一个网络适配器

     

    5.7修改网卡ens33和ens37

    1. cd /etc/sysconfig/network-scripts/
    2. cp ifcfg-ens33 ifcfg-ens37
    3. vim ifcfg-ens37

    5.8重启网络服务并查看网卡信息

    1. systemctl restart network
    2. ifconfig

     6、windows客户机

    6.1修改网卡信息

    6.2进行连通性测试 

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

     

    总结


    集群:就是将多台主机作为一个整体,对外提供相同的服务

    群集类型有负载均衡 高可用 高性能运算

    负载均衡作用:减少响应的延迟,提高并发处理能力

    高可用作用:系统的可靠性、稳定性,减少服务中断时间,减少损失

    高性能运算作用:高性能运算得能力  分布式 并发

    LVS负载均衡三种模式

    NAT地址转换:调度器作为网关,是访问请求的入口,也是响应访问的出口,在高并发场景当中负载压力很高,可以提高安全性能

    TUN ip隧道:仅访问请求的路口,响应数据不经过调度器。但是需要大量公网ip,还需要专用的ip隧道,数据转发受ip隧道影响

    DR直接路由:仅访问请求的入口,响应数据不经过调度器。节点服务器和调度器在同一个物理网络中,数据转发不受额外的影响

    负载调度器:通过调度算法确定,以及RIP(真实的ip)发送;节点服务器池:所有服务器用的资源通过;共享存储:提供网站存储资源

  • 相关阅读:
    [附源码]计算机毕业设计springboot良辰之境影视评鉴系统
    【非BAT】不需要写BAT批处理:文件也能批量查找与复制,也能完成批量图片的查找,批量的文件查找,查找后复制到指定位置
    前端工程化精讲第十五课 版本特性:Webpack 5 中的优化细节
    Docker - 编译安装nginx镜像
    YOLOv6又快又准的目标检测框架 已开源
    什么是NoSQL?什么是redis?redis是做什么的?
    【数据结构】设计环形队列
    Android 开发小贴士
    腾讯云轻量2核4G5M服务器双11优惠价166元一年可选三年
    【学习日志】2022.11.03 LearnOpenGL----DAY1
  • 原文地址:https://blog.csdn.net/qq_44239779/article/details/126751529