天天看点

Web集群实现共享存储的架构演变及MogileFS

本篇博客从Web集群中亟需解决的大容量存储问题引入,分析了几类常用的共享存储架构,重点解析了分布式存储系统的原理及配置实现;

===================================================================

1 共享存储的架构演变

2 分布式存储系统

    2.1 基础知识

    2.2 分类

    2.3 CAP理论

    2.4 协议

3 MogileFS

    3.1 特性

    3.2 架构

    3.3 组成

    3.4 服务安装及启动

    3.5 配置部署

    3.6 配置前端代理Nginx

    3.7 访问验证

    3.8 后续扩展

rsync+inotify:本地各保留一份完整数据,但通过rsync实时同步修改文件,双主模型哦

NFS:多节点挂载后性能下降严重;存在单点故障,且多个客户端并发修改同一个文件时可能出现不一致的情况;

SAN:存储区域网络,不适用于海量高并发的存储场景,且代价昂贵;可通过软件实现iSCSI存储网络;涉及GFS2/CLVM(LVM2)

MooseFS:分布式文件系统,适用于海量小文件存储;支持FUSE,可被挂载使用;

MogileFS:分布式存储系统,适用于海量小文件存储;不支持FUSE,只能通过API调用;

2.1 基础知识

定义:分布式存储系统是大量普通PC服务器通过Internet互联,对外作为一个整体提供存储服务

特性:

可扩展:分布式存储系统可以扩展到几百台至几千台的集群规模,且随着集群规模的增长,系统整体性能表现为线性增长;

低成本:分布式存储系统的自动容错、自动负载均衡机制使其可以构建在普通PC机之上;另外,线性扩展能力也使得增加、减少机器非常方便,可以实现自动运维;

高性能:无论是针对整个集群还是单台服务器,都要求分布式系统具备高性能;

易用:分布式存储系统需要能够提供易用的对外接口;另外,也要求具备完善的监控、运维工具,并能方便的与其他系统集成,如从Hadoop云计算系统导入数据;

挑战:在于数据、状态信息的持久化,要求在自动迁移、自动容错、并发读写的过程中保证数据的一致性;

2.2 分类

数据类型大致可分为非结构化数据(如文本、图片、视频等),结构化数据(一般存储在关系型数据库中),半结构化数据(如HTML文档);根据处理不同类型数据的需求,分布式存储系统可分为如下4类:

分布式文件系统:用于存储Blob对象,如图片、视频等,这类数据以对象的形式组织,对象之间没有关联;如GFS,MogileFS等;

分布式键值系统:用于存储关系简单的半结构化数据,它只提供基于主键的CRUD(Create/Read/Update/Delete)功能;如Memcache,Redis等;

分布式表格系统:用于存储关系较为复杂的半结构化数据,不仅支持简单的CRUD操作,还支持扫描某个主键范围;如Google Bigtable、Megastore;

分布式数据库:用于存储结构化数据,利用二维表格组织数据;如MySQL Sharding集群,Google Spanner等;

2.3 CAP理论

来自Berkerly的Eric Brewer教授提出了一个著名的CAP理论:一致性(Consistency),可用性(Availability)和分区容忍性(Tolerance of network Partition)三者不能同时满足:

C:读操作总是能读取到之前完成的写操作结果,满足这个条件的系统成为强一致系统,这里的“之前”一般对同一个客户端而言;

A:读写操作在单台机器发生故障的情况下依然能够正常执行,而不需要等待发生故障的机器重启或者其上的服务迁移到其他机器;

P:机器故障、网络故障、机房停电等异常情况下仍然能够满足一致性和可用性;

分布式存储系统要求能够自动容错,即分区可容忍性总是需要满足的,因此,一致性和写操作的可用性就不能同时满足了,需要在这二者间权衡,是选择不允许丢失数据,保持强一致,还是允许少量数据丢失以获得更好的可用性;

2.4 协议

分布式协议涉及的协议很多,例如租约,复制协议,一致性协议,其中以两阶段提交协议和Paxos协议最具有代表性;

