深入浅出分布式文件系统MogileFS集群
一,简介
MogileFS是一款开源的分布式文件存储系统,由LiveJournal旗下的Danga Interactive公司开发。Danga团队开发了包括 Memcached、MogileFS、Perlbal 等多个知名的开源项目。目前MogileFS的日益成熟使用此解决方法的公司越来越多,例如日本的又拍、digg、中国的豆瓣、1号店、大众点评、搜狗和安居客等,分别为所在的组织或公司管理着海量的图片。和传统网络存储不一样的是分布式文件系统是将数据分散存储至多台服务器上,而网络文件系统往往是将所有的数据存放在一起,存储服务器将成为系统可用性的瓶颈,不能满足大规模的存放所有数据需求。分布式文件系统采用可扩展的系统结构,利用多台存储设备分别存储,分担服务器负荷,利用位置服务器定位存储信息,因此不仅能够提升系统性能同时还易于扩展。
二、实现组件
MogileFS主要有三个部分组成:
①server端,包括两个部分,mogilefsd和mogstored两个应用程序,tracker是mogilefsd的实现方式,它通过数据库来保证元数据信息,比如站点的domian、class、host等,mogstored则为存储节点,默认监听7500端口,接受客服端的文件存储请求,在MogileFS安装完后,要运行mogadm工具将所有的store node注册到mogilefsd的数据库里,mogilefsd会对这些节点进行管理和监控。
②utils工具集,主要是MogileFS的一些管理工具如mogadm等。
③客服端API,MogileFS的API接口很多,常用的的时间方式有php,perl,python,java等,使用这些语言可进行编写客服端程序,实现文件的备份管理功能。
三、MogileFS的特性及原理
MogileFS特性:
1.应用层服务,不需要使用和兴组件
2.无单点故障,tracker为跟踪点,mogstored为存储节点,mysql为储存元数据节点,建议使用MySQL做高可用
3.传输中立,无特殊协议,可用通过nfs和http实现通信
4.简单的命名空间,没有目录,直接存储在存储空间上,通过域来实现,不共享任何数据
MogileFS工作原理:MogileFS主要由mogilefsd和mogstored两应用程序提供服务,tracker节点借助数据库保存各个节点文件的元数据信息,保存每个域中所哟的存储位置分布,用于实现快速定位同时监控各个节点,通知客户端存储区域位置并指挥storaged节点复制数据副本,进程名为mogilefsd监听与7001端口。storage节点为实际存放文件的地方,存储节点可以是http服务器,及其其他web服务,storage节点可自动维护键值的对应关系,storage节点前端可使用nginx进行反代,此时需要nginx-mogilefs-module-master模块,此服务监听与7501端口,进程名为mogstored.一个域中的键值是唯一的,一个mogilefs可以有多个域,域可以有多个存储设备,每个设备都有数据的容器,称之为domain.每个存储节点为一个主机(host),一个主机上可以有多个存储设备,每个设备有id号,用来定位。复制的最小单元为class,文件属性管理,定义文件存储在不同的设备上的份数。
四、MogileFS安装及其配置实现
安装说明:此实验可以仅适用两台服务进行,一台服务即当做server端,又当做存储节点同时还是mysql服务器,在每台服务器上部署tracker管理并监控节点。
#在两服务器上均安装如下rpm包 yum -y install per-IO-AIO #mogilefsd和mogstored依赖于此包,先解决依赖关系。 yum -y install MogileFS-Server-2.46-2.el6.noarch.rpm #安装sever端 yum -y install MogileFS-server-mogilefsd-2.46-2.el6.noarch.rpm #安装mogilefsd yum -y install MogileFS-Server-mogstored-2.46-2.rl6.noarch.rpm #安装mogstored
创建数据库及授权修改相应的配置文件
grant all privileges on mogdb.* to 'moguser'@'127.0.0.1' identified by 'pass'; grant all privileges on mogdb.* to 'moguser'@'localhost' identified by 'pass'; flush privileges; #修改mogilefsd.conf配置文件 # 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=127.0.0.1 #修改为上面授权的账号密码及其主机 db_user = moguser #修改为上面授权的账号密码及其主机 db_pass = pass #修改为上面授权的账号密码及其主机 # IP:PORT to listen on for mogilefs client requests listen = 0.0.0.0: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 = 1 # 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 # Number of fsck workers to start by default. # (these can cause a lot of load when fsck'ing) #fsck_jobs = 1 # Minimum amount of space to reserve in megabytes # default: 100 # Consider setting this to be larger than the largest file you # would normally be uploading. #min_free_space = 200 # Number of seconds to wait for a storage node to respond. # default: 2 # Keep this low, so busy storage nodes are quickly ignored. #node_timeout = 2 # Number of seconds to wait to connect to a storage node. # default: 2 # Keep this low so overloaded nodes get skipped. #conn_timeout = 2 # Allow replication to use the secondary node get port, # if you have apache or similar configured for GET's #repl_use_get_port = 1 #mogstored配置文件,一般无需修改,自行根据业务需求做决定 maxconns = 10000 httplisten = 0.0.0.0:7500 mgmtlisten = 0.0.0.0:7501 docroot = /data/mogstored#将上诉配置考别一份至其他主机,并且启动服务,安装后默认在Init.d下有启动脚本 service mogilefsd start service mogstored start [root@centos6 mogilefs]# ss -tnl |grep *.7.* #默认mogilefsd监听7001,mogstored监听7501及其7501 LISTEN 0 128 *:7500 *:* LISTEN 0 128 *:7501 *:* LISTEN 0 128 *:7001 *:* [root@node mogilefs]# #设置数据库,存储元数据 mogdbsetup --dbhost=127.0.0.1 --dbpass=pass mogdbsetup --dbname=mogdb --dbuser=moguser --dbhost=127.0.0.1 --dbpass=pass mogadm host add 10.1.100.1 --ip=10.1.100.1 --port=7500 --status=alive #添加host,storaged mogadm domain add files #添加域 mogadm domain add p_w_picpaths [root@centos6 ~]# mogstats --db_dsn="DBI:mysql:mogdb:host=localhost" --db_user="moguser" --db_pass="pass" --stats="all" Fetching statistics... (all)Statistics for devices... #表示此storage设备存活 device host files status---------- ---------------- ------------ ----------dev1 10.1.100.1 2 alive dev3 10.1.100.2 1 alivedev4 10.1.100.2 1 alive---------- ---------------- ------------ ----------Statistics for file ids...Max file id: 9Statistics for files... #添加的域显示结果domain class files size (m) fullsize (m)-------------------- ----------- ---------- ----------- -------------files default 1 0 0p_w_picpaths default 1 0 0-------------------- ----------- ---------- ----------- -------------Statistics for replication... #默认的类示结果domain class devcount files-------------------- ----------- ---------- ----------files default 2 1p_w_picpaths default 2 1-------------------- ----------- ---------- ----------Statistics for replication queue...status count-------------------- -------------------------------- ------------Statistics for delete queue...status count-------------------- -------------------------------- ------------Statistics for general queues...queue status count--------------- -------------------- --------------------------- -------------------- ------------done [root@node ~]# [root@node~]# mogupload --trackers=10.1.100.1 --domain=files --key='/issue' --file='/etc/issue' #上传文件至files域内,指明可Key和上传的文件目录 [root@node ~]# moglistkeys --trackers=10.1.100.1 --domain=files #显示域内文件 /fstab.txt /issue [root@node ~]# mogfetch --trackers=10.1.100.1 --domain=files --key='/issue' --file='/tmp/issue' #下载域内文件至某目录 [root@node ~]# ll /tmp/issue -rw-r--r--. 1 root root 47 11月 25 16:48 /tmp/issue -bash: ogfileinfo: command not found [root@node2 ~]# mogfileinfo --tracker=10.1.100.1 --domain=files --key='/fstab.txt' - file: /fstab.txtclass: defaultdevcount: 2domain: filesfid: 5key: /fstab.txtlength: 1115-http://10.1.100.2:7500/dev4/0/000/000/0000000005.fid #可通过此URL访问到相应的资源-http://10.1.100.1:7500/dev1/0/000/000/0000000005.fid #可通过此URL访问到相应的资源 [root@node2 ~]#
实验结果图示:
五、实战nginx前端反代mogfilefs及负载均衡
要求说明:在前期那配置nginx做反代将用户的请求调度至后端的MogileFS,此实验依赖于nginx-mogilefs-module模块,需在编译时加上此模块。
#实战配置如下所示: #user nobody; worker_processes 1;#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024; }http {include mime.types;default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;#upstream mogtrackers { #定义一个upstream组server 10.1.100.1:7001;server 10.1.100.2:7001;}server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}location /p_w_picpaths/ {mogilefs_tracker mogtrackers; #在此调用此mogtrackers即可实现反代至mogilefs后端mogilefs_domain p_w_picpaths; #域为p_w_picpaths域 mogilefs_methods get; #请求的方法为getmogilefs_pass {proxy_pass $mogilefs_path;proxy_hide_header Content-Type;proxy_buffering off;}expires 1h;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}
图示:此时可通过http://uri/p_w_picpaths/aqua.jpg进行访问,而不是原来很长的路径名进行访问。
总结:在大型站点中,mogilefs的重要性不言而喻,尤其是图片存储量很大的网站例如:某宝,某东等,此配置过程中,mysql易于成为单点故障,所以可将其做主从复制,同时结合MySQL半同步复制,可降低数据的丢失风险。在配置nginx做反向代理时,大部分步骤和其他反代类是不同的是,需将模块编译进nginx中才能使用此模块功能。
转载于:https://blog.51cto.com/purify/1878002
深入浅出分布式文件系统MogileFS集群相关推荐
- fastdfs原理_搭建分布式文件系统FastDFS集群
本文摘选abcdocker运维博客 abcdocker运维博客 – 专注DevOps自动化运维,传播优秀it运维技术文章i4t.com 在生产环境中往往数据存储量比较大,因此会大部分会选择分布式存储 ...
- 分布式文件系统FastDFS集群搭建
一.集群规划 服务器名称 IP地址 fastdsf-tracker1 192.168.0.250 fastdsf-tracker2 192.168.0.251 fastdfs-storage1-gro ...
- 分布式文件存储系统-集群管理
这篇文章比预期来的要晚一点,第一遍接近完成时,脑子一热去清理了一下草稿箱,然后右手一抖就把它给删了,然后又不得不来第二遍....这个时候分布式备份就显得尤为重要!!! 言归正传,本文对分布式文件系统的 ...
- 18_clickhouse副本同步与高可用功能验证,分布式表与集群配置,数据副本与复制表,ZooKeeper整合,创建复制表,副本同步机制,数据原子写入与去重,负载平衡策略,案例(学习笔记)
24.副本同步与高可用功能验证 24.1.分布式表与集群配置 24.2.数据副本与复制表 24.3.ZooKeeper整合 24.4.创建复制表 24.5.副本同步机制 24.6.数据原子写入与去重 ...
- docker 分布式管理群集_Coolpy7分布式物联网MQTT集群搭建
Coolpy7分布式技术,支持多个Coolpy7 Core提供跨数据中心(多活)模式组建群集,支持群集零手动维护(基于Gossip分布式协议作为群集节点状态维护).Coolpy7从版本号V7.3.2. ...
- 部署Ceph分布式高可用集群中篇
前言 如何快速部署Ceph分布式高可用集群 Ceph分布式存储底层实现原理 上文介绍了ceph的原理以及ceph的部署(部署了一个mon角色)本文继续介绍下ceph的部署 部署OSD 查看磁盘使用情况 ...
- 分布式架构和集群架构的区别
目录 1.分布式架构 2.集群架构 1.分布式架构 分布式架构是每个服务器都是运行不同的程序,提供的功能不一样,相互协作形成一个完整的生态,再对外提供服务,各个服务器之间有存在相互通信调用的情况,架构 ...
- 服务器分布式部署和集群部署的区别
服务器分布式部署和集群部署的区别 1.分布式部署 分布式是以缩短单个任务的执行时间来提升效率的:分布式是将不同的业务分布在不同的地方: 2.集群部署 集群是将几台服务器集中在一起,实现同一业务:集群是 ...
- Hadoop的三种模式(单机模式,伪分布式,完全分布式)以及集群的搭建
基本概念: 1. Hadoop是一个分布式文件系统的基础架构,用户可以利用集群进行高速运算和存储 2. Hadoop实现了一个分布式文件系统(Hadoop Distributed File Syste ...
最新文章
- Spark _24 _读取JDBC中的数据创建DataFrame/DataSet(MySql为例)(三)
- Android多线程优劣,Android 开发中用到的几个多线程解析
- 基于阈值的损失函数_推荐 :常见损失函数和评价指标总结(附公式amp;代码)...
- Learning to rank 特征抽取
- treelistview 所有节点失去焦点_球天下-儿皇梦只是一厢情愿 皇马已失去对博格巴的兴趣...
- 微软发布 Win11新补丁
- 欧瑞变频器800参数设置_ACS800系列变频器的参数及设置
- php使用redis实例,php中使用redis队列操作实例代码
- oracle sqldeveloper 115网盘 提取码
- 盘点python socket 中recv函数的坑
- 三校生计算机教学计划,三校生高考英语教学计划.doc
- 关于msp430的BSL下载
- Frenet坐标系与Cartesian坐标系互转(二):Python代码函数实现
- 毕业设计源码之“油价”小程序
- 自己写的基金投资分析系统,这只基你们觉得怎么样?
- 如何减少城市拥堵?——虹科利用激光雷达技术实现智能交通
- LeetCode 2315. 统计星号
- 无穷级数的简单求解方法——高等数学
- Qno技术:支持网吧业务目标持续推进——FVR9000系列网吧解决方案(转)
- 乘风广告联盟系统 v6.2