天天看点

LVS的DR模型+NAS

 LVS的DR模型+NAS

<a href="http://blog.51cto.com/attachment/201212/160314830.png" target="_blank"></a>

在上图的DR模型中,所有机器(包括Director)都配置了一个额外的IP地址,即vip

该模型需要解决一下几个问题

1、当一个客户client上VIP发去一个连接请求是,此请求必须要连接到Director的VIP上,而不是real server上的lo:0的,因为LVS主要目的就是要Director负责调度这些连接请求到real server上,所以到ARP广播请求时,仅将Director的MAC地址响应给client就可以了。

解决此问题,

(1)可以再路由器上做静态的mac-ip绑定、或arp地址过滤。

(2)在本地的linux主机上通过arp_ignore、arp_announce来解决。

在这我们就用第二种方法来解决。

关于arp_ignore、arp_announce在linux的2.4和2.6的版本中以引入。

Arp_announce  --arp宣告 有3个值

0 - (default) Use any local address, configured on any interface.

1 - Try to avoid local addresses that are not in the target's subnet for this interface.

2 - Always use the best local address for this target.  --自己与arp请求的目标ip地址不符,不回答。

Arp_ignore     --arp忽略 有8个值

0 - (default): reply for any local target IP address, configured on any interface.

1 - reply only if the target IP address is local address configured on the incoming interface. --仅响应与本地的进接口一致的请求

2 - reply only if the target IP address is local address configured on the incoming interface and both with the sender's IP address are part from same subnet on this interface.

3 - do not reply for local address configured with scope host,only resolutions for golbal and link addresses are replied.

4-7 - reserved

8 - do not reply for all local addresses

2、real server必须要有与director的VIP一样的ip地址,即可以配置Looback地址

3、Real server 必须要有到client的路由

下面就用上面的模型图做一个web服务的例子,具体配置一下。

1、Director上的配置

配置eth0:0的ip

<a href="http://blog.51cto.com/attachment/201212/160333424.png" target="_blank"></a>

安装ipvsadm

yum -y install ipvsadm

添加规则使Director成为虚拟的web服务

Ipvsadm -A -t  192.168.2.1:80 -s  rr

指明后方的real server 

Ipvsadm -a -t 192.168.2.1:80 -r 192.168.2.100  -g   (默认就是-g 即DR) 

Ipvsadm -a -t 192.168.2.1:80 -r 192.168.2.200  -g 

service ipvsadm save

service ipvsadm start

chkconfig ipvsadm on

2、real server的配置

Real server 的lo:0接口ip的配置

先看一下arp的那两个参数

sysctl -a |grep arp  默认都是0

net.ipv4.conf.eth0.arp_ignore = 0

net.ipv4.conf.eth0.arp_announce = 0

设置它们的值如下:

 echo "net.ipv4.conf.eth0.arp_ignore = 1" &gt;&gt;/etc/sysctl.conf 

 echo "net.ipv4.conf.eth0.arp_announce = 2" &gt;&gt;/etc/sysctl.conf

sysctl -p  --立即生效   下面配置lo:0 的ip

<a href="http://blog.51cto.com/attachment/201212/160355343.png" target="_blank"></a>

 掩码是4个255

server1和server2一样

你可以cp server1

scp 192.168.2.100:/etc/sysctl.conf   /etc/

3、配置server1和server2的路由

route add  -host 192.168.2.1 dev lo:0

4、搭建Server1和server2的web服务

这里就不写了

当客户机client访问VIP是,每刷新一次就会在server1和server2之间轮询,这在实际应用中对于静态的网站不会出现什么问题,但当时动态网站时,如你注册了一个账号保存到了server1上了,当你刷新时你连接到了server2上,但是server2上可没有保存你的注册信息呀,怎样解决这个问题呢,需要共享存储了。我们先看看先下面的NAS吧。。

<a href="http://baike.baidu.com/picview/2679515/2679515/0/f35ea009737def736b60fbd2.html"></a>

<a href="http://baike.baidu.com/picview/2679515/2679515/0/f35ea009737def736b60fbd2.html">  </a>

NAS网络存储是文件级别的共享存储,可以通过文件共享协议SAMBA、NFS来实现。

假如有一台共享存储服务器,它的ip为192.168.2.2  我们可以共享文件夹在本地,server1和server2通过磁盘映射将共享文件夹挂载到/var/ww/html/下,在共享文件夹下存放我们的动态网站不就可以了。你也可以设置成自动挂载。。。。!!!

关于NFS的配置和自动挂载,这里我就不写了,可以参考

本文转自 abc16810 51CTO博客,原文链接:http://blog.51cto.com/abc16810/1104029

继续阅读