两阶段提交协议(Two-phase Commit,2PC)用以保证跨多个节点操作的原子性,即跨多个节点的操作要么在所有节点上全部执行成功,要么全部失败;

两个阶段的执行过程如下:

阶段一:请求阶段(Prepare phase),在请求阶段,协调者通知事务参与者准备提交或者取消事务,然后进入表决过程;

阶段二:提交阶段(Commit phase);

Paxos协议用于确保多个节点对某个投票(例如哪个节点为主节点)达成一致;

3.1 特性

工作于应用层:无需特殊的核心组件;

无单点:三大组件(tracker,mogstore,database)皆可实现高可用;

自动文件复制:复制的最小单位不是文件,而是class;基于不同的class,文件可以被自动的复制到多个有足够存储空间的存储节点上;

传输中立,无特殊协议:可以通过NFS或HTTP协议进行通信;

简单的命名空间:文件通过一个给定的key来确定,是一个全局的命名空间;没有目录,基于域实现文件隔离;

不共享数据:无需通过昂贵的SAN来共享磁盘,每个存储节点只需维护自己所属的存储设备(device)即可;

3.2 架构

<a href="http://s3.51cto.com/wyfs02/M00/28/6B/wKiom1N5jnXTNFaZAAITIAkEXNM059.jpg" target="_blank"></a>

Tracker:MogileFS的核心,是一个调度器;服务进程为mogilefsd;可以做负载均衡调度;

主要职责有:

数据删除;

数据复制;

监控:故障后生成新的数据副本;

查询;

Database:Tracker访问Database,返回用户可用的Storage Node及文件的存放位置;

mogstored:数据存储的位置,通常是一个HTTP(WebDAV)服务器,用于数据的创建、删除、获取等;不可做负载均衡调度;

3.3 组成

MogileFS由3个部分组成:

server:主要包括mogilefsd和mogstored两个应用程序。

mogilefsd实现的是tracker,它通过数据库来保存元数据信息,包括站点domain、class、host等;

mogstored是存储节点(store node),它其实是个WebDAV服务,默认监听在7500端口,接受客户端的文件存储请求。

Utils(工具集):主要是MogileFS的一些管理工具,例如mogadm等;

在MogileFS安装完后,要运行mogadm工具将所有的store node注册到mogilefsd的数据库里,mogilefsd会对这些节点进行管理和监控;

客户端API:MogileFS的客户端API很多,例如Perl、PHP、Java、Python等,用这个模块可以编写客户端程序,实现文件的备份管理功能等;

3.4 服务安装及启动

基本架构(在LNMT架构的基础上改进)

<a href="http://s3.51cto.com/wyfs02/M00/28/6B/wKioL1N5jryCLxbNAAcokoPHoI8707.jpg" target="_blank"></a>

服务器规划

<a href="http://s3.51cto.com/wyfs02/M02/28/6B/wKiom1N5jv6RaOl_AALC6DaRAQg067.jpg" target="_blank"></a>

服务安装及启动

数据库授权

1

2

3

4

5

6

7

8

9

10

<code>MariaDB [(none)]&gt; grant all on *.* to </code><code>'root'</code><code>@</code><code>'192.168.%.%'</code> <code>identified by </code><code>'magedu'</code><code>;</code>

<code>Query OK, 0 rows affected (0.01 sec)</code>

<code>MariaDB [(none)]&gt; grant all on mogdb.* to </code><code>'moguser'</code><code>@</code><code>'192.168.%.%'</code> <code>identified by </code><code>'mogpass'</code><code>;</code>

<code>Query OK, 0 rows affected (0.02 sec)</code>

<code>MariaDB [(none)]&gt; flush privileges;</code>

<code>Query OK, 0 rows affected (0.00 sec)</code>

<code>MariaDB [(none)]&gt;</code>

<code>grant all on *.* to </code><code>'root'</code><code>@</code><code>'192.168.%.%'</code> <code>identified by </code><code>'magedu'</code><code>;</code>

