MFS 特性:
MFS 文件系统结构:
包含 4 种角色:
管理服务器 managing server (master)
元数据日志服务器 Metalogger server(Metalogger)
数据存储服务器 data servers (chunkservers)
客户机挂载使用 client computer
各角色作用:
原始的读/写速度很明显是主要取决于所使用的硬盘的性能、网络的容量和拓扑结构的,使用的硬
盘和网络的吞吐量越好,整个系统的性能也就会越好。
主机环境:RHEL6.5 selinux and iptables disabled
Master:172.25.0.122
Metalogger: 172.25.0.122
Chunkserver: 172.25.0.123 / 172.25.0.124
Client: 172.25.0.16
1.MFS管理服务器(master)———server6
准备安装包:
moosefs-cgi-3.0.97-1.rhsysv.x86_64.rpm
moosefs-cgiserv-3.0.97-1.rhsysv.x86_64.rpm
moosefs-chunkserver-3.0.97-1.rhsysv.x86_64.rpm
moosefs-cli-3.0.97-1.rhsysv.x86_64.rpm
moosefs-client-3.0.97-1.rhsystemd.x86_64.rpm
moosefs-client-3.0.97-1.rhsysv.x86_64.rpm
moosefs-master-3.0.97-1.rhsysv.x86_64.rpm
moosefs-metalogger-3.0.97-1.rhsysv.x86_64.rpm
1)安装master端所需要的mfs包
[root@server6 3.0.97]# yum install moosefs-cgi-3.0.97-1.rhsysv.x86_64.rpm moosefs-cgiserv-3.0.97-1.rhsysv.x86_64.rpm
moosefs-master-3.0.97-1.rhsysv.x86_64.rpm -y
2)添加解析并打开服务
[root@server6 3.0.97]# vim /etc/hosts
172.25.0.122 server6 mfsmaster
172.25.0.123 server7 chunkserver
172.25.0.124 server8 chunkserver
[root@server6 3.0.97]# /etc/init.d/moosefs-master start
Starting mfsmaster: [ OK ]
[root@server6 3.0.97]# /etc/init.d/moosefs-cgiserv start
Starting mfscgiserv: [ OK ]
查看端口:
[root@server6 3.0.97]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9419 0.0.0.0:* LISTEN 3621/mfsmaster
tcp 0 0 0.0.0.0:9420 0.0.0.0:* LISTEN 3621/mfsmaster
tcp 0 0 0.0.0.0:9421 0.0.0.0:* LISTEN 3621/mfsmaster
tcp 0 0 0.0.0.0:9425 0.0.0.0:* LISTEN 3673/python
浏览器测试: http://172.25.0.122:9425/mfs.cgi
2.数据存储服务器(chunkserver端配置)
1)安装并添加域名解析
[root@server7 3.0.97]# yum install moosefs-chunkserver-3.0.97-1.rhsysv.x86_64.rpm -y
[root@server7 3.0.97]# vim /etc/hosts
172.25.0.122 server6 mfsmaster
2)建立chunkserver的目录,在配置文件中注名作为chunkserver的目录,并开启服务
[root@server7 ~]# mkdir /mnt/chunk1
[root@server7 ~]# chown mfs.mfs /mnt/chunk1/
[root@server7 ~]# vim /etc/mfs/mfshdd.cfg
/mnt/chunk1 //最后一行写入
[root@server7 ~]# /etc/init.d/moosefs-chunkserver start
Starting mfschunkserver: [ OK ]
server8上相同,只修改创建的目录名即可
3)当所有的数据服务器都配置好之后,我们可以在浏览器刷新MFS的界面,点选servers就可以看见我们的所有数据服务器。
3.moosefs-client配置
客户端在访问其中的数据时候,是先来master端取得存储数据得元数据,再去chunkserver取数据
1)安装并添加解析
[root@foundation78 3.0.97]# yum install moosefs-client-3.0.97-1.rhsystemd.x86_64.rpm -y
[root@foundation78 3.0.97]# vim /etc/hosts
172.25.0.122 server6 mfsmaster
2)建立挂载目录,并进行挂载
[root@foundation78 3.0.97]# mkdir /mnt/mfs
[root@foundation78 3.0.97]# vim /etc/mfs/mfsmount.cfg
/mnt/mfs
[root@foundation78 3.0.97]# mfsmount //挂载
mfsmaster accepted connection with parameters: read-write,restricted_ip,admin ; root mapped to root:root
[root@foundation78 3.0.97]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda12 267709732 45188028 222521704 17% /
devtmpfs 3945704 0 3945704 0% /dev
tmpfs 3961712 524 3961188 1% /dev/shm
tmpfs 3961712 9452 3952260 1% /run
tmpfs 3961712 0 3961712 0% /sys/fs/cgroup
/dev/sda10 505580 156092 349488 31% /boot
/dev/sda2 262144 37440 224704 15% /boot/efi
/dev/loop0 3947824 3947824 0 100% /var/www/html/rhel7.2
/dev/loop1 3762278 3762278 0 100% /var/www/html/rhel6.5
tmpfs 792344 20 792324 1% /run/user/1000
/dev/sdb1 30768560 29299296 1469264 96% /run/media/kiosk/disk
tmpfs 792344 0 792344 0% /run/user/0
mfsmaster:9421 36324672 2781888 33542784 8% /mnt/mfs //挂载目录
4)测试:挂载目录中建立文件,查看文件份数
[root@foundation78 3.0.97]# cd /mnt/mfs/
[root@foundation78 mfs]# mkdir dir1 dir2
[root@foundation78 mfs]# mfsgetgoal dir1 //文件在chunkserver端存的份数
dir1: 2
[root@foundation78 mfs]# mfsgetgoal dir2
dir2: 2
[root@foundation78 mfs]# mfssetgoal -r 1 dir1 //设置存的份数为1
dir1:
inodes with goal changed: 1
inodes with goal not changed: 0
inodes with permission denied: 0
[root@foundation78 mfs]# cd dir1
[root@foundation78 dir1]# cp /etc/passwd .
[root@foundation78 dir1]# mfsfileinfo passwd //1份
passwd:
chunk 0: 0000000000000001_00000001 / (id:1 ver:1)
copy 1: 172.25.0.124:9422 (status:VALID)
[root@foundation78 dir1]# cd ../dir2
[root@foundation78 dir2]# cp /etc/fstab .
[root@foundation78 dir2]# mfsfileinfo fstab //2份
fstab:
chunk 0: 0000000000000002_00000001 / (id:2 ver:1)
copy 1: 172.25.0.123:9422 (status:VALID)
copy 2: 172.25.0.124:9422 (status:VALID)
当关闭dir1保存文件的chunkserver:
[root@server8 ~]# /etc/init.d/moosefs-chunkserver stop
Stopping mfschunkserver: [ OK ]
[root@foundation78 dir1]# mfsfileinfo passwd //可以查看到看到有这文件,但是不能查看
passwd:
chunk 0: 0000000000000001_00000001 / (id:1 ver:1)
no valid copies !!!
重新打开chunkserver后文件恢复正常
[root@foundation78 dir1]# mfsfileinfo passwd
passwd:
chunk 0: 0000000000000001_00000001 / (id:1 ver:1)
copy 1: 172.25.0.124:9422 (status:VALID)
5)文件误删的恢复方法
[root@foundation78 dir1]# ls
passwd
[root@foundation78 dir1]# rm -fr passwd
[root@foundation78 dir1]# mkdir /mnt/mfsmeta
[root@foundation78 dir1]# mfsmount -m /mnt/mfsmeta/
mfsmaster accepted connection with parameters: read-write,restricted_ip
[root@foundation78 dir1]# cd /mnt/mfsmeta/trash/
[root@foundation78 trash]# ls
0FD 20F 321 433 545 657 769 87B 98D A9F BB1 CC3 DD5 EE7 FF9
0FE 210 322 434 546 658 76A 87C 98E AA0 BB2 CC4 DD6 EE8 FFA
0FF 211 323 435 547 659 76B 87D 98F AA1 BB3 CC5 DD7 EE9 FFB
100 212 324 436 548 65A 76C 87E 990 AA2 BB4 CC6 DD8 EEA FFC
101 213 325 437 549 65B 76D 87F 991 AA3 BB5 CC7 DD9 EEB FFD
102 214 326 438 54A 65C 76E 880 992 AA4 BB6 CC8 DDA EEC FFE
103 215 327 439 54B 65D 76F 881 993 AA5 BB7 CC9 DDB EED FFF
104 216 328 43A 54C 65E 770 882 994 AA6 BB8 CCA DDC EEE undel
[root@foundation78 trash]# find -name *passwd*
./004/00000004|dir1|passwd
[root@foundation78 trash]# mv ./004/00000004\|dir1\|passwd undel/
[root@foundation78 trash]# cd /mnt/mfs
[root@foundation78 mfs]# cd dir1
[root@foundation78 dir1]# ls
passwd
6)自动恢复moosefs-master异常
master上修改启动脚本
[root@server6 3.0.97]# vim /etc/init.d/moosefs-master
31 $prog start >/dev/null 2>&1 || $prog -a >/dev/null 2>&1 && success
不正常情况下关闭moosefs-master
[root@server6 mfs]# kill -9 9108
[root@server6 mfs]# /etc/init.d/moosefs-master start
Starting mfsmaster: [ OK ] //不会报错
第二种方法:将mfs目录下的metadata.mfs文件重命名为以.back结尾的文件。即可启动服务
[root@server6 ~]# cd /var/lib/mfs/
[root@server6 mfs]# ll
total 3612
-rw-r----- 1 mfs mfs 37 Nov 15 20:40 changelog.1.mfs
-rw-r----- 1 mfs mfs 1867 Nov 15 20:30 changelog.2.mfs
-rw-r----- 1 mfs mfs 129 Nov 15 19:57 changelog.3.mfs
-rw-r----- 1 mfs mfs 3618 Nov 15 20:48 metadata.mfs.back
-rw-r----- 1 mfs mfs 3626 Nov 15 20:36 metadata.mfs.back.1
-rwxr--r-- 1 mfs mfs 8 Aug 2 2017 metadata.mfs.empty
-rw-r----- 1 mfs mfs 3672832 Nov 15 20:48 stats.mfs