设为首页 收藏本站
查看: 897|回复: 0

[经验分享] Mogilefs介绍与安装步骤

[复制链接]

尚未签到

发表于 2019-2-1 07:14:04 | 显示全部楼层 |阅读模式
  

MogileFS简介:
MogileFS是一个开源的分布式文件存储系统,由LiveJournal旗下的Danga Interactive公司开发。Danga团队开发了包括 Memcached、MogileFS、Perlbal 等多个知名的开源项目。目前使用MogileFS 的公司非常多,如日本排名先前的几个互联公司及国内的yupoo(又拍)、digg、豆瓣、1号店、大众点评、搜狗和安居客等,分别为所在的组织或公司管理着海量的图片。

MogileFS特性
    1   工在于应用层
    2   无单点,三大组件(tracker,mogstore,database)皆可实现高可用;
    3   自动完成文件复制,制的最小单位不是文件,而是class;基于不同的class,文件可以被自动的复制到多个有足够存储空间的存储节点上;
    4   传输无需特殊协议,可以通过NFS或HTTP协议进行通信;
    5   名称安间简单,文件通过一个给定的key来确定,是一个全局的命名空间;没有目录,基于域实现文件隔离;
    6   不共享任何数据,每个存储节点只需维护自己所属的存储设备(device)即可;


MogileFS由部分组成:
  (1) server:主要包括mogilefsd和mogstored两个应用程序。
    mogilefsd实现的是tracker,它通过数据库来保存元数据信息,包括站点domain、class、host等;
    mogstored是存储节点(store node),它其实是个WebDAV服务,默认监听在7500端口,接受客户端的文件存储请求。
  (2) utils(工具集):主要是MogileFS的一些管理工具,例如mogadm等。
    在MogileFS安装完后,要运行mogadm工具将所有的store node注册到mogilefsd的数据库里,mogilefsd会对这些节点进行管理和监控。
  (3) 客户端API:MogileFS的客户端API很多,例如Perl、PHP、Java、Python等,用这个模块可以编写客户端程序,实现文件的备份管理功能等。


存储主机(节点)
    这个是 MogileFS 存储文件存放在这些机器上,也是 mogstored 节点,也叫 Storage Server,一台存储主要都要启动一个 mogstored 服务.扩容就是增加这些机器.


设备(device)
    一个存储节点,以就是上面的主机,可以有多个 device, 就是用来存放文件的目录(例如挂载的目录),每个设备都有一个设备id,需要在 mogstored 的配置文件中的 docroot 配置的项目 指定的目录下面创建相应的设备的目录,目录名为 $docroot/dev$id,设备是不能删除的.只能将其设备的状态的值置为dead,当一个设备 dead 之后,就真的 dead了,里面的数据也无法恢复了,且这个dead了的设备的 id 也不能再用.

  




安装Mogilefs简单步骤:

准备环境:

1.创建3台centos6.7服务器。其中1台装有mariadb5.5.47版本数据库。两外两台做 mogstored节点。

先安装epel源,解决安装时依赖关系。


1.    配置146,tracker+mysql配置
准备安装包:

root@localhost mogilefs]# ll
total 636
-rw-r--r--. 1 root root   1916 Jan  9 03:57 MogileFS-Server-2.46-2.el6.noarch.rpm
-rw-r--r--. 1 root root 176308 Jan  9 03:57 MogileFS-Server-mogilefsd-2.46-2.el6.noarch.rpm
-rw-r--r--. 1 root root  26872 Jan  9 03:57 MogileFS-Server-mogstored-2.46-2.el6.noarch.rpm
-rw-r--r--. 1 root root  75916 Jan  9 03:57 MogileFS-Utils-2.19-1.el6.noarch.rpm
-rw-r--r--. 1 root root   5880 Jan  9 03:57 Perlbal-1.78-1.el6.noarch.rpm
-rw-r--r--. 1 root root   1624 Jan  9 03:57 Perlbal-doc-1.78-1.el6.noarch.rpm
-rw-r--r--. 1 root root  30312 Jan  9 03:57 perl-MogileFS-Client-1.14-1.el6.noarch.rpm
-rw-r--r--. 1 root root  25140 Jan  9 03:57 perl-Net-Netmask-1.9015-8.el6.noarch.rpm
-rw-r--r--. 1 root root 268620 Jan  9 03:57 perl-Perlbal-1.78-1.el6.noarch.rpm