<code>grant all on mogdb.* to </code><code>'moguser'</code><code>@</code><code>'192.168.%.%'</code> <code>identified by </code><code>'mogpass'</code><code>;</code>

<code>flush privileges;</code>

主机192.168.0.45(mogilefs+mogilestored)

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

<code># 所需程序包</code>

<code>[root@mysql mogilefs]</code><code># ls</code>

<code>MogileFS-Server-2.46-2.el6.noarch.rpm            perl-MogileFS-Client-1.14-1.el6.noarch.rpm</code>

<code>MogileFS-Server-mogilefsd-2.46-2.el6.noarch.rpm  perl-Net-Netmask-1.9015-8.el6.noarch.rpm</code>

<code>MogileFS-Server-mogstored-2.46-2.el6.noarch.rpm  perl-Perlbal-1.78-1.el6.noarch.rpm</code>

<code>MogileFS-Utils-2.19-1.el6.noarch.rpm</code>

<code>[root@mysql mogilefs]</code><code># yum install -y *.rpm perl-IO-AIO</code>

<code># 修改配置文件</code>

<code>[root@mysql mogdata]</code><code># vi /etc/mogilefs/mogilefsd.conf # 调度器tracker的配置文件</code>

<code>    </code><code># Enable daemon mode to work in background and use syslog </code>

<code>    </code><code>daemonize = 1</code>

<code>    </code><code># Where to store the pid of the daemon (must be the same in the init script)</code>

<code>    </code><code>pidfile = </code><code>/var/run/mogilefsd/mogilefsd</code><code>.pid</code>

<code>    </code><code># Database connection information</code>

<code>    </code><code>db_dsn = DBI:mysql:mogdb:host=192.168.0.45:3406    </code><code># 存储元数据的数据库信息,包括数据库mogdb及连接地址192.168.0.45:3406</code>

<code>    </code><code>db_user = moguser     </code><code># 数据库用户名</code>

<code>    </code><code>db_pass = mogpass     </code><code># 数据库登录密码</code>

<code>    </code><code># IP:PORT to listen on for mogilefs client requests</code>

<code>    </code><code>listen = 192.168.0.45:7001</code>

<code>[root@mysql mogdata]</code><code># vi /etc/mogilefs/mogstored.conf # 存储节点mogstored的配置文件</code>

<code>    </code><code>maxconns = 10000     </code><code># 最大连接数</code>

<code>    </code><code>httplisten = 0.0.0.0:7500 </code><code># http请求监听的地址和端口</code>

<code>    </code><code>mgmtlisten = 0.0.0.0:7501</code>

<code>    </code><code>docroot = </code><code>/var/mogdata</code> <code># 存储设备挂载目录,可修改</code>

<code># 准备存储设备</code>

<code>[root@mysql mogdata]</code><code># fdisk /dev/sda # 新建分区sda4,大小10G(实际生产环境中,此为整块磁盘,而非分区)</code>

<code>[root@mysql mogdata]</code><code># kpartx -af /dev/sda</code>

<code>[root@mysql mogdata]</code><code># partx -a /dev/sda</code>

<code>[root@mysql mogdata]</code><code># cat /proc/partitions # 验证分区已创建成功</code>

<code>[root@mysql mogdata]</code><code># mke2fs -t ext4 /dev/sda4 # 初始化分区</code>

<code>[root@mysql mogdata]</code><code># mkdir /var/mogdata</code>

<code>[root@mysql mogdata]</code><code># mount -t ext4 /dev/sda4 /var/mogdata/ # 挂载分区</code>

<code>[root@mysql mogdata]</code><code># mkdir /var/mogdata/dev1 # 创建存储设备dev1(注:在192.168.0.46上,此为dev2)</code>

<code>[root@mysql mogdata]</code><code># chown -R mogilefs.mogilefs /var/mogdata/</code>

<code># 初始化数据库</code>

<code>[root@mysql mogdata]</code><code># mogdbsetup --dbhost=192.168.0.45 --dbport=3406 --dbrootuser=root --dbrootpass=magedu --dbuser=moguser --dbpass=mogpass --dbname=mogdb --yes</code>

