1)MFS 文件系统的组成
2)MFS 读写数据的处理过程
3)MFS 搭建案例环境
4)MFS 搭建过程详解
5)MFS 监控
6)文章总结node
MooseFS是一个具备容错性的网络分布式文件系统。它把数据分散存放在多个物理服务器上,而呈现给用户的则是一个统一的资源。python
独有特征:
一、高可靠(数据的多个拷贝被存储在不一样的计算机上)
二、经过附加新的计算机或者硬盘能够实现容量的动态扩展
三、删除的文件能够根据一个可配置的时间周期进行保留(一个文件系统级别的回收站)
四、不受访问和写入影响的文件连贯快照c++
体系机构
一、管理服务器(master server)
一台管理整个文件系统的独立主机,存储着每一个文件的元数据(文件的大小、属性、位置信息,包括全部很是规文件的全部信息,例如目录、套接字、管道以及设备文件)
二、数据服务器群(chunk servers)
任意数目的商用服务器,用来存储文件数据并在彼此之间同步(若是某个文件有超过一个备份的话)
三、元数据备份服务器(metalogger server)
任意数量的服务器,用来存储元数据变化日志并周期性下载主要元数据文件,以便用于管理服务器意外中止时好接替其位置。
四、访问mfs的客户端
任意数量的主机,能够经过mfsmount进程与管理服务器(接收和更改元数据)和数据服务器(改变实际文件数据)进行交流。vim
MFS 文件系统组成架构图以下:浏览器
1·MFS 读取数据的处理过程:服务器
以下图:网络
2·MFS 写入数据的处理过程:session
以下图:架构
分布式原理:app
分布式文件系统,就是把一些分散的 (分布在局域网内各个计算机上)共享文件夹,集合到一个文件夹内(虚拟共享文件夹)。对于用户来讲,要访问这些共享文件夹时,只要打开它就能够看到全部连接到虚拟共享文件夹内的共享文件夹,用户时感受不到这些时分散各个计算机的。它的好处是:集中访问、简化操做、数据容灾,以及提升文件的存储性能。
案例拓扑图:
此篇文章是使用五台服务器模拟搭建MFS文件系统,以下图:
案例表格:
主机 操做系统 IP 地址 主要软件 Master Server CenOS 7.4 192.168.154.128 mfs-1.6.27-5.tar.gz MetaLogger Server CenOS 7.4 192.168.154.136 mfs-1.6.27-5.tar.gz Chunk Server 1 CenOS 7.4 192.168.154.131 mfs-1.6.27-5.tar.gz Chunk Server 2 CenOS 7.4 192.168.154.132 mfs-1.6.27-5.tar.gz Client CenOS 7.4 192.168.154.130 mfs-1.6.27-5.tar.gz 、 fuse-2.9.2.tar.gz
源码包下载:
MFS 源码包 百度网盘连接 密码:x4v5
部署(Master Server)
1·部署元数据服务器 (Master Server),下载源码包、关闭防火墙、安装依赖包
[root@localhost Y2C]# yum install gcc gcc-c++ zlib-devel -y [root@localhost Y2C]# systemctl stop firewalld.service [root@localhost Y2C]# setenforce 0
2·建立 mfs 管理用户
[root@localhost Y2C]# useradd -s /sbin/nologin -M mfs
3·解压、安装源码包
[root@localhost Y2C]# tar zxvf mfs-1.6.27-5.tar.gz -C /opt/ [root@localhost Y2C]# cd /opt/mfs-1.6.27 [root@localhost mfs-1.6.27]# ./configure \ --prefix=/usr/local/mfs \ #指定安装路径 --with-default-user=mfs \ #指定默认用户为 mfs --with-default-group=mfs \ #指定默认组为 mfs 组 --disable-mfschunkserver \ #关闭 数据存储服务器 --disable-mfsmount #关闭客户端挂载功能 [root@localhost mfs-1.6.27]# make && make install
4·把配置文件模板复制为配置文件
[root@localhost mfs-1.6.27]# cd /usr/local/mfs/etc/mfs [root@localhost mfs]# cp mfsexports.cfg.dist mfsexports.cfg [root@localhost mfs]# cp mfsmaster.cfg.dist mfsmaster.cfg [root@localhost mfs]# cp mfstopology.cfg.dist mfstopology.cfg [root@localhost mfs]# cd /usr/local/mfs/var/mfs [root@localhost mfs]# cp metadata.mfs.empty metadata.mfs
5·以上配置文件无需修改就直接可使用,如今能够启动 Master Server
[root@localhost mfs]# /usr/local/mfs/sbin/mfsmaster start #启动mfs服务 working directory: /usr/local/mfs/var/mfs lockfile created and locked initializing mfsmaster modules ... loading sessions ... file not found if it is not fresh installation then you have to restart all active mounts !!! exports file has been loaded mfstopology: incomplete definition in line: 7 mfstopology: incomplete definition in line: 7 mfstopology: incomplete definition in line: 22 mfstopology: incomplete definition in line: 22 mfstopology: incomplete definition in line: 28 mfstopology: incomplete definition in line: 28 topology file has been loaded loading metadata ... create new empty filesystemmetadata file has been loaded no charts data file - initializing empty charts master <-> metaloggers module: listen on *:9419 master <-> chunkservers module: listen on *:9420 main master server module: listen on *:9421 mfsmaster daemon initialized properly
[root@localhost mfs]# ps -ef | grep mfs #检查服务是否启动 mfs 46007 1 0 11:21 ? 00:00:00 /usr/local/mfs/sbin/mfsmaster start
中止 Master Server 的命令是:[root@localhost mfs]# /usr/local/mfs/sbin/mfsmaster stop
部署 MetaLogger Server。和Master Server是同样的过程
1·下载源码包、关闭防火墙、安装依赖包
[root@localhost Y2C]# yum install gcc gcc-c++ zlib-devel -y [root@localhost Y2C]# systemctl stop firewalld.service [root@localhost Y2C]# setenforce 0
2·建立管理用户、解压、安装源码包
[root@localhost Y2C]# useradd -s /sbin/nologin -M mfs [root@localhost Y2C]# tar zxvf mfs-1.6.27-5.tar.gz -C /opt [root@localhost Y2C]# cd /opt/mfs-1.6.27 [root@localhost mfs-1.6.27]# ./configure \ --prefix=/usr/local/mfs \ --with-default-user=mfs \ --with-default-group=mfs \ --disable-mfschunkserver \ --disable-mfsmount [root@localhost mfs-1.6.27]# make && make install
3·把配置文件模板,复制为配置文件
[root@localhost mfs-1.6.27]# cd /usr/local/mfs/etc/mfs [root@localhost mfs]# cp mfsmetalogger.cfg.dist mfsmetalogger.cfg
4·修改 mfsmetalogger.cfg 配置文件
[root@localhost mfs]# vim mfsmetalogger.cfg 修改内容以下: MASTER_HOST = 192.168.154.128 #这里 IP地址须要指向 Master Server 的 IP地址
5·启动 MfsmetaLogger Server 服务
[root@localhost mfs]# /usr/local/mfs/sbin/mfsmetalogger start [root@localhost mfs]# ps -elf |grep mfs #查看服务是否启动 5 S mfs 41488 1 0 61 -19 - 2967 poll_s 11:46 ? 00:00:00 /usr/local/mfs/sbin/mfsmetalogger start 0 S root 41508 1387 0 80 0 - 28180 - 11:48 pts/0 00:00:00 grep --color=auto mfs
部署 Chunk Server
此文章是两台 Chunk Server 服务器,每台的搭建步骤是相同的 。
1· 下载源码包、关闭防火墙、安装依赖包
[root@localhost Y2C]# systemctl stop firewalld.service [root@localhost Y2C]# setenforce 0 [root@localhost Y2C]# yum install gcc gcc-c++ zlib-devel -y
2·建立管理用户 mfs 、解压、安装源码包
[root@localhost Y2C]# tar zxvf mfs-1.6.27-5.tar.gz -C /opt [root@localhost Y2C]# cd /opt/mfs-1.6.27 [root@localhost mfs-1.6.27]# useradd -s /sbin/nologin -M mfs [root@localhost mfs-1.6.27]# ./configure \ --prefix=/usr/local/mfs \ --with-default-user=mfs \ --with-default-group=mfs \ --disable-mfsmaster \ --disable-mfsmount [root@localhost mfs-1.6.27]# make && make install
3·复制配置文件模板为配置文件
[root@localhost mfs-1.6.27]# cd /usr/local/mfs/etc/mfs [root@localhost mfs]# cp mfschunkserver.cfg.dist mfschunkserver.cfg [root@localhost mfs]# cp mfshdd.cfg.dist mfshdd.cfg
4·修改chunk server 配置文件
[root@localhost mfs]# vim mfschunkserver.cfg 修改内容以下: MASTER_HOST = 192.168.154.128 #须要指向 Master Server 服务器IP地址
[root@localhost mfs]# vim mfshdd.cfg 添加以下内容: /data #这里添加的 /data 是一个给 MFS 的分区,生产环境中最好使用独立的分区或磁盘挂载到此目录
5·建立 /data 目录、给予管理用户权限、启动服务
[root@localhost mfs]# mkdir /data [root@localhost mfs]# chown -R mfs.mfs /data [root@localhost mfs]# /usr/local/mfs/sbin/mfschunkserver start [root@localhost mfs]# netstat -antp | grep mfschunkserve #查看启动状态
部署 Client 客户端
1·另外一台 mfschunk server 安装配置都是相同,这里就再也不重复介绍。如今开始部署 Client 客户端。关闭防火墙、下载源码包、安装依赖包
[root@localhost ~]# systemctl stop firewalld.service [root@localhost ~]# setenforce 0 [root@localhost ~]# yum install gcc gcc-c++ zlib-devel -y
2· 解压 、 安装软件包 fuse
[root@localhost Y2C]# tar zxvf fuse-2.9.2.tar.gz -C /opt #MFS 客户端依赖于 fuse 因此这里须要先安装 fuse 这个包 [root@localhost Y2C]# cd /opt/fuse-2.9.2 [root@localhost fuse-2.9.2]# ./configure [root@localhost fuse-2.9.2]# make && make install
设置环境变量: [root@localhost ~]# vim /etc/profile 加入如下环境变量: export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
加载环境变量配置文件: [root@localhost ~]# source /etc/profile
3·建立管理用户 mfs ,解压 mfs 源码包、安装
[root@localhost Y2C]# useradd -s /sbin/nologin mfs [root@localhost Y2C]# tar zxvf mfs-1.6.27-5.tar.gz -C /opt [root@localhost mfs-1.6.27]# ./configure \ --prefix=/usr/local/mfs \ --with-default-user=mfs \ --with-default-group=mfs \ --disable-mfsmaster \ --disable-mfschunkserver \ --enable-mfsmount #开启客户端挂载功能 [root@localhost mfs-1.6.27]# make && make install
4·建立挂载点、加载内核模块、挂载MFS
[root@localhost mfs-1.6.27]# mkdir /opt/mfs [root@localhost mfs-1.6.27]# modprobe fuse [root@localhost mfs-1.6.27]# /usr/local/mfs/bin/mfsmount /opt/mfs -H 192.168.154.128 # -H 指定元数据服务器 IP地址 mfsmaster accepted connection with parameters: read-write,restricted_ip ; root mapped to root:root
5·查看挂载是否成功:
[root@localhost mfs-1.6.27]# df -h
6· MFS 经常使用操做
MFS 在客户端安装完毕后,会生成 /usr/local/mfs/bin/ 目录,在这个目录下会生成不少命令是用户所须要的,为了方便,能够将 /usr/local/mfs/bin 加入环境变量中
[root@localhost mfs-1.6.27]# vim /etc/profile 加入以下内容: export PATH=/usr/local/mfs/bin:$PATH [root@localhost mfs-1.6.27]# source /etc/profile #从新加载环境变量配置文件
7· mfsgetgoal 命令用来查询文件被复制的分数,利用 -r 命能够对整个目录进行递归,goal 是指文件被复制份数
[root@localhost mfs-1.6.27]# mfsgetgoal -r /opt/mfs /opt/mfs: directories with goal 1 :
8·mfssetgoal 命令用来设置文件被复制的份数,生产环境 Chunk Server 节点数量应该大于2,文件副本数小于等于 Chunk Server 服务器的数量。
[root@localhost mfs-1.6.27]# mfssetgoal -r 2 /opt/mfs /opt/mfs: inodes with goal changed: 1 inodes with goal not changed: 0 inodes with permission denied: 0
[root@localhost mfs-1.6.27]# mfsgetgoal -r /opt/mfs /opt/mfs: directories with goal 2 :
9·建立测试文件
[root@localhost mfs-1.6.27]# cd /opt/mfs [root@localhost mfs]# echo "this is test" > test.txt
Mfscgiserv 是用 python 编写的一个Web 服务器,其监听端口是 9425 ,能够在 Master Server 上经过命令 /usr/local/mfs/sbin/mfscgiserv 来启动,用户利用浏览器就能够全面监控全部客户挂载、chunk server、master server,以及客户端的各类操做等。
在 Master Server 上经过命令 /usr/local//mfs/sbin/mfscgiserv 启动监控,经过浏览器访问
http://192.168.154.128:9425/mfs.cgi 。以下图:
下表是对 MFS 监控 的含义说明:
功能 含义 Info 显示 MFS 的基本信息 Servers 列出现有 Chunk Server Disks 列出现有 Chunk Server 的硬盘信息 Exports 列出可被挂载的目录 Mounts 列出被挂载的目录 operations 显示正在执行的操做 Resources 列出当前存储信息 Quotas 列出当前配额信息 Master Charts 显示Master Server的操做状况。如:读、写 Server Charts 显示 Chunk server 的操做状况。数据传输率及系统状态