LVS负载均衡之LVS-NAT实例部署(配置篇)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LVS负载均衡之LVS-NAT实例部署(配置篇)相关的知识,希望对你有一定的参考价值。
前面我们了解了关于LVS三种模式(LVS/NAT,LVS/DR,LVS/TUN)的工作原理,以及它们间区别和优势,下面我们逐一介绍关于这三种模式的实例部署,本节主要介绍LVS/NAT实例部署,如下:
LVS/NAT实例部署
如图所示为整体的拓扑图:
一.部署前说明:
(1)系统版本: centos 6.6
(2)角色及ip相关信息:
CIP:192.168.10.13/24
VIP:192.168.10.100/24
DIR:eth0:192.168.1.100/24 Eth1:192.168.10.100/24
Real-server:192.168.1.10/24 和 192.168.1.11/24. 192.168.1.12/24(提供http服务)
二.部署操作:
负载均衡器上配置操作
(1)在DIR上安装ipvsadm软件包以及相关依赖包:
# yum install popt-devel libnl-devel -y
(2)在DIR上新建一个shell脚本文件,如下操作所示:
# vim /etc/init.d/lvs-nat
脚本内容如下
#!/bin/sh # # Startup script handle the initialisation of LVS # chkconfig: - 28 72 # description: Initialise the Linux Virtual Server for NAT # ### BEGIN INIT INFO # Provides: ipvsadm # Required-Start: $local_fs $network $named # Required-Stop: $local_fs $remote_fs $network # Short-Description: Initialise the Linux Virtual Server # Description: The Linux Virtual Server is a highly scalable and highly # available server built on a cluster of real servers, with the load # balancer running on Linux. # description: start LVS of Nat LOCK=/var/lock/ipvsadm.lock VIP=192.168.10.10 RIP1=192.168.6.9 RIP2=192.168.6.11 . /etc/rc.d/init.d/functions start() { if [ -e $LOCK ]; then echo "The LVS-NAT Server is already running !" else 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 /bin/touch $LOCK #Clear IPVS table /sbin/ipvsadm -C #set LVS /sbin/ipvsadm -At $VIP:80 -s rr /sbin/ipvsadm -at $VIP:80 -r $RIP1:80 -m -w 1 /sbin/ipvsadm -at $VIP:80 -r $RIP2:80 -m -w 1 echo "starting LVS-NAT Server is ok!" fi } stop() { echo "0" >/proc/sys/net/ipv4/ip_forward echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects echo "1" >/proc/sys/net/ipv4/conf/eth0/send_redirects echo "1" >/proc/sys/net/ipv4/conf/eth1/send_redirects /sbin/ipvsadm -C rm -rf $LOCK echo "stopping LVS-NAT server is ok!" } start() { if [ -e $LOCK ]; then echo "The LVS-NAT Server is already running !" else echo "The LVS-NAT Server is not running !" fi } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; *) echo "Usage: $1 {start|stop|restart|status}" exit 1 esac exit 0
RS server 上配置操作
LVS-NAT 模式的后端机器不需要做任何配置.特别注意的是:LVS-NAT模式中需要将后端的RS server即RIP的网关统一指向到DIR的内网地址Eth0的ip,即DIR的内网地址充当后端RS server的网关;
总结 : LVS/NAT是所有模式中最方便配置的一种模式
以上是关于LVS负载均衡之LVS-NAT实例部署(配置篇)的主要内容,如果未能解决你的问题,请参考以下文章