<code># 初始化数据库执行一次即可,故在主机192.168.0.46上无需执行此步骤</code>

<code># 启动服务</code>

<code>[root@mysql mogilefs]</code><code># service mogilefsd start</code>

<code>Starting mogilefsd                                         [  OK  ]</code>

<code>[root@mysql mogilefs]</code><code># service mogstored start</code>

<code>Starting mogstored                                         [  OK  ]</code>

主机192.168.0.46(mogilefs+mogilestored)

同上,直至mogilefsd和mogstored服务都正常启动

3.5 配置部署(任意一个tracker节点上配置即可,如192.168.0.45)

添加节点

<code>[root@mysql mogdata]</code><code># echo "trackers = 192.168.0.45:7001" &gt; /etc/mogilefs/mogilefs.conf # 管理程序mogadm的配置文件</code>

<code>[root@mysql mogdata]</code><code># mogadm host add 192.168.0.45 --ip=192.168.0.45 --status=alive # 添加节点1</code>

<code>[root@mysql mogdata]</code><code># mogadm host add 192.168.0.46 --ip=192.168.0.46 --status=alive # 添加节点2</code>

<code>[root@mysql mogilefs]</code><code># mogadm host list # 查看已添加节点</code>

<code>192.168.0.45 [1]: alive</code>

<code>  </code><code>IP:       192.168.0.45:7500</code>

<code>192.168.0.46 [2]: alive</code>

<code>  </code><code>IP:       192.168.0.46:7500</code>

添加设备

<code>[root@mysql mogdata]</code><code># mogadm device add 192.168.0.45 1 # 添加存储设备1,设备编号需与/var/mogdata目录下的dev1目录保持一致</code>

<code>[root@mysql mogdata]</code><code># mogadm device add 192.168.0.46 2 # 添加存储设备2,设备编号需与/var/mogdata目录下的dev2目录保持一致</code>

<code>[root@mysql mogdata]</code><code># mogadm device list # 查看已添加设备</code>

<code>                    </code><code>used(G)    </code><code>free</code><code>(G)   total(G)  weight(%)</code>

<code>   </code><code>dev1:   alive      0.146      9.200      9.347        100</code>

<code>   </code><code>dev2:   alive      0.146      9.199      9.346        100</code>

添加domain(域)

<code>[root@mysql mogdata]</code><code># mogadm domain add images</code>

<code>[root@mysql mogdata]</code><code># mogadm domain add text</code>

<code>[root@mysql mogdata]</code><code># mogadm domain list</code>

<code> </code><code>domain               class                mindevcount   replpolicy   hashtype</code>

<code>-------------------- -------------------- ------------- ------------ -------</code>

<code> </code><code>images               default                   2        MultipleHosts() NONE</code>

<code> </code><code>text                 default                   2        MultipleHosts() NONE</code>

添加class(文件类别)

<code>[root@mysql mogdata]</code><code># mogadm class add images class1 --mindevcount=2 # 在域images中添加类别class1和class2,最小文件复制份数为2</code>

<code>[root@mysql mogdata]</code><code># mogadm class add images class2 --mindevcount=2</code>

<code>[root@mysql mogdata]</code><code># mogadm class add text class1 --mindevcount=2 # 在域text中添加类别class1和class2,最小文件复制份数为2</code>

<code>[root@mysql mogdata]</code><code># mogadm class add text class2 --mindevcount=2</code>

<code>[root@mysql mogdata]</code><code># mogadm class list</code>

<code> </code><code>images               class1                    2        MultipleHosts() NONE</code>

<code> </code><code>images               class2                    2        MultipleHosts() NONE</code>

<code> </code><code>text                 class1                    2        MultipleHosts() NONE</code>

<code> </code><code>text                 class2                    2        MultipleHosts() NONE</code>

3.6 配置前端代理Nginx

重新编译安装nginx,添加nginx-mogilefs-module-master模块

<code>[root@nginx1 </code><code>tar</code><code>]</code><code># cd /home/software/src/nginx-1.4.7/</code>

