LVS NAT & DR

Standard

—NAT——————————–
网络结构:
Linux Virtual Server:
eth0: 10.0.0.1/24
eth1: 192.168.0.254/24
Real Servers:
RServer1: eth0: 192.168.0.1/24 Gateway: 192.168.0.254
RServer2: eth0: 192.168.0.2/24 Gateway: 192.168.0.254
RServer3: eth0: 192.168.0.3/24 Gateway: 192.168.0.254
RServer4: eth0: 192.168.0.4/24 Gateway: 192.168.0.254

                               Internet
                                   |
                            -------+---------
                            |  10.0.0.1     |
                            |  LVS Server   |
                            | 192.168.0.254 |
                            -------+---------
                                   |
       +-----------------+---------+-------+-----------------+
       |                 |                 |                 |
-------+-------   -------+-------   -------+-------   -------+-------
|   Rserver1  |   |   Rserver2  |   |   Rserver3  |   |   Rserver4  |
| 192.168.0.1 |   | 192.168.0.2 |   | 192.168.0.3 |   | 192.168.0.4 |
---------------   ---------------   ---------------   ---------------

Virtual Server:
vi /opt/lvs-up.sh

#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/eth0/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/eth1/send_redirects
LVSADM='/sbin/ipvsadm'
$LVSADM -C
$LVSADM -A -t 10.0.0.1:80 -s rr
$LVSADM -a -t 10.0.0.1:80 -r 192.168.0.1:80 -m -w 1  #-m表示使用nat方式
$LVSADM -a -t 10.0.0.1:80 -r 192.168.0.2:80 -m -w 1  #-w 1表示服务器的权重
$LVSADM -a -t 10.0.0.1:80 -r 192.168.0.3:80 -m -w 1  #-w 0将该rserver设置为静止状态,以便于维护
$LVSADM -a -t 10.0.0.1:80 -r 192.168.0.4:80 -m -w 1

Real Servers:
配置并启动Web服务,网关均指向192.168.0.254。

—D R——————————–
网络结构:
Linux Virtual Server:
eth0: 10.0.0.1/24
Real Servers:
RServer1: eth0: 192.168.0.5/24
RServer2: eth0: 192.168.0.6/24
RServer3: eth0: 192.168.0.7/24
RServer4: eth0: 192.168.0.8/24

                               Internet
                                   |
                            -------+---------
                            |  10.0.0.1     |
                            |  LVS Server   |
                            -------+---------
                                   |
       +-----------------+---------+-------+-----------------+
       |                 |                 |                 |
-------+-------   -------+-------   -------+-------   -------+-------
|   Rserver1  |   |   Rserver2  |   |   Rserver3  |   |   Rserver4  |
| 192.168.0.5 |   | 192.168.0.6 |   | 192.168.0.7 |   | 192.168.0.8 |

Virtual Server:
vi lvs-up.sh

#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/eth0/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/eth1/send_redirects
LVSADM='/sbin/ipvsadm'
$LVSADM -C
$LVSADM -A -t 10.0.0.1:80 -s rr
$LVSADM -a -t 10.0.0.1:80 -r 192.168.0.5:80 -g -w 1   #-g表示使用dr方式
$LVSADM -a -t 10.0.0.1:80 -r 192.168.0.6:80 -g -w 1
$LVSADM -a -t 10.0.0.1:80 -r 192.168.0.7:80 -g -w 1
$LVSADM -a -t 10.0.0.1:80 -r 192.168.0.8:80 -g -w 1

Real Servers:
vi /opt/rs-up.sh

#!/bin/bash
ifconfig lo:0 10.0.0.1 netmask 255.255.255.0 #添加虚拟地址
route add -host 10.0.0.1 dev lo:0   #添加路由设置
echo 0 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

3 thoughts on “LVS NAT & DR

  1. 莫言

    楼主,请问您在做DR模式测试中,Director的DIP是与VIP同网段还是与realserver同网段?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.