2.安装
yum --nogpgcheck localinstall *.rpm




3.检查配置
[root@localhost ~]# rpm -ql MogileFS-Server          #象征性的文档
(contains no files)
[root@localhost ~]# rpm -ql MogileFS-Server-mogilefsd
/etc/mogilefs/mogilefsd.conf        #主配置文件
/etc/rc.d/init.d/mogilefsd
/usr/bin/mogdbsetup                 #数据库初始化工具
/usr/bin/mogilefsd                  #守护进程对应的主文件
/usr/share/man/man1/mogilefsd.1.gz
/usr/share/man/man3/MogileFS::Checksum.3pm.gz
/usr/share/man/man3/MogileFS::Class.3pm.gz
/usr/share/man/man3/MogileFS::DevFID.3pm.gz
/usr/share/man/man3/MogileFS::Device.3pm.gz
/usr/share/man/man3/MogileFS::Domain.3pm.gz
/usr/share/man/man3/MogileFS::FID.3pm.gz
/usr/share/man/man3/MogileFS::Factory.3pm.gz
/usr/share/man/man3/MogileFS::Host.3pm.gz
/usr/share/man/man3/MogileFS::IOStatWatcher.3pm.gz
/usr/share/man/man3/MogileFS::Overview.3pm.gz


4.配置远程用户:

远程配置mysql用户:with grant option 选项表示允许该用户有权限授权其他用户。

  
MariaDB [(none)]> GRANT ALL ON *.* TO 'root'@'192.168.%.%' IDENTIFIED BY '123..com' WITH GRANT OPTION;
MariaDB [(none)]> flush privileges;


  

5.初始化配置:
  
[root@localhost mogilefs]# mogdbsetup --help
Usage: mogdbsetup [opts] Options:                   Default      Description                  ============ =========================================== --verbose                Be verbose about what's happening.  --dbhost=        localhost    hostname or IP to database server.  --dbport=        dbd default  port number to database server.  --dbname=        mogilefs     database name to create/upgrade.  --dbrootuser=    root         Database administrator username.  Only needed                               for initial setup, not subsequent upgrades.  --dbrootpass=          Database administrator password.  Only needed                               for initial setup, not subsequent upgrades.  --dbuser=        mogile       Regular database user to create and/or use                               for MogileFS database.  This is what the                               mogilefsd trackers connect as.  --dbpass=              You should change this, especially if your                               database servers are accessible to other users                               on the network.  But they shouldn't be                               if you're running MogileFS, because MogileFS                               assumes your network is closed.   --type=         MySQL        Which MogileFS::Store implementation to use.                               Available: MySQL, Postgres   --yes                        Run without questions. [root@localhost mogilefs]#


配置用户:

[root@localhost mogilefs]# mogdbsetup --dbhost=192.168.1.146 --dbrootuser=root --dbrootpass=123..com --dbname=mogdb --dbuser=moguser --dbpass=mogpass
This will attempt to setup or upgrade your MogileFS database.
It won't destroy existing data.
Run with --help for more information.  Run with --yes to shut up these prompts.
Continue? [N/y]: y
Create/Upgrade database name 'mogdb'? [Y/n]: y
Grant all privileges to user 'moguser', connecting from anywhere, to the mogilefs database 'mogdb'? [Y/n]: y
[root@localhost mogilefs]#


  

此时数据库有创建好的mogdb:

