Home  >  Article  >  System Tutorial  >  Describe in detail the VIP and DIP cross-segment examples of LVS-DR

Describe in detail the VIP and DIP cross-segment examples of LVS-DR

PHPz
PHPzOriginal
2024-07-23 13:46:30369browse

Describe in detail the VIP and DIP cross-segment examples of LVS-DR

在日常应用环境中,我们会遇到这样一种lvs部署环境,所有的dr以及的rs server都在一个局域网环境中,但只有一个公网ip,而又需要将应用发布到internet上,都知道lvs的最好的模式就是所有的server都有一个公网ip,但很多时候公网资源稀缺,当出现只有一个公网ip的时候,怎么实现lvs对外发布呢?

一、实验拓扑

Describe in detail the VIP and DIP cross-segment examples of LVS-DR

二、整体环境

Describe in detail the VIP and DIP cross-segment examples of LVS-DR

三、详细配置
路由器配置
eth0:公网IP接入INTERNET
eth1:172.18.68.10(公网IP)                     #实验环境中使用172.18.68.10做公网IP
eth2:10.10.0.1内网IP

在上面的配置中eth0、eth2、VIP一共使用了3个公网IP。还可以缩减成两个公网IP。
即eth1不配置公网IP,在路由上添加主机路由 route add -host 172.18.68.100 dev eth2 ,也能达到相同的效果。
VS调度器配置

在脚本中修改VIP、网卡名、端口、后端服务器然后执行脚本即可。

注意:关于vip,如果vip不在DIP所在的网段内,那么vip一定要配置在dr与后端RS Server直连的网卡上,不然就会出现无法访问的情况;也就是说VIP与RIP要配到同一个网卡上。

#!/bin/bash
#Author:shuaiguoxia.com
#Date:2017-10-23
vip='172.18.0.100'
iface='eth0:1'
mask='255.255.255.255'
port='80'
rs1='10.10.0.72'
rs2='10.10.0.73'
scheduler='wrr'
type='-g'
case $1 in
start)
    ifconfig $iface $vip netmask $mask broadcast $vip up
    iptables -F
    ipvsadm -A -t ${vip}:${port} -s $scheduler
    ipvsadm -a -t ${vip}:${port} -r ${rs1} $type -w 1
    ipvsadm -a -t ${vip}:${port} -r ${rs2} $type -w 1
    echo "The VS Server is Ready!"
    ;;
stop)
    ipvsadm -C
    ifconfig $iface down
    echo "The VS Server is Canceled!"
    ;;
*)
    echo "Usage: $(basename $0) start|stop"
    exit 1
    ;;
esac

将以上代码保存为脚本,然后执行脚本即可

./dr-vs.sh start              #dr-vs.sh为脚本名
RS服务器配置

首先配置RS的内网IP地址,设定默认网关为10.10.0.1.然后运行下面脚本即可

#!/bin/bash
#Author:shuaiguoxia.com
#Date:2017-10-23
vip=172.18.68.100
mask='255.255.255.255'
dev=lo:1
case $1 in
start)
    echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
    echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
    echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
    echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
    ifconfig $dev $vip netmask $mask broadcast $vip up
    route add -host $vip dev $dev
    echo "The RS Server is Ready!"
    ;;
stop)
    ifconfig $dev down
    echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore3
    echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
    echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
    echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
    echo "The RS Server is Canceled!"
    ;;
*) 
    echo "Usage: $(basename $0) start|stop"
    exit 1
    ;;
esac

将以上代码保存为脚本,然后执行脚本即可

./dr-rs.sh start              #dr-rs.sh为脚本名
注意

注意:关于vip,如果vip不在DIP所在的网段内,那么vip一定要配置在dr与后端RS Server直连的网卡上,不然就会出现无法访问的情况;也就是说VIP与RIP要配到同一个网卡上。

The above is the detailed content of Describe in detail the VIP and DIP cross-segment examples of LVS-DR. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn