码迷,mamicode.com
首页 > 其他好文 > 详细

lvs-DR模型

时间:2016-11-07 22:47:19      阅读:373      评论:0      收藏:0      [点我收藏+]

标签:lvs dr

  1. 部署规划

技术分享


2.设备ip规划:

  因为只是本机摸拟,设备全部用虚拟机,包括机器、路由器、交换机都可用vmware搞定。

除R1、C、S1是真实设备,其它都为虚拟设备,简单介绍下每个设备的情况。

R1:所在公司网络路由器。

C:自已的电脑。

S1:采用桥接模式就相当于连入了这个交换机,从而成为这网络的一部分,而这个网络一般就叫VMnet0。(不一定准切,但是这个道理)

S2:采用仅主机模式就接入了这个交换机,这个网络一般就叫VMnet1。

DR:两个网卡,一个桥接模式,一个仅主机模式。

N[1-n]:Nginx服务器,采用一个网卡,采用仅主机模式。

T[1-n]:Tomcat服务器,采用一个网卡,采用仅主机模式。

R2:软路由,采用两个网卡,一个桥接模式,一个仅主机模式。

设备名接口名ip默认网关子网掩码接入模式
C本机网卡192.168.13.121192.168.13.1255.255.255.0-
R1lan口192.168.13.1-255.255.255.0-
R2wan口192.168.13.125
192.168.13.1255.255.255.0桥接
R2lan口192.168.19.6-255.255.255.0仅主机
DReth0192.168.13.210(vip)192.168.13.1255.255.255.0桥接
DReth1192.168.19.3192.168.19.6255.255.255.0仅主机
N1eth0192.168.19.4192.168.19.6255.255.255.0仅主机
N1lo:0192.168.13.210(vip)-255.255.255.255-
N2eth0192.168.19.5192.168.19.6255.255.255.0仅主机
N2lo:0192.168.13.210(vip)-255.255.255.255-
T1eth0192.168.19.7192.168.19.6255.255.255.0仅主机
T2eth0192.168.19.8192.168.19.6255.255.255.0仅主机
T3eth0192.168.19.9192.168.19.6255.255.255.0仅主机
T4eth0192.168.19.10192.168.19.6255.255.255.0仅主机
























    

3.虚拟机网络配置

N[1-n]主机lo:0接口上的vip在后面步骤设置。
/**DR eth0**/
[root@server ~]#ifconfig eth0 192.168.13.210 netmask 255.255.255.0 up
[root@server ~]#route add default gw 192.168.13.1 dev eth0
/**vip所在网卡都加一条特殊路由,意思是以目标地址进来的请求数据包,
那么响应数据包的源地址都应为该设备上的ip地址**/
[root@server ~]#route add -host 192.168.13.210  dev eth0 
/**DR eth1**/
[root@server ~]#ifconfig eth1 192.168.19.3 netmask 255.255.255.0 up
[root@server ~]#route add default gw 192.168.19.6 dev eth1
[root@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.13.210 netmask 255.255.255.0 up
route add default gw 192.168.13.1 dev eth0
ifconfig eth1 192.168.19.3 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth1
:wq
/**N1 eth0**/
[root@server ~]#ifconfig eth0 192.168.19.4 netmask 255.255.255.0 up
[root@server ~]#route add default gw 192.168.19.6 dev eth0
[root@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.4 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
/**N2 eth0**/
[root@server ~]#ifconfig eth0 192.168.19.5 netmask 255.255.255.0 up
[root@server ~]#route add default gw 192.168.19.6 dev eth0
[root@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.5 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
/**T1 eth0**/
[root@server ~]#ifconfig eth0 192.168.19.7 netmask 255.255.255.0 up
[root@server ~]#route add default gw 192.168.19.6 dev eth0
[root@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.7 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
/**T2 eth0**/
[root@server ~]#ifconfig eth0 192.168.19.8 netmask 255.255.255.0 up
[root@server ~]#route add default gw 192.168.19.6 dev eth0
[root@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.8 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
/**T3 eth0**/
[root@server ~]#ifconfig eth0 192.168.19.9 netmask 255.255.255.0 up
[root@server ~]#route add default gw 192.168.19.6 dev eth0
[root@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.9 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
/**T4 eth0**/
[root@server ~]#ifconfig eth0 192.168.19.10 netmask 255.255.255.0 up
[root@server ~]#route add default gw 192.168.19.6 dev eth0
[root@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.10 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq




4.安装软件

 在每台机上把防火墙都先关闭,避免干扰。dr上一定要关闭,因为ipvs和iptables不能同时开。

 

[root@server ~]#chkconfig iptables off
[root@server ~]#service iptables stop
[root@server ~]#setenforce

 (1)在N1和N2上安装nginx

  nginx-1.6.2.tar.gz

 [root@server ~]#yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
 [root@server ~]#mv nginx-1.6.2.tar.gz /usr/local/src
 [root@server ~]#cd /usr/local/src
 [root@server src]#tar -zxvf nginx-1.6.2.tar.gz
 [root@server src]#cd nginx-1.6.2
 [root@server src]#./configure
 [root@server src]#make 
 [root@server src]#make install
 [root@server src]#cd /usr/local/nginx
 [root@server nginx]#echo "test nginx 192.168.19.4" > html/index.html /**在N1上执行**/
 [root@server nginx]#echo "test nginx 192.168.19.5" > html/index.html /**在N2上执行**/
 [root@server nginx]#sbin/nginx /**启动nginx**/
 [root@server nginx]#vi /etc/rc.local
  /usr/local/nginx/sbin/nginx
  :wq

 (2)安装tomcat(略)

 (3)在DR上安装ipadm和ipvs(ipvs模块编绎在linux内核不用安装)

  [root@server nginx]#grep -i ‘vs‘ /boot/config-2.6.32-642.el6.x86_64 /**查看ipvs模块是否存在**/
  [root@server nginx]#yum install ipvsadm

5.配置N[1-n]的lo:0接口的vip


/**N1和N2 设置禁用arp的内核参数,为了让别的主机发现不要它,不与外界通迅**/
[root@server ~]#sysctl -w net.ipv4.conf.lo.arp_announce=2
[root@server ~]#sysctl -w net.ipv4.conf.all.arp_announce=2
[root@server ~]#sysctl -w net.ipv4.conf.lo.arp_ignore=1
[root@server ~]#sysctl -w net.ipv4.conf.all.arp_ignore=1
/**N1和N2 lo:0**/
/**禁止这个网卡与外界通迅,设置广播为自已,掩码4个255,表示网络中只有自已本身一个主机**/
[root@server ~]#ifconfig lo:0 192.168.13.210 broadcast 192.168.13.210 netmask 255.255.255.255 up
/**vip所在网卡都加一条特殊路由,意思是以目标地址进来的请求数据包,
那么响应数据包的源地址都应为该设备上的ip地址**/
[root@server ~]#route add -host 192.168.13.210 dev lo:0
[root@server ~]#vi /etc/rc.local
sysctl -w net.ipv4.conf.lo.arp_announce=2
sysctl -w net.ipv4.conf.all.arp_announce=2
sysctl -w net.ipv4.conf.lo.arp_ignore=1
sysctl -w net.ipv4.conf.all.arp_ignore=1
ifconfig lo:0 192.168.13.210   broadcast 192.168.13.210  netmask 255.255.255.255 up
route add -host 192.168.13.210  dev lo:0
:wq


6.开启DR并添加nginx服务

[root@server ~]#ipvsadm -C
[root@server ~]#ipvsadm -A -t 192.168.13.210:80 -s wlc
[root@server ~]#ipvsadm -a -t 192.168.13.210:80 -r 192.168.19.4 -g -w 1
[root@server ~]#ipvsadm -a -t 192.168.13.210:80 -r 192.168.19.5 -g -w 2
[root@server ~]#ipvsadm -L -n
[root@server ~]#vi /etc/rc.local
ipvsadm -A -t 192.168.13.210:80 -s wlc
ipvsadm -a -t 192.168.13.210:80 -r 192.168.19.4 -g -w 1
ipvsadm -a -t 192.168.13.210:80 -r 192.168.19.5 -g -w 2
:wq

6.测试

技术分享



本文出自 “开心程序” 博客,请务必保留此出处http://jamesoak.blog.51cto.com/4365697/1870357

lvs-DR模型

标签:lvs dr

原文地址:http://jamesoak.blog.51cto.com/4365697/1870357

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!