- MFS是什么
MFS
全称MooseFS
,是文件管理系统的抽象层,将用户的数据通过master
之后,存储在多个网络存储节点上面,这个过程对于用户来说时透明的,并且MFS
具有很强大的网络容错能力;- MFS的特性
- 1.是一个通用的文件系统,不需要商城应用软件提供接口,直接可以进行使用;
- 2.允许在线扩容,伸缩性强大;
- 3.可以设置任意文件的冗余程度,并且不会影响读/写性能;
- 4.可以在执行事件内恢复误删除的文件;
- 5.提供快照功能;
- 6.提供方便的管理界面
- MFS的文件系统结构
managing server
:也就是master
,用于负责各个数据存储服务器的管理,文件读写调度,文件空间回收,文件误删除恢复,多节点数据拷贝等;Metalogger Server
:负责备份master
服务器上面特殊的日志文件,用于确保master
故障时,进行接管操作,类似于ext3
之后支持的日志文件系统的日志作用,文件格式通常为changelog_ml.*.mfs
;Chunk Server
:数据存储服务器,受管理服务器调度,提供实际的数据存储服务,并且在管理服务器的调度下,完成对于数据的操作client computers
:客户端使用透明的存储方式,完全和本地文件系统一样的使用;
- MFS结构图
- 配置小范围的MFS分布式存储系统
服务的规划
Client: server6.com 172.25.23.6
Master: server7.com 172.25.23.7
Metalogger: server8.com 172.25.23.8
Chunkserver: server9.com 172.25.23.9 sever10.com 172.25.23.10
首先禁用可能影响实验的因素
- 这里使用跳板机的原理来在各个节点上面执行相同的命令
[root@my Desktop]# for I in {6,7,8,9,10};do echo server$I.com; ssh 172.25.23.$I '/etc/init.d/iptables stop';setenforce 0; done
server6.com
X11 forwarding request failed on channel 0
server7.com
X11 forwarding request failed on channel 0
server8.com
X11 forwarding request failed on channel 0
server9.com
X11 forwarding request failed on channel 0
server10.com
X11 forwarding request failed on channel 0
- 因为需要在多个节点上面进行配置,所以这里制作成为
rpm
软件包来进行安装,软件包的制作,后面会单独说明
[root@server7 mnt]# yum install gcc make rpm-build fuse-devel zlib-devel rpm-build -y
[root@server7 mnt]# yum install libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm libpcap-devel-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm -y
[root@server7 mnt]# ln -sv moosefs-3.0.80-1.tar.gz moosefs-3.0.80.tar.gz
[root@server7 mnt]# rpmbuild -tb moosefs-3.0.80.tar.gz
- 制作生成了这些软件包
[root@server7 mnt]# ls /root/rpmbuild/RPMS/x86_64/
moosefs-cgi-3.0.80-1.x86_64.rpm moosefs-client-3.0.80-1.x86_64.rpm
moosefs-cgiserv-3.0.80-1.x86_64.rpm moosefs-master-3.0.80-1.x86_64.rpm
moosefs-chunkserver-3.0.80-1.x86_64.rpm moosefs-metalogger-3.0.80-1.x86_64.rpm
moosefs-cli-3.0.80-1.x86_64.rpm moosefs-netdump-3.0.80-1.x86_64.rpm
- 在
master
节点上面安装
[root@server7 x86_64]# rpm -ivh moosefs-cgi-3.0.80-1.x86_64.rpm moosefs-cgiserv-3.0.80-1.x86_64.rpm moosefs-cli-3.0.80-1.x86_64.rpm moosefs-master-3.0.80-1.x86_64.rpm moosefs-netdump-3.0.80-1.x86_64.rpm
Preparing... ########################################### [100%]
1:moosefs-cgi ########################################### [ 20%]
2:moosefs-cgiserv ########################################### [ 40%]
3:moosefs-netdump ########################################### [ 60%]
4:moosefs-master ########################################### [ 80%]
5:moosefs-cli ########################################### [100%]
- 复制给元数据节点,用于进行备份
[root@server7 x86_64]# scp moosefs-metalogger-3.0.80-1.x86_64.rpm 172.25.23.8:/mnt/
- 复制给存储节点,用于数据管理
[root@server7 x86_64]# scp /mnt/libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm moosefs-chunkserver-3.0.80-1.x86_64.rpm 172.25.23.9:/mnt/
[root@server7 x86_64]# scp /mnt/libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm moosefs-chunkserver-3.0.80-1.x86_64.rpm 172.25.23.10:/mnt/
- 然后再
chunk server 上面安装
[root@server9 mnt]# rpm -ivh libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm moosefs-chunkserver-3.0.80-1.x86_64.rpm
warning: libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:libpcap ########################################### [ 50%]
2:moosefs-chunkserver ########################################### [100%]
[root@server10 mnt]# rpm -ivh libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm moosefs-chunkserver-3.0.80-1.x86_64.rpm
warning: libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:libpcap ########################################### [ 50%]
2:moosefs-chunkserver ########################################### [100%]
- 在元数据节点安装
[root@server8 ~]# rpm -ivh /mnt/moosefs-metalogger-3.0.80-1.x86_64.rpm /mnt/libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm
warning: /mnt/libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:libpcap ########################################### [ 50%]
2:moosefs-metalogger ########################################### [100%]
- 使用的
MFS client
上面
[root@server7 x86_64]# scp moosefs-client-3.0.80-1.x86_64.rpm /mnt/libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm 172.25.23.6:/mnt/
[root@server6 ~]# yum install /mnt/libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm /mnt/moosefs-client-3.0.80-1.x86_64.rpm /mnt/libpcap-devel-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm
- 在
master
上面执行下面命令就会出现
[root@server7 mfs]# mfsmaster
open files limit has been set to: 16384
working directory: /var/lib/mfs
lockfile created and locked
initializing mfsmaster modules ...
exports file has been loaded
topology file has been loaded
loading metadata ...
metadata 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@server7 mfs]# mfscgiserv
lockfile created and locked
starting simple cgi server (host: any , port: 9425 , rootpath: /usr/share/mfscgi)
- 通过浏览器访问可以得到
- 编辑主及解析的配置,添加解析
[root@server7 mfs]# vim /etc/hosts
172.25.23.7 server7.com server7 mfsmaster
后面的解析名称和/etc/mfs/mfsmaster.cfg保持一致
# name of process to place in syslog messages (default is mfsmaster)
# SYSLOG_IDENT = mfsmaster
- 然后再次刷新页面
- 在
chunk
节点提供可供格式化的磁盘
[root@server9 mnt]# fdisk -cu /dev/vdb
Command (m for help): p
按照如下信息进行分区:
Device Boot Start End Blocks Id System
/dev/vdb1 2048 10485759 5241856 83 Linux
[root@server9 mnt]# partx /dev/vdb
- 然后格式化为
ext4
系统
[root@server9 mnt]# mkfs.ext4 /dev/vdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310464 blocks
65523 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
- 创建目录并且挂载这个分区
[root@server9 mnt]# mkdir /mnt/chunk1
[root@server9 mnt]# mount /dev/vdb1 /mnt/chunk1/
- 改变创建目录的属性信息
[root@server9 mnt]# chown mfs.mfs /mnt/chunk1/ -R
[root@server9 mnt]# vim /etc/fstab
添加:
UUID="273478e3-b96b-4207-9f81-d53286136cac" /mnt/chunk1 ext4 defaults 0 0
- 在
chunck
节点上面同时也需要添加解析信息
[root@server9 mnt]# vim /etc/hosts
添加
172.25.23.7 server7.com server7 mfsmaster
- 添加
master
控制的设备
[root@server9 mnt]# vim /etc/mfs/mfshdd.cfg
/mnt/chunck1
- 执行命令启动服务,并检查配置文件是否有错误
[root@server9 mnt]# mfschunkserver
open files limit has been set to: 16384
working directory: /var/lib/mfs
lockfile created and locked
setting glibc malloc arena max to 8
setting glibc malloc arena test to 1
initializing mfschunkserver modules ...
hdd space manager: path to scan: /mnt/chunk1/
hdd space manager: start background hdd scanning (searching for available chunks)
main server module: listen on *:9422
no charts data file - initializing empty charts
mfschunkserver daemon initialized properly
- 查看浏览器的
disk
界面,就可以看到,添加的设备信息
- 在
/mnt/chunk1
里面都是这些文件
- 在另一个
chunk
节点上面执行同样的操作
[root@server10 mnt]# fdisk -cu /dev/vdb
[root@server10 mnt]# partx /dev/vdb
[root@server10 mnt]# mkfs.ext4 /dev/vdb1
[root@server10 mnt]# mkdir /mnt/chunk2
[root@server10 mnt]# chown mfs.mfs /mnt/chunk2/ -R
[root@server10 mnt]# mount /dev/vdb1 /mnt/chunk2/
[root@server10 mnt]# vim /etc/fstab
添加
UUID="b45be960-ab60-4952-80d5-5fef22744962" /mnt/chunk2 ext4 defaults 0 0
- 如果在出现下面的错误
[root@server10 mnt]# mfschunkserver
open files limit has been set to: 16384
working directory: /var/lib/mfs
lockfile created and locked
setting glibc malloc arena max to 8
setting glibc malloc arena test to 1
initializing mfschunkserver modules ...
hdd space manager: can't create lock file '/mnt/chunk2/.lock': EACCES (Permission denied)
hdd space manager: no hdd space defined in /etc/mfs/mfshdd.cfg file
init: hdd space manager failed !!!
error occurred during initialization - exiting
- 很明显是因为权限的原因
[root@server10 mnt]# chown mfs.mfs /mnt/chunk2/
- 显示正常
- 在浏览器里面查看
disk
选项卡,增加了新的磁盘信息
- 接下来配置client进行挂载
- 首先配置
client
的解析正常
[root@server6 ~]# vim /etc/hosts
172.25.23.7 server7.com server7 mfsmaster
- 然后修改配置文件
[root@server6 ~]# vim /etc/mfs/mfsmount.cfg
/mnt/mfs
- 然后执行命令
[root@server6 ~]# mfsmount
- 显示下面的页面就是正常的
- 通过管理界面可以看到
server6.com
作为客户端已经挂载
- 创建一些文件并且可以进行管理
[root@server6 mfs]# mkdir dir1
[root@server6 mfs]# mkdir dir2
[root@server6 mfs]# mfsgetgoal dir1/
dir1/: 2
[root@server6 mfs]# mfsgetgoal dir2/
dir2/: 2 //表示数据在两个节点上面都有存在
表示文件只在一个结点上面进行存放
[root@server6 mfs]# mfssetgoal -r 1 dir1/
dir1/:
inodes with goal changed: 1
inodes with goal not changed: 0
inodes with permission denied: 0
- 表示这个文件只在一个结点上面保存
[root@server6 mfs]# cp /etc/passwd dir1/
[root@server6 mfs]# mfsfileinfo dir1/passwd
dir1/passwd:
chunk 0: 0000000000000001_00000001 / (id:1 ver:1)
copy 1: 172.25.23.10:9422 (status:VALID)
- 在另一个目录里面数据就保存了两份
[root@server6 mfs]# cp /etc/hosts dir2/
[root@server6 mfs]# mfsfileinfo dir2/hosts
dir2/hosts:
chunk 0: 0000000000000002_00000001 / (id:2 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
copy 2: 172.25.23.10:9422 (status:VALID)
- 现在停止节点
server10.com
上面的chunk
服务
[root@server6 dir2]# less hosts
127.0.0.1 www.linux.org
127.0.0.1 www.linux.com.cn
172.25.23.2/24 www.linux.com
172.25.23.2 virtual_host.linux.com ftp.linux.com
172.25.23.2 bbs.linux.com
172.25.23.3 wordpress.linux.com
0.0.0.0 account.jetbrains.com
172.25.23.1 server1.com server1
172.25.23.2 server2.com server2
172.25.23.3 server3.com server3
172.25.23.4 server4.com server4
172.25.23.5 server5.com server5
172.25.23.6 server6.com server6 server6.linux.org server6.westos.org
172.25.23.7 server7.com server7 mfsmaster
172.25.23.8 server8.com server8
172.25.23.9 server9.com server9
172.25.23.10 server10.com server10
hosts文件是可以正常进行访问的
- 下面的西悉尼说明使用的是
server9.com
节点上面的信息
[root@server6 dir2]# mfsfileinfo hosts
hosts:
chunk 0: 0000000000000002_00000001 / (id:2 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
- 接下来停止
server9.com
上面的服务,启动server10.com
上面的服务
[root@server10 mnt]# mfschunkserver start
[root@server9 chunk1]# mfschunkserver stop
- 查看文件内容
[root@server6 dir2]# mfsfileinfo ../dir1/passwd
../dir1/passwd:
chunk 0: 0000000000000001_00000001 / (id:1 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
[root@server6 dir2]# cat hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 www.linux.org
127.0.0.1 www.linux.com.cn
172.25.23.2/24 www.linux.com
172.25.23.2 virtual_host.linux.com ftp.linux.com
172.25.23.2 bbs.linux.com
172.25.23.3 wordpress.linux.com
0.0.0.0 account.jetbrains.com
172.25.23.1 server1.com server1
查看这个节点上面的内容会因为阻塞.而无法获取
[root@server6 dir2]# cat ../dir1/passwd
- 查看
passwd
文件的信息得到的是
[root@server6 dir2]# mfsfileinfo ../dir1/passwd
../dir1/passwd:
chunk 0: 0000000000000001_00000001 / (id:1 ver:1)
no valid copies !!!
- 这里创建一个比较大的文件,小文件磁盘的是使用量看着不明显;
[root@server6 dir1]# mfsfileinfo bigfile
bigfile:
chunk 0: 0000000000000003_00000001 / (id:3 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
chunk 1: 0000000000000004_00000001 / (id:4 ver:1)
copy 1: 172.25.23.10:9422 (status:VALID)
- 在创建了两个大文件之后,
chunk
的容量增长了,但是磁盘使用空间的Web
界面并没有显示增长;
[root@server6 dir1]# dd if=/dev/zero of=bigfile bs=100M count=20
20+0 records in
20+0 records out
2097152000 bytes (2.1 GB) copied, 27.4592 s, 76.4 MB/s
[root@server6 dir1]# dd if=/dev/zero of=bigfile bs=100M count=5
5+0 records in
5+0 records out
524288000 bytes (524 MB) copied, 6.68441 s, 78.4 MB/s
* 这是显示的占有的chunk
信息
[root@server6 dir1]# mfsfileinfo bigfile
bigfile:
chunk 0: 000000000000000D_00000001 / (id:13 ver:1)
copy 1: 172.25.23.10:9422 (status:VALID)
chunk 1: 000000000000000E_00000001 / (id:14 ver:1)
copy 1: 172.25.23.10:9422 (status:VALID)
chunk 2: 000000000000000F_00000001 / (id:15 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
chunk 3: 0000000000000010_00000001 / (id:16 ver:1)
copy 1: 172.25.23.10:9422 (status:VALID)
chunk 4: 0000000000000011_00000001 / (id:17 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
chunk 5: 0000000000000012_00000001 / (id:18 ver:1)
........
........
chunk 28: 0000000000000029_00000001 / (id:41 ver:1)
copy 1: 172.25.23.10:9422 (status:VALID)
chunk 29: 000000000000002A_00000001 / (id:42 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
chunk 30: 000000000000002B_00000001 / (id:43 ver:1)
copy 1: 172.25.23.10:9422 (status:VALID)
chunk 31: 000000000000002C_00000001 / (id:44 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
- 在目录
dir2/
里面执行的操作过程是这样的,分别将数据备份在不同的节点上面
[root@server6 dir2]# mfsfileinfo bigfile2
bigfile2:
chunk 0: 000000000000002D_00000001 / (id:45 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
copy 2: 172.25.23.10:9422 (status:VALID)
chunk 1: 000000000000002E_00000001 / (id:46 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
copy 2: 172.25.23.10:9422 (status:VALID)
chunk 2: 000000000000002F_00000001 / (id:47 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
copy 2: 172.25.23.10:9422 (status:VALID)
............
............
............
chunk 14: 000000000000003B_00000001 / (id:59 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
copy 2: 172.25.23.10:9422 (status:VALID)
chunk 15: 000000000000003C_00000001 / (id:60 ver:1)
copy 1: 172.25.23.9:9422 (status:VALID)
copy 2: 172.25.23.10:9422 (status:VALID)
- 还有一个需要说明的一点是,如果使用命令查看目录的大小,得到的结果很意外
[root@server9 chunk1]# du -sh
1.3M .
[root@server10 chunk2]# du -sh .
1.3M .
- 接下来尝试删除文件并且找回
- 首先需要挂载
mfs client
需要通过命令挂载元数据
[root@server6 trash]# mkdir /mnt/mfsmeta/
[root@server6 trash]# mfsmount -m /mnt/mfsmeta/
- 然后尝试删除某个文件,这里选择
passwd
,一定是/mnt/mfs/dir1/
里面的,不要删除系统的passwd
;
[root@server6 trash]# cd /mnt/mfs/dir1/
[root@server6 dir1]# rm -f passwd
[root@server6 dir1]# mfsfileinfo passwd
passwd: realpath error on (/mnt/mfs/dir1/passwd): ENOENT (No such file or directory)
- 然后进入元数据的挂载目录
[root@server6 dir1]# cd /mnt/mfsmeta/
[root@server6 mfsmeta]# ls
sustained trash
[root@server6 mfsmeta]# cd trash/
- 然后查找删除的文件名称
[root@server6 trash]# find -name *passwd*
./004/00000004|dir1|passwd
- 将文件放回
undel
目录里面
[root@server6 trash]# mv ./004/00000004\|dir1\|passwd undel/
[root@server6 trash]# ll undel/
total 0
- 进入目录查看文件的内容
[root@server6 dir1]# ls
bigfile passwd
[root@server6 dir1]# cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
但是对于
/mnt/mfsmeta/trash/undel/
显示是空的;这里修改上面的规划,因为硬件限制,这里将
mfsmetalogger
安装在server6.com
上面,也就是安装在mfs client
上面
[root@server6 mnt]# yum install moosefs-metalogger-3.0.80-1.x86_64.rpm -y
[root@server6 mnt]# mfsmetalogger start
[root@server6 mnt]# mfsmetalogger start
open files limit has been set to: 4096
working directory: /var/lib/mfs
lockfile created and locked
initializing mfsmetalogger modules ...
mfsmetalogger daemon initialized properly
- 这里首先到
mfs master
上面查看几个文件
[root@server7 x86_64]# ll /var/lib/mfs/
-rw-r-----. 1 mfs mfs 5189 3月 22 15:28 metadata.mfs.back
-rw-r-----. 1 mfs mfs 4968 3月 22 15:00 metadata.mfs.back.1
- 上面的两个文件,就是
mfs logger
需要从mfs master
上面进行同步的文件
[root@server7 x86_64]# ll /var/lib/mfs/
-rw-r-----. 1 mfs mfs 763 3月 22 15:25 changelog.1.mfs
-rw-r-----. 1 mfs mfs 106 3月 22 14:52 changelog.2.mfs
-rw-r-----. 1 mfs mfs 61 3月 21 21:58 changelog.3.mfs
-rw-r-----. 1 mfs mfs 2877 3月 21 19:27 changelog.5.mfs
-rw-r-----. 1 mfs mfs 6771 3月 21 19:09 changelog.6.mfs
-rw-r-----. 1 mfs mfs 1345 3月 21 17:56 changelog.7.mfs
- 上面的表示的元数据发生更改的日志文件;
master <-> metaloggers module: listen on *:9419 //这个端口表示的就是和metalogger 进行通信的端口
master <-> chunkservers module: listen on *:9420
main master server module: listen on *:9421
[root@server6 mnt]# ll /var/lib/mfs/
total 20
-rw-r-----. 1 mfs mfs 29 3月 22 15:49 changelog_ml.0.mfs
-rw-r-----. 1 mfs mfs 93 3月 22 15:39 changelog_ml_back.0.mfs
-rw-r-----. 1 mfs mfs 763 3月 22 15:39 changelog_ml_back.1.mfs
-rw-r-----. 1 mfs mfs 5189 3月 22 15:39 metadata_ml.mfs.back
- 对于这些文件,是
mfs logger
从mfs master
上面同步过来的文件,实际情况下,mfs logger
并不能够很好的完成接管服务,建议使用单节点的高可用; - 对于
MFS
的服务配置,如果不是因为特殊需要,配置文件是不建议进行更改的;