从官网下载了moosefs2.0版本的用户手册,根据内容做了一个简单的实验。
实验需要3~4台虚拟机:
master:192.168.149.136(centos7)
chunkserver:192.168.149.137(centos7)
client:192.168.149.138(centos7),192.168.149.128(centos6)
实验步骤:
1.配置DNS。由于设备数量太少,我简单的通过改写/etc/hosts文件,实现了互相访问。
master /etc/hosts配置如下:
192.168.149.136 mfsmaster
192.168.149.137 mfschunkserver1
chunkserver,client只需配置192.168.149.136 mfsmaster。
2.添加repo。所有虚拟机都需要添加repo,并下载相应安装包。
centos7:
Adding the repo key
# curl "http://ppa.moosefs.com/RPM-GPG-KEY-MooseFS" > /etc/pki/rpm-gpg/RPM-GPG-KEY-MooseFS
Next you need to add the repository entry to yum repo:
Adding MooseFS repo
# curl "http://ppa.moosefs.com/MooseFS-2-el7.repo" > /etc/yum.repos.d/MooseFS.repo
centos6:
Adding the repo key
# curl "http://ppa.moosefs.com/RPM-GPG-KEY-MooseFS" > /etc/pki/rpm-gpg/RPM-GPG-KEY-MooseFS
Adding the MooseFS repo
# curl "http://ppa.moosefs.com/MooseFS-2-el6.repo" > /etc/yum.repos.d/MooseFS.repo
3.注意安装包的区别。moosefs分专业版(Pro)和社区版(CE),从软件包名称能区分。
moosefs-master 社区版
moosefs-pro-master 专业版
4.master server的安装。
yum install moosefs-master 安装完毕后,在/etc/mfs下会有6个配置文件。实际上它们的内容两两相同。mfsexports.cfg文件用于设置允许哪台客户端以何种权限登陆。这里我使用默认值,没有改动。
[root@localhost mfs]# ls
mfsexports.cfg mfsmaster.cfg mfstopology.cfg
mfsexports.cfg.dist mfsmaster.cfg.dist mfstopology.cfg.dist
启动mfsmaster有2种方法:(1)mfsmaster start;(2)systemctl start moosefs-master.service
5.安装CGI monitor,CGI server 和命令行。简单的安装,启动。
# yum install moosefs-cgi
# yum install moosefs-cgiserv
# yum install moosefs-cli
# systemctl start moosefs-cgiserv.service
6. chunkserver安装。
yum install moosefs-chunkserver 之后,在/mnt下创建mfschunk1和mfschunk2两个文件夹,用于存放共享的数据。并在mfshdd.cfg文件末尾加上这2个文件夹。
[root@localhost mfs]# tail mfshdd.cfg
#*/mnt/hd2
#
# use hard drive '/mnt/hd3', but try to leave 5GiB on it:
#/mnt/hd3 -5GiB
#
# use hard drive '/mnt/hd4', but use only 1.5TiB on it:
#/mnt/hd4 1.5TiB
/mnt/mfschunk1
/mnt/mfschunk2
将这2个文件夹的拥有者和组改为mfs,使用systemctl start moosefs-chunkserver.service启动chunkserver。
7. client安装。
使用yum install moosefs-client,并创建/mnt/mfs,然后使用mfsmount /mnt/mfs -H mfsmaster进行挂载。
如果想开机启动,需要将配置写入/etc/fstab:
[root@www ~]# tail -2 /etc/fstab
proc /proc proc defaults 0 0
mfsmount /mnt/mfs fuse defaults,mfsdelayedinit,mfsmaster=mfsmaster,mfsport=9421 0 0
注意mfsmaster= 后面要接master的域名。在本实验,我在/etc/hosts配置的是192.168.149.136 mfsmaster,所以mfsmaster=mfsmaster。
8.简单使用。
此时,client已经挂载了mfs,可以使用# mfssetgoal -r 1 /mnt/mfs/folder1来设置保存的副本数。由于只有1个chunkserver,所以即使设置成2,也只能看到1个副本。
9.安装过程容易遇到的问题。
如果/etc/fstab写错,因为开机不会使用fsck检查,所以操作系统能启动,但是mfs无挂载。确保防火墙关闭之后,可以用mount命令检查。
故障现象:
[root@www mnt]# ls
ls: cannot access mfs: Input/output error
可通过mount检查:
[root@www mnt]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
mfsmaster.example.lan:9421 on /mnt/mfs type fuse.mfs (rw,allow_other)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
,allow_other)
10.可通过web查看mfs集群状态。网址为http://192.168.1.1:9425,192.168.1.1需改为相应的CGI server的IP。
11.最后,实验了一下在master故障的情况下,如何在另一台服务器恢复数据。
在1台虚拟机上安装moosefs-metalogger并启动,默认会自动备份mfsmaster的数据。
master默认将数据保存到/var/lib/mfs了:
[root@mfsmaster mfs]# ll
total 3368
-rw-r----- 1 mfs mfs 660 Feb 20 16:33 changelog.10.mfs
-rw-r----- 1 mfs mfs 1347 Feb 20 15:59 changelog.11.mfs
-rw-r----- 1 mfs mfs 218 Feb 21 14:50 changelog.2.mfs
-rw-r----- 1 mfs mfs 311 Feb 21 12:40 changelog.6.mfs
-rw-r----- 1 mfs mfs 449 Feb 21 10:42 changelog.8.mfs
-rw-r----- 1 mfs mfs 486 Feb 20 17:31 changelog.9.mfs
-rw-r----- 1 mfs mfs 1553 Feb 21 15:38 metadata.mfs
-rw-r----- 1 mfs mfs 1553 Feb 21 14:54 metadata.mfs.back.1
-rwxr--r-- 1 mfs mfs 8 Sep 28 2016 metadata.mfs.empty
-rwxr----- 1 mfs mfs 3410488 Feb 21 15:38 stats.mfs
metalogger默认也保存在/var/lib/mfs了:
[root@mfsmetalogger mfs]# ll
total 3352
-rw-r----- 1 mfs mfs 42 Feb 21 14:56 changelog.2.mfs
-rwxr----- 1 mfs mfs 136 Feb 21 14:50 changelog_ml.0.mfs
-rwxr----- 1 mfs mfs 57 Feb 21 12:40 changelog_ml.1.mfs
-rw-r----- 1 mfs mfs 0 Feb 21 15:35 changelog_ml_back.0.mfs
-rw-r----- 1 mfs mfs 218 Feb 21 15:35 changelog_ml_back.1.mfs
-rw-r----- 1 mfs mfs 1553 Feb 21 15:35 metadata_ml.mfs.back
-rw-r----- 1 mfs mfs 3410488 Feb 21 15:11 stats.mfs
其实这里面对于恢复数据,有用的就是metadata_ml.mfs.back。
我这边模拟master无法提供服务,将master的moosefs-master服务关掉了。然后在一台新虚拟机上安装了moosefs-master,进入/var/lib/mfs目录,该目录下只有metadata.mfs metadata.mfs.empty两个文件,将metadata.mfs删除,将metadata_ml.mfs.back从metalogger服务器上复制过来,重命名为metadata.mfs,一定要注意权限,不然服务无法启动。最后,启动服务即可。
注意:如果新建一台虚拟机为master,一定要注意IP,确保chunkserver和client的解析正确!
一般来说,Moosefs的chunkserver只要还有1台正常,业务就不会中断。同时,如果每台服务器硬盘数量不同,通过写入mfshdd.cfg不同的挂载点,每个chunkserver也可以挂载不同数量的硬盘,很灵活。