<code>[root@nginx1 nginx-1.4.7]</code><code># ./configure \</code>

<code>&gt;   --prefix=</code><code>/usr</code> <code>\</code>

<code>&gt;   --sbin-path=</code><code>/usr/sbin/nginx</code> <code>\</code>

<code>&gt;   --conf-path=</code><code>/etc/nginx/nginx</code><code>.conf \</code>

<code>&gt;   --error-log-path=</code><code>/var/log/nginx/error</code><code>.log \</code>

<code>&gt;   --http-log-path=</code><code>/var/log/nginx/access</code><code>.log \</code>

<code>&gt;   --pid-path=</code><code>/var/run/nginx/nginx</code><code>.pid  \</code>

<code>&gt;   --lock-path=</code><code>/var/lock/nginx</code><code>.lock \</code>

<code>&gt;   --user=nginx \</code>

<code>&gt;   --group=nginx \</code>

<code>&gt;   --with-http_ssl_module \</code>

<code>&gt;   --with-http_flv_module \</code>

<code>&gt;   --with-http_stub_status_module \</code>

<code>&gt;   --with-http_gzip_static_module \</code>

<code>&gt;   --http-client-body-temp-path=</code><code>/var/tmp/nginx/client/</code> <code>\</code>

<code>&gt;   --http-proxy-temp-path=</code><code>/var/tmp/nginx/proxy/</code> <code>\</code>

<code>&gt;   --http-fastcgi-temp-path=</code><code>/var/tmp/nginx/fcgi/</code> <code>\</code>

<code>&gt;   --http-uwsgi-temp-path=</code><code>/var/tmp/nginx/uwsgi</code> <code>\</code>

<code>&gt;   --http-scgi-temp-path=</code><code>/var/tmp/nginx/scgi</code> <code>\</code>

<code>&gt;   --with-pcre \</code>

<code>&gt;   --with-debug \</code>

<code>&gt;   --add-module=</code><code>/home/software/tar/nginx-mogilefs-module-master</code>

<code>[root@nginx1 nginx-1.4.7]</code><code># make &amp;&amp; make install</code>

配置Nginx,将静态文件和图片的访问都转发至后端MogileFS即可

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

<code>[root@nginx1 nginx]</code><code># cat /etc/nginx/nginx.conf</code>

<code>worker_processes  2;</code>

<code>error_log  </code><code>/var/log/nginx/nginx</code><code>.error.log;</code>

<code>pid        </code><code>/var/run/nginx</code><code>.pid;</code>

<code>events {</code>

<code>    </code><code>worker_connections  1024;</code>

<code>}</code>

