1 系统架构
MFS manager 10.90.5.132(node2)
MFS Metalog 10.90.5.133(node3)
MFS chunkserver_01 10.90.5.134(node4)
MFS chunkserver_02 10.90.5.135(node5)
clients 10.90.5.136(node6)
2 安装元数据服务器(MFS manager)
2.1 用户名与主机IP对应
vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.90.5.132 node2
10.90.5.133 node3
10.90.5.134 node4
10.90.5.135 node5
10.90.5.136 node6
10.90.5.137 node7
2.2 添加用户
useradd -s /sbin/nologin mfs
2.3 编译安装软件
wet http://ncu.dl.sourceforge.net/project/moosefs/moosefs/1.6.11/mfs-1.6.11.tar.gz
mkdir -p /usr/local/mfs
tar zxvf mfs-1.6.11.tar.gz
./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs
make ; make install
2.4 修改配置文件
cd /usr/local/mfs/etc/
cp mfsmaster.cfg.dist mfsmaster.cfg
cp mfsexports.cfg.dist mfsexports.cfg
vim mfsexports.cfg
#* / ro
#192.168.1.0/24 / rw
#192.168.1.0/24 / rw,alldirs,maproot=0,password=passcode
#10.0.0.0-10.0.0.5 /test rw,maproot=nobody,password=test
* . rw
* / rw,alldirs,maproot=0
2.5 启动master server
[root@node2 mfs]# /usr/local/mfs/sbin/mfsmaster start
关闭master server
[root@node2 mfs]# /usr/local/mfs/sbin/mfsmaster -s
[root@node2 mfs]# vim /etc/init.d/mfsmaster
#!/bin/bash
#
# Init file for the MooseFS master service
#
# chkconfig: - 92 84
#
# description: MooseFS master
#
# processname: mfsmaster
# Source function library.
# Source networking configuration.
. /etc/init.d/functions
. /etc/sysconfig/network
# Source initialization configuration.
prefix="/usr/local/mfs"
pidfile="/var/run/mfsmaster.pid"
# Check that networking is up.
[ "${NETWORKING}" == "no" ] && exit 0
[ -x "$prefix/sbin/mfsmaster" ] || exit 1
[ -r "$prefix/etc/mfsmaster.cfg" ] || exit 1
[ -r "$prefix/etc/mfsexports.cfg" ] || exit 1
RETVAL=0
prog="mfsmaster"
datadir="/opt/mfs/var/mfs"
mfsbin="/usr/local/mfs/sbin/mfsmaster"
mfsrestore="/usr/local/mfs/sbin/mfsmeta"
start () {
echo -n $"Starting $prog: "
daemon --pidfile=${pidfile} $mfsbin start #>/dev/null 2>&1
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog &&pidof "$mfsbin" >$pidfile
return $RETVAL
}
stop () {
echo -n $"Stopping $prog: "
$mfsbin -s >/dev/null 2>&1 || killproc $prog #>/dev/null 2>&1
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $pid_file && rm -f /var/lock/subsys/$prog
return $RETVAL
}
restart () {
stop
start
}
reload () {
echo -n $"reload $prog: "
$mfsbin reload >/dev/null 2>&1 #|| killproc $prog #>/dev/null 2>&1
RETVAL=$?
echo
/var/lock/subsys/$prog
return $RETVAL
}
restore () {
echo -n $"restore $prog: "
$mfsrestore -a -d $datadir
RETVAL=$?
echo
/var/lock/subsys/$prog
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
restore)
restore
;;
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
2.6 错误解决方案
问题:
if this is new instalation then rename metadata.mfs.empty as metadata.mfs
init: file system manager failed !!!
error occured during initialization - exiting
解决方案:
mv /usr/local/mfs/var/mfs/metadata.mfs.empty /usr/local/mfs/var/mfs/metadata.mfs
3 安装MFS Metalog(node3)
3.1 用户名与主机IP对应
vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.90.5.132 node2
10.90.5.133 node3
10.90.5.134 node4
10.90.5.135 node5
10.90.5.136 node6
3.2 添加用户
useradd -s /sbin/nologin mfs
3.3 编译安装软件
wget http://ncu.dl.sourceforge.net/project/moosefs/moosefs/1.6.11/mfs-1.6.11.tar.gz
mkdir -p /usr/local/mfs
tar zxvf mfs-1.6.11.tar.gz
./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs
make ; make install
3.4 修改配置文件
cd /usr/local/mfs/etc/
cp mfsmetalogger.cfg.dist mfsmetalogger.cfg
vim mfsmetalogger.cfg
(添加下面两行)
MASTER_HOST = 10.90.5.132
MASTER_PORT = 9419
3.5 启动mfsmetalogger
/usr/local/mfs/sbin/mfsmetalogger start
产看是否启动
[root@node3 etc]# lsof -i:9419
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mfsmetalo 9406 mfs 7u IPv4 21397 0t0 TCP node3:37644->node2:9419 (ESTABLISHED)
关闭mfsmetalogger
/usr/local/mfs/sbin/mfsmetalogger -s
4 安装MFS chunkserver
(两台IP仅IP不同,不在重复配置)
4.1 用户名与主机IP对应
vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.90.5.132 node2
10.90.5.133 node3
10.90.5.134 node4
10.90.5.135 node5
10.90.5.136 node6
4.2 添加用户
useradd -s /sbin/nologin mfs
4.3 编译安装软件
wget http://ncu.dl.sourceforge.net/project/moosefs/moosefs/1.6.11/mfs-1.6.11.tar.gz
mkdir -p /usr/local/mfs
tar zxvf mfs-1.6.11.tar.gz
./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs
make ; make install
4.4 分区并格式化新加载磁盘
fdisk /dev/sdb
–-----------------------------------------------------------------------------------------
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8c550059
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux
Command (m for help): w
–-----------------------------------------------------------------------------------------
partprobe
mkfs -t ext4 /dev/sdb1
mkdir /data
mount /dev/sdb1 /data
[root@node4 ~]# blkid /dev/sdb1 | cut -d '"' -f 2
87bcc5f9-68e8-44b7-8ec4-13724f11fada
vim /etc/fstab
UUID=87bcc5f9-68e8-44b7-8ec4-13724f11fada /data ext4 defaults 0 0
4.5 修改配置文件
cd /usr/local/mfs/etc/
cp mfschunkserver.cfg.dist mfschunkserver.cfg
vim mfschunkserver.cfg
MASTER_HOST = 10.90.5.132
MASTER_PORT = 9420
cp mfshdd.cfg.dist mfshdd.cfg
[root@node4 etc]# cat mfshdd.cfg
/data
4.6 启动mfschunkserver
/usr/local/mfs/sbin/mfschukserver start
查看是否正常启动
[root@node4 etc]# ps -ef | grep mfs
mfs 1113 1 0 10:57 ? 00:00:00 /usr/local/mfs/sbin/mfschunkserver start
root 1153 993 0 11:01 pts/0 00:00:00 grep mfs
5 client 安装
5.1 用户名与主机IP对应
vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.90.5.132 node2
10.90.5.133 node3
10.90.5.134 node4
10.90.5.135 node5
10.90.5.136 node6
5.2 添加用户
useradd -s /sbin/nologin mfs
5.3 编译安装软件
yum -y install fuse*
wget http://ncu.dl.sourceforge.net/project/moosefs/moosefs/1.6.11/mfs-1.6.11.tar.gz
tar zxvf mfs-1.6.11.tar.gz
cd mfs-1.6.11
./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs --enable-mfsmount
make && make install
5.4 挂接mfs文件系统
创建挂载点
mkdir /mnt/mfs
加载挂载模块
modprobe fuse
挂载目录
[root@node6 mfs-1.6.11]# mfsmount -H node2 /mnt/mfs
mfsmaster accepted connection with parameters: read-write,restricted_ip ; root mapped to root:root
[root@node6 mfs-1.6.11]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 37G 993M 34G 3% /
tmpfs 120M 0 120M 0% /dev/shm
/dev/sda1 194M 26M 159M 14% /boot
node2:9421 37G 0 37G 0% /mnt/mfs
加入环境变量
echo “export PATH=$PATH:/usr/local/mfs/bin” >> /etc/profile
source /etc/profile
5.5 服务器端开启mfscgiserv
用户利用浏览器就可全面监控所有客户挂接, chunkserver 及
master server,客户端的各种操作等等。
node2 开启mfscgiserv服务
/usr/local/mfs/sbin/mfscgiserv start
[root@node2 ~]# netstat -tulnp | grep 9425
tcp 0 0 0.0.0.0:9425 0.0.0.0:* LISTEN 1056/python
在浏览器里输入http://10.90.5.132:9425 即可查看
5.6 系统管理
设置文件副本的份数,本方案仅有两台存储数据主机,因而副本最多有两份
mfssetgoal -r 2 /mnt/mfs
查看某个文件
mfsgetgoal /mnt/mfs
查看某个文件
mfsdirinfo -H /mnt/mfs
6 性能测试(客户端)
大文件写
[root@node6 mfs]# dd if=/dev/zero of=1.txt bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 299.935 s, 17.5 MB/s
小文件写
[root@node6 mfs]# dd if=/dev/zero of=2.txt bs=1K count=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB) copied, 0.00865678 s, 118 kB/s
7 回收站
7.1 查看隔离时间
一个删除文件能够存放在一个回收站的时间就是一个隔离时间
查看隔离时间
[root@node6 mfs]# mfsgettrashtime 2.txt
2.txt: 86400 (24小时)
7.2 还原删除的文件
rm 2.txt
umount /mnt/mfs
mfsmount -m -H node2 /mnt/mfs
[root@node6 home]# ll /mnt/mfs/trash/ | grep 2.txt
-rw-r--r-- 1 root root 1024 7月 9 14:25 00007A88|2.txt
mv /mnt/mfs/trash/00007A88|2.txt /mnt/mfs/undel
umount /mnt/mfs
mfsmount -H node2 /mnt/mfs
[root@node6 home]# ll /mnt/mfs | grep 2.txt
-rw-r--r-- 1 root root 1024 7月 9 14:25 2.txt
7.3 更改隔离时间
mfssettrashtime 0 2.txt (若文件被删除,不进入回收站)
ls -l /mnt/mfs/trash/ | grep 2.txt
回收站不存在
时间的长短直接决定文件在回收站的时间
8 安全测试
8.1 管理服务器故障切换测试
1,安装一台新的master,配置文件与故障master完全一致(需要前期定期备份master配置文件)
2,找回metadata.mfs.back 文件,从备份中或者metalogger主机中找回,而后把该文件放入/usr/local mfs/var/mfs/下
3,从在 master 宕掉之前的任何运行 metalogger 服务的服务器上拷贝最后 metadata 文件,然后放
入 mfsmaster 的数据目录。
4,用 mfsmetarestore 命令合并元数据 changelogs ,可以用自动恢复模式 mfsmetarestore –a,也
可以利用非自动化恢复模式,语法如下:
mfsmetarestore -m metadata.mfs.back -o metadata.mfs changelog_ml.*.mfs
8.2 数据存储服务器故障测试
关闭其中一台mfschunkserv,客户端重新挂载mfs
查看/mnt/mfs下的文件
[root@node6 ~]# ll /mnt/mfs/
total 5120003
drwxr-xr-x 2 root root 0 7月 9 14:17 0
drwxr-xr-x 2 root root 0 7月 9 14:17 1
-rw-r--r-- 1 root root 153 7月 9 14:15 1.sh
-rw-r--r-- 1 root root 5242880000 7月 9 14:04 1.txt
drwxr-xr-x 2 root root 0 7月 9 14:17 2
drwxr-xr-x 2 root root 0 7月 9 14:18 3
-rw-r--r-- 1 root root 1024 7月 9 14:25 3.txt
drwxr-xr-x 2 root root 0 7月 9 14:18 4
-rw-r--r-- 1 root root 1024 7月 9 14:25 4.txt
drwxr-xr-x 2 root root 0 7月 9 14:18 5
drwxr-xr-x 2 root root 0 7月 9 14:19 6
drwxr-xr-x 2 root root 0 7月 9 14:19 7
drwxr-xr-x 2 root root 0 7月 9 14:19 8
drwxr-xr-x 2 root root 0 7月 9 14:19 9
文件正常
两台都关闭。无文件
集群环境中复制份数足够合理,文件很难丢失。