LVS NAT模式

1、(20.20.20.22客户机    20.20.20.11 是负载服务器公网地址 10.10.10.11是内网地址是普通服务器的网关地址  10.10.10.12/13是普通服务器

         RS1和RS2通过网关返回给10.11然后通过20.11给20.22)

 

2、本地增加一网卡地址20.20.20.22

3、负载服务器需要新增一张网卡(eth0 设置为20.11 eth1设置为10.11)

    service network restart

4、关闭NetworkManager   chkconfig NetworkManager off(3台都操作)

5.安装ipvsadm

6、负载服务器/etc/sysctl.conf 

                     将net.ipv4.ip_forward改为1(路由转发功能)

                      sysctl -p 生效

7、service iptables start   chkconfig iptables on

8、iptables -t nat -A POSTROUTING -s 10.10.10.0/24 -o eth0 -j SNAT --to-source 20.20.20.11

    (当10.10.10.0并且是eth0网口源地址发过来的数据转化为是20.20.20.11)

    iptables  -t nat -L (查看NAT表)

   service iptables save(防火墙规则保存)

   chkconfig iptables on

9、ipvsadm -A -t 20.20.20.11:80 -s rr   -----集群服务器设置

     ipvsadm -a -t 20.20.20.11:80 -r 10.10.10.12:80 -m  ----普通服务器

      ipvsadm -a -t 20.20.20.11:80 -r 10.10.10.13:8080 -m(NAT模式支持端口映射,服务器只要将httpd端口改为8080)   ---普通服务器

     service ipvsadm save  (lvs配置保存)

1、将GATEWAY=10.10.10.11写道普通服务器中作为网关地址

   service network restart

2、service httpd start

    echo "1111111111" >>/var/www/html/index.html  写道12那一台

  echo "222222222" >>/var/www/html/index.html  写道13那一台

   13  /etc/httpd/conf/httpd.conf 将端口80改为8080

     

      

原文地址:https://www.cnblogs.com/jdwy24/p/12350379.html