<code>http {</code>

<code>    </code><code>include       mime.types;</code>

<code>    </code><code>default_type  application</code><code>/octet-stream</code><code>;</code>

<code>    </code><code>log_format  main  </code><code>'$remote_addr - $remote_user [$time_local] "$request" '</code>

<code>                      </code><code>'$status $body_bytes_sent "$http_referer" '</code>

<code>                      </code><code>'"$http_user_agent" "$http_x_forwarded_for"'</code><code>;</code>

<code>    </code><code>sendfile        on;</code>

<code>    </code><code>keepalive_timeout  65;</code>

<code>    </code><code>fastcgi_cache_path </code><code>/www/cache</code> <code>levels=1:2 keys_zone=fcgicache:10m inactive=5m;</code>

<code>    </code><code>upstream mogfs_cluster { </code><code># 定义后端mogilefs集群</code>

<code>        </code><code>server 192.168.0.45:7001;</code>

<code>        </code><code>server 192.168.0.46:7001;</code>

<code>    </code><code>}</code>

<code>    </code><code>server {</code>

<code>        </code><code>listen       4040;</code>

<code>        </code><code>server_name  xxrenzhe.lnmmp.com;</code>

<code>        </code><code>access_log  </code><code>/var/log/nginx/nginx-img</code><code>.access.log  main;</code>

<code>        </code><code>root </code><code>/www/lnmmp</code><code>.com;</code>

<code>        </code><code>valid_referers none blocked xxrenzhe.lnmmp.com *.lnmmp.com;</code>

<code>        </code><code>if</code> <code>($invalid_referer) {</code>

<code>            </code><code>rewrite ^/ http:</code><code>//xxrenzhe</code><code>.lnmmp.com</code><code>/404</code><code>.html</code>

<code>        </code><code>}</code>

<code>        </code><code>location ~* ^(</code><code>/images/</code><code>.*)$ {    </code><code># 图片访问直接转发至后端mogilefs集群</code>

<code>            </code><code>mogilefs_tracker mogfs_cluster;</code>

<code>            </code><code>mogilefs_domain images;    </code><code># 指定images域</code>

<code>            </code><code>mogilefs_noverify on;</code>

<code>            </code><code>mogilefs_pass $1 {    </code><code># 传输访问的全路径(/images/.*)</code>

<code>                </code><code>proxy_pass $mogilefs_path;</code>

<code>                </code><code>proxy_hide_header Content=Type;</code>

<code>                </code><code>proxy_buffering off;</code>

<code>            </code><code>}</code>

<code>        </code><code>listen       80;</code>

<code>        </code><code>access_log  </code><code>/var/log/nginx/nginx-static</code><code>.access.log  main;</code>

<code>        </code><code>location / {</code>

<code>            </code><code>root   </code><code>/www/lnmmp</code><code>.com;</code>

<code>            </code><code>index  index.php index.html index.htm;</code>

<code>        </code><code>location ~* ^(</code><code>/text/</code><code>.*)$ {    </code><code># 文本访问直接转发至后端mogilefs集群</code>

<code>            </code><code>mogilefs_domain text;    </code><code># 指定text域</code>

<code>            </code><code>mogilefs_pass $1 {    </code><code># 传输访问的全路径(/text/.*)</code>

<code>               </code><code>proxy_pass $mogilefs_path;</code>

<code>               </code><code>proxy_hide_header Content=Type;</code>

<code>               </code><code>proxy_buffering off;</code>

<code>        </code><code>gzip</code> <code>on;</code>

<code>        </code><code>gzip_comp_level 6;</code>

<code>        </code><code>gzip_buffers 16 8k;</code>

<code>        </code><code>gzip_http_version 1.1;</code>

<code>        </code><code>gzip_types text</code><code>/plain</code> <code>text</code><code>/css</code> <code>application</code><code>/x-javascript</code> <code>text</code><code>/xml</code> <code>application</code><code>/xml</code><code>;</code>

<code>        </code><code>gzip_disable msie6;</code>

<code>        </code><code>listen       8080;</code>

<code>        </code><code>access_log  </code><code>/var/log/nginx/nginx-php</code><code>.access.log  main;</code>

<code>        </code><code>error_page  404              </code><code>/404</code><code>.html;</code>

<code>        </code><code>error_page  500 502 503 504  </code><code>/50x</code><code>.html;</code>

<code>        </code><code>location = </code><code>/50x</code><code>.html {</code>

<code>        </code><code>location ~ \.php$ {</code>

<code>            </code><code>root           </code><code>/www/lnmmp</code><code>.com;</code>

<code>            </code><code>fastcgi_pass   127.0.0.1:9000;</code>

<code>          </code><code>fastcgi_cache  fcgicache;</code>

<code>          </code><code>fastcgi_cache_valid 200 302 1h;</code>

<code>          </code><code>fastcgi_cache_valid 301 1d;</code>

<code>          </code><code>fastcgi_cache_valid any 1m;</code>

<code>          </code><code>fastcgi_cache_min_uses 1;</code>

<code>          </code><code>fastcgi_cache_key $request_method:</code><code>//</code><code>$host$request_uri;</code>

<code>          </code><code>fastcgi_cache_use_stale error timeout invalid_header http_500;</code>

<code>            </code><code>fastcgi_index  index.php;</code>

<code>            </code><code>fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;</code>

<code>            </code><code>include        fastcgi_params;</code>

启动nginx服务

<code>[root@nginx1 nginx]</code><code># service nginx start</code>

<code>Starting nginx:                                            [  OK  ]</code>

3.7 访问验证

上传文件测试分布式文件系统MogileFS的功能

<code>[root@mysql mogdata]</code><code># mogupload --domain=images --key='/images/fish.jpg' --file="/images/fish.jpg" # 上传图片文件,选择images域</code>

<code>[root@mysql mogdata]</code><code># mogupload --domain=text --key='/text/index.html' --file="/text/index.html" # 上传文本文件,选择text域</code>

<code>[root@mysql mogdata]</code><code># moglistkeys --domain=images # 列出已添加的key</code>

<code>/images/fish</code><code>.jpg</code>

<code>[root@mysql mogdata]</code><code># moglistkeys --domain=text</code>

<code>/text/index</code><code>.html</code>

<code>[root@mysql mogdata]</code><code># mogfileinfo --domain=images --key='/images/fish.jpg' # 查看已添加文件的具体信息,包括实际可访问地址</code>

<code>- </code><code>file</code><code>: </code><code>/images/fish</code><code>.jpg</code>

<code>     </code><code>class:              default</code>

<code>  </code><code>devcount:                    2</code>

<code>    </code><code>domain:               images</code>

<code>       </code><code>fid:                    9</code>

<code>       </code><code>key:     </code><code>/images/fish</code><code>.jpg</code>

<code>    </code><code>length:                 3225</code>

<code> </code><code>- http:</code><code>//192</code><code>.168.0.45:7500</code><code>/dev1/0/000/000/0000000009</code><code>.fid</code>

<code> </code><code>- http:</code><code>//192</code><code>.168.0.46:7500</code><code>/dev2/0/000/000/0000000009</code><code>.fid</code>

<code>[root@mysql mogdata]</code><code># mogfileinfo --domain=text --key='/text/index.html'</code>

<code>- </code><code>file</code><code>: </code><code>/text/index</code><code>.html</code>

<code>    </code><code>domain:                 text</code>

<code>       </code><code>fid:                    8</code>

<code>       </code><code>key:     </code><code>/text/index</code><code>.html</code>

<code>    </code><code>length:                   15</code>

<code> </code><code>- http:</code><code>//192</code><code>.168.0.46:7500</code><code>/dev2/0/000/000/0000000008</code><code>.fid</code>

<code> </code><code>- http:</code><code>//192</code><code>.168.0.45:7500</code><code>/dev1/0/000/000/0000000008</code><code>.fid</code>

<a href="http://s3.51cto.com/wyfs02/M02/28/6C/wKioL1N5kDKSm8M5AAIFP5jSOZ4098.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M00/28/6C/wKioL1N5kEfyHb5GAAHQ2SleL4s408.jpg" target="_blank"></a>

说明:直接访问mogilefs提供的文件存储路径,访问正常;

结合Nginx,从前端访问测试

<a href="http://s3.51cto.com/wyfs02/M02/28/6C/wKioL1N5kHqRsxb9AAG1O1WVluU610.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M00/28/6C/wKioL1N5kI-Rfe30AAFcrLcKYOM853.jpg" target="_blank"></a>

说明:通过前端Nginx访问图片和文本文件一切正常,实现了对前端访问的透明性;

3.8 后续扩展

结合LNMT的架构,再通过Haproxy进行前端调度,就可以使用MogileFS这个分布式存储系统完全替代NFS,实现对图片文件和文本文件的存储和读写;

鉴于MogileFS的无目录性,无法直接挂载使用,故向mogilefs集群中添加文件则需要程序通过API调用上传(upload)文件,虽然对于运维人员有点不方便,但也保证了一定的高效性;

如果想体验直接挂载使用分布式文件系统的乐趣,则可以尝试使用MooseFS,在此就不多说了!

本文转自 xxrenzhe11 51CTO博客,原文链接:http://blog.51cto.com/xxrenzhe/1413521,如需转载请自行联系原作者