负载均衡群集之—LVS-NAT

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了负载均衡群集之—LVS-NAT相关的知识,希望对你有一定的参考价值。

调度服务器:
两块网卡:
Vmnet1内网:192.168.80.100
Vmnet2外网:192.168.90.100(调度器的地址是外网口地址)
-------------------------加载LVS内核模块----------------------
LVS现在已成为Linux内核的一部分,默认编译为ip_vs模块,必要时能够自动调用。以下操作可以手动加载ip_vs模块,并查看当前系统中ip_vs模块的版本信息
[[email protected] ~]# cat /proc/net/ip_vs
cat: /proc/net/ip_vs: 没有那个文件或目录
[[email protected] ~]# modprobe ip_vs //加载ip_vs模块,
[[email protected] ~]# cat /proc/net/ip_vs //查看ip_vs版本信息
[[email protected] ~]# rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm //安装管理软件,不需要启动

[[email protected] ~]# vi nat.sh
#!/bin/bash
echo "1" > /proc/sys/net/ipv4/ip_forward
ipvsadm -C
ipvsadm -A -t 192.168.90.100:80 -s rr
ipvsadm -a -t 192.168.90.100:80 -r 192.168.80.102:80 -m
ipvsadm -a -t 192.168.90.100:80 -r 192.168.80.101:80 -m
ipvsadm -Ln
[[email protected] ~]# sh nat.sh

192.168.80.101服务器:
Vmnet1内网:192.168.80.101
网关:192.168.90.100
[[email protected] ~]# yum install -y httpd
[[email protected] ~]# vi /etc/httpd/conf/httpd.conf
ServerName www.aa.com
[[email protected] ~]# vi /var/www/html/index.html
<h1>Server aa </h1>
[[email protected] ~]# service httpd restart
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
GATEWAY=192.168.80.100
[[email protected] ~]# service network restart

192.168.80.102服务器:
Vmnet1内网:192.168.80.102
网关:192.168.90.100

[[email protected] ~]# yum install -y httpd
[[email protected] ~]# vi /etc/httpd/conf/httpd.conf
ServerName www.bb.com
[[email protected] ~]# vi /var/www/html/index.html
<h1>Server bb </h1>
[[email protected] ~]# service httpd restart
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
GATEWAY=192.168.80.100
[[email protected] ~]# service network restart

真机浏览器测试:
Vmnet1:192.168.80.88
Vmnet2:192.168.90.88
技术分享图片

以上是关于负载均衡群集之—LVS-NAT的主要内容,如果未能解决你的问题,请参考以下文章

负载均衡群集之—LVS-NAT

#构建LVS负载均衡群集之地址转换模式(LVS-NAT)

LVS负载均衡之二:LVS-NAT搭建web群集

Linux——LVS-NAT负载均衡群集原理搭建大白话

LVS负载均衡群集(LVS-NAT)

LVS负载均衡群集(LVS-NAT)