Chinaunix首页 | 论坛 | 博客
  • 博客访问: 315683
  • 博文数量: 50
  • 博客积分: 3052
  • 博客等级: 中校
  • 技术积分: 710
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-03 12:13
文章分类
文章存档

2009年(10)

2008年(40)

我的朋友

分类: LINUX

2009-03-23 20:15:59

此文章同步发布在我的新blog中,

看glusterfs的东西也有段时间了,不过一直一来也是停留在对这个分布式系统的学习,当然对于一个软件的学习不能仅仅停留在对这个软件的熟悉,还要考虑它所适用的范围。最近就在思考,到底对于我们的什么应用合适,我这边接触的比较多的结构就是N台Web+单个NFS。我就再想,既然glusterfs是个聚合分布式文件系统,而且支持HA的功能,是不是可以使用glusterfs来替换NFS,既可以达到共享文件的用途,有可以解决了单点的问题。

先来看下我预计的拓扑结构

下面来解释一下这个拓扑,前端的web应用,每台web上的应用都放置在glusterfs共享出来的硬盘上,尽管我图上画的是一个diskpool,但实际的容量大小是几台web中glusterfs共享空间最小的那个大小。而且对于上面这个拓扑的应用,我并不需要独立的NAS来做共享,完全可以使用每台web服务器上未用的硬盘空间(注:当然你可以选择使用NAS来进行存储,在存储量很大的情况下)。

接下来就来看下实现的方式:
web01:192.168.220.128 共享出来的地址:/var/app
web02:192.168.220.129 共享出来的地址:/var/app
两台机器都事先安装好glusterfs和fuse(安装方法可以参考我前几篇文章)
首先来配置web01的server端

cat /etc/glusterfs/server.vol

volume brick
type storage/posix # POSIX FS translator
option directory /var/app # Export this directory
end-volume

volume locker
type features/posix-locks
subvolumes brick
end-volume

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option listen-port 6996 # Default is 6996
subvolumes locker
option auth.addr.brick.allow * # Allow access to "brick" volume
option auth.addr.locker.allow *
end-volume

web02上的server端配置相同
cat /etc/glusterfs/server.vol

volume brick
type storage/posix # POSIX FS translator
option directory /var/app # Export this directory
end-volume

volume locker
type features/posix-locks
subvolumes brick
end-volume

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option listen-port 6996 # Default is 6996
subvolumes locker
option auth.addr.brick.allow * # Allow access to "brick" volume
option auth.addr.locker.allow *
end-volume

服务器端配置完毕,接下来就是client端的配置,因为两台机器互为对方的sever又同时是自己的server所以两台上都需要配置client端。
首先看下web01上的配置
cat /etc/glusterfs/replicate.vol

volume client0
type protocol/client
option transport-type tcp/client
option remote-host 127.0.0.1 # IP address of the remote brick
option remote-port 6996 # default server port is 6996
option remote-subvolume locker # name of the remote volume
end-volume

volume client1
type protocol/client
option transport-type tcp/client
option remote-host 192.168.211.129
option remote-port 6996
option remote-subvolume locker
end-volume

volume bricks
type cluster/replicate
subvolumes client0 client1
option read-subvolume client0
end-volume

再来看下web02上的配置
cat /etc/glusterfs/replicate.vol

volume client0
type protocol/client
option transport-type tcp/client
option remote-host 127.0.0.1 # IP address of the remote brick
option remote-port 6996 # default server port is 6996
option remote-subvolume locker # name of the remote volume
end-volume

volume client1
type protocol/client
option transport-type tcp/client
option remote-host 192.168.211.128
option remote-port 6996
option remote-subvolume locker
end-volume

volume bricks
type cluster/replicate
subvolumes client0 client1
option read-subvolume client0
end-volume

到此,配置就已经完成了,接下来就可以测试咯,首先两台机器上需要加载fuse
modprobe fuse
如果没有报错,说明fuse模块加载完毕,然后在两台机器上启动server端和client端
web01上执行

启动服务端
glusterfsd -f /etc/glusterfs/server.vol

启动client端
glusterfs -f /etc/glusterfs/replicate.vol /usr/local/nginx/html/blog

web02上如法炮制
然后就可以在web01上的/mnt上放置web的内容了,web02上可以自动的看到相应的内容,并不需要人为的干预,没台机器上都会有一份web应用的拷贝,这样无论那台web宕机,web的提供的服务是不会中断,也不会受到影响的,从而避免了,单点NFS故障导致服务中断,同时避免了,双NFS数据同步的问题。同时每台web优先读取自己硬盘上的copy,所以可以减少网络负载。
但这个方案还不是最完美的,因为这种方案对于写频繁的应用来说是存在问题的,如果出现同时写一个文件的情况,就会造成数据的不一致,所以如果web应用是读频繁的话,还是很有优势的,而且如果后台人员需要对应用进行更新,只需要更新第一台server的就行,默认情况下replicate的应用,subvolumes client0 client1 中的一个就是主server,这里只要对于client0上的数据进行更新就可以做到同步了。


阅读(1550) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~