MariaDB [mogdb]> show tables;
+----------------------+
| Tables_in_mogdb      |
+----------------------+
| checksum             |
| class                |
| device               |
| domain               |
| file                 |
| file_on              |
| file_on_corrupt      |
| file_to_delete       |
| file_to_delete2      |
| file_to_delete_later |
| file_to_queue        |
| file_to_replicate    |
| fsck_log             |
| host                 |
| server_settings      |
| tempfile             |
| unreachable_fids     |
+----------------------+
17 rows in set (0.00 sec)
MariaDB [mogdb]>


5.编辑配置文件:先复制一份,良好的习惯。
# Enable daemon mode to work in background and use syslog
daemonize = 1
# Where to store the pid of the daemon (must be the same in the init script)
pidfile = /var/run/mogilefsd/mogilefsd.pid
# Database connection information
db_dsn = DBI:mysql:mogdb:host=192.168.1.146
db_user = moguser
db_pass = mogpass
# IP:PORT to listen on for mogilefs client requests
listen = 192.168.1.146:7001
# Optional, if you don't define the port above.
conf_port = 7001
# Number of query workers to start by default.
query_jobs = 10
# Number of delete workers to start by default.
delete_jobs = 2
# Number of replicate workers to start by default.
replicate_jobs = 5
# Number of reaper workers to start by default.
# (you don't usually need to increase this)
reaper_jobs = 1


配置完成,启动服务:

[root@localhost mogilefs]# service mogilefsd start
Starting mogilefsd                                         [  OK  ]
[root@localhost mogilefs]# ss -tnl
State      Recv-Q Send-Q              Local Address:Port                Peer Address:Port
LISTEN     0      50                              *:3306                           *:*     
LISTEN     0      128                            :::22                            :::*     
LISTEN     0      128                             *:22                             *:*     
LISTEN     0      128                 192.168.1.146:7001                           *:*     
LISTEN     0      100                           ::1:25                            :::*     
LISTEN     0      100                     127.0.0.1:25                             *:*     
[root@localhost mogilefs]#


6.配置109,101两个节点:


安装方法同上面,注需要单独安装

yum -y install perl-IO-AIO


打开配置文件:

[root@localhost ~]# vim /etc/mogilefs/mogstored.conf
maxconns = 10000     #最大并发连接数
httplisten = 0.0.0.0:7500         #http协议
mgmtlisten = 0.0.0.0:7501     #tracter来监测mogstored健康状态的
docroot = /mogstore            #数据存放目录,一般是新磁盘挂在目录


两个节点准备一个文件目录来存放数据,这里直接使用系统根下创建:

节点2:mkdir /var/mogdata/dev1 -p
节点3:mkdir /var/mogdata/dev2 -p
[root@localhost mogstore]# chown -R mogilefs.mogilefs /mogstore/   #一定要将目录属主,属组改为mogilefs,否则无法识别不能认到。

  

配置mogstored.conf,另外一个节点配置相同:


maxconns = 10000
httplisten = 0.0.0.0:7500
mgmtlisten = 0.0.0.0:7501
docroot = /mogstore


配置好后启动,另外一个节点相同:
[root@localhost dev1]# service mogstored start
Starting mogstored                                         [  OK  ]
[root@localhost dev1]#
[root@localhost dev1]# ss -tnl
State      Recv-Q Send-Q              Local Address:Port                Peer Address:Port
LISTEN     0      128                            :::22                            :::*   
LISTEN     0      128                             *:22                             *:*   
LISTEN     0      64                             :::23                            :::*   
LISTEN     0      100                           ::1:25                            :::*   
LISTEN     0      100                     127.0.0.1:25                             *:*   
[root@localhost dev1]#


7.确保两个节点加入到当前集群中:
  
在节点1利用管理工具mogadm 来管理节点,首先检查是否正常,并且用查看命令看一下:

  
[root@localhost dev1]# mogadm --trackers=192.168.1.146:7001 check
Checking trackers...
  192.168.1.146:7001 ... OK
Checking hosts...
No devices found on tracker(s).
[root@localhost dev1]#


详细的查看命令:
[root@localhost dev1]# mogstats --db_dsn="DBI:mysql:mogdb:host=192.168.1.146" --db_user="moguser" --db_pass="mogpass" --stats="all"
Fetching statistics... (all)
Statistics for devices...
  device     host                   files     status
  ---------- ---------------- ------------ ----------
  ---------- ---------------- ------------ ----------
Statistics for file ids...
  Max file id: none
Statistics for files...
  domain               class           files    size (m)  fullsize (m)
  -------------------- ----------- ---------- ----------- -------------
  -------------------- ----------- ---------- ----------- -------------
Statistics for replication...
  domain               class        devcount      files
  -------------------- ----------- ---------- ----------
  -------------------- ----------- ---------- ----------
Statistics for replication queue...
  status                      count
  -------------------- ------------
  -------------------- ------------
Statistics for delete queue...
  status                      count
  -------------------- ------------
  -------------------- ------------
Statistics for general queues...
  queue           status                      count
  --------------- -------------------- ------------
  --------------- -------------------- ------------
done
[root@localhost dev1]#
mogstats --db_dsn=驱动:数据库类型:数据库名字:数据库地址:用户名:密码 --stats状态



添加host主机:
[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 host list
192.168.1.109 [1]: alive  IP:       192.168.1.109:7500
[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 host add 192.168.1.101 --ip=192.168.1.101 --status=alive
[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 host list192.168.1.109 [1]: alive  IP:       192.168.1.109:7500
192.168.1.101 [2]: alive
  IP:       192.168.1.101:7500
[root@localhost mogilefs]#


查看一下节点
现在还没有任何主机集群中:

[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 device list
192.168.1.109 [1]: alive                    used(G)    free(G)   total(G)  weight(%)
192.168.1.101 [2]: alive
                    used(G)    free(G)   total(G)  weight(%)
[root@localhost mogilefs]#


添加目录:
[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 device add 192.168.1.109
1
[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 device add 192.168.1.101 2
[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 device list
192.168.1.109 [1]: alive
                    used(G)    free(G)   total(G)  weight(%)
   dev1:   alive      2.315     13.975     16.290        100
192.168.1.101 [2]: alive
                    used(G)    free(G)   total(G)  weight(%)
   dev2:   alive      2.081     15.384     17.465        100
[root@localhost mogilefs]#


添加domain:
[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 domain add images[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 domain add conffilles[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 domain list domain               class                mindevcount                replpolicy   hashtype-------------------- -------------------- ------------- ------------ ------- conffilles           default          #复制数量   2        MultipleHosts() NONE    images               default                   2                       MultipleHosts() NONE   [root@localhost mogilefs]#
添加class:
[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 class add images nc1 --mindevcount=2[root@localhost mogilefs]# mogadm --trackers=192.168.1.146:7001 class list domain               class                mindevcount   replpolicy   hashtype-------------------- -------------------- ------------- ------------ ------- conffilles           default                   2        MultipleHosts() NONE    images               default                   2        MultipleHosts() NONE    images               nc1                       2        MultipleHosts() NONE   [root@localhost mogilefs]#


到此配置基本完成。



测试一下上传图片:



[root@localhost ~]# mogupload --trackers=192.168.1.146:7001 --domain=images --key='1.jpg' --file='/root/1.jpg'



在109节点能看到:



[root@localhost dev1]# tree
.
├── 0
│   └── 000
│       └── 000
│           └── 0000000002.fid     #图片文件




或者在本机通过info命令能查到

[root@localhost ~]# mogfileinfo --trackers=192.168.1.146:7001 --domain=images --key='1.jpg'
- file: 1.jpg
     class:              default
  devcount:                    2
    domain:               images
       fid:                    2
       key:                1.jpg
    length:               419640
-
   #可以通过url能直接访问
- http://192.168.1.109:7500/dev1/0/000/000/0000000002.fid
[root@localhost ~]#


  


  

  

  但是这样看图片是不是不方便,可以用nginx+模块实现
  



二.在以上环境实现高可用,三台服务器同时为tracker 和storage
复制tracker的配置文件到另外两台storage服务器:
[root@localhost ~]# scp /etc/mogilefs/mogilefsd.conf 192.168.1.109:/etc/mogilefs/
[root@localhost ~]# scp /etc/mogilefs/mogilefsd.conf 192.168.1.101:/etc/mogilefs/


将1.146创建个目录:/mogstore,然后修改属主,属组:

  root@localhost mogstore]# chown -R mogilefs.mogilefs /mogstore/
[root@localhost mogstore]# mogadm --tracker=192.168.1.146:7001 host add 192.168.1.146 --ip=192.168.1.146 --status=alive
[root@localhost mogstore]# mogadm --tracker=192.168.1.146:7001 host list
192.168.1.109 [1]: alive
  IP:       192.168.1.109:7500
192.168.1.101 [2]: alive
  IP:       192.168.1.101:7500
192.168.1.146 [3]: alive
  IP:       192.168.1.146:7500
[root@localhost mogstore]#[root@localhost mogstore]# ss -tnl
State      Recv-Q Send-Q       Local Address:Port         Peer Address:Port
LISTEN     0      50                       *:3306                    *:*     
LISTEN     0      128                      *:7500                    *:*     
LISTEN     0      128                      *:7501                    *:*     
LISTEN     0      128                     :::22                     :::*     
LISTEN     0      128                      *:22                      *:*     
LISTEN     0      128          192.168.1.146:7001                    *:*     
LISTEN     0      100                    ::1:25                     :::*     
LISTEN     0      100              127.0.0.1:25                      *:*     
[root@localhost mogstore]#[root@localhost mogstore]# mogadm --tracker=192.168.1.146:7001 device add 192.168.1.146 3
[root@localhost mogstore]# mogadm --tracker=192.168.1.146:7001 device list
192.168.1.109 [1]: alive
                    used(G)    free(G)   total(G)  weight(%)
   dev1:   alive      2.317     13.973     16.290        100
192.168.1.101 [2]: alive
                    used(G)    free(G)   total(G)  weight(%)
   dev2:   alive      2.083     15.382     17.465        100
192.168.1.146 [3]: alive
                    used(G)    free(G)   total(G)  weight(%)
   dev3:   alive      1.607     15.857     17.465        100
[root@localhost mogstore]#
将109,101两个节点修改:

将listen端口改为任意,然后启动:

  # IP:PORT to listen on for mogilefs client requests
  listen = 0.0.0.0:7001
  

[root@localhost dev1]# ss -tnl
State       Recv-Q Send-Q                                                     Local Address:Port                                                       Peer Address:Port
LISTEN      0      128                                                                    *:7500                                                                  *:*     
LISTEN      0      128                                                                    *:7501                                                                  *:*     
LISTEN      0      128                                                                   :::22                                                                   :::*     
LISTEN      0      128                                                                    *:22                                                                    *:*     
LISTEN      0      64                                                                    :::23                                                                   :::*     
LISTEN      0      128                                                                    *:7001                                                                  *:*     
LISTEN      0      100                                                                  ::1:25                                                                   :::*     
LISTEN      0      100                                                            127.0.0.1:25                                                                    *:*     
[root@localhost dev1]#  

  101也同样配置并且启动,这样3个节点变为高可用了。
  




         




  



附件:http://down.运维网.com/data/2367273


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-670196-1-1.html 上篇帖子: Linux自学笔记——mogilefs 下篇帖子: mogilefs概述
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表