部署MFS文件系统
MFS
MooseFS是一个具有容错性的网络分布式文件系统。它把数据分散存放在多个物理服务器上,而呈现给用户的则是一个统一的资源。
MFS的读数据过程:
client当需要一个数据时,首先向master server发起查询请求;
管理服务器检索自己的数据,获取到数据所在的可用数据服务器位置ip|port|chunkid;
管理服务器将数据服务器的地址发送给客户端;
客户端向具体的数据服务器发起数据获取请求;
数据服务器将数据发送给客户端;
MFS的写数据过程:
MFS的写数据过程:
当客户端有数据写需求时,首先向管理服务器提供文件元数据信息请求存储地址(元数据信息如:文件名|大小|份数等);
管理服务器根据写文件的元数据信息,到数据服务器创建新的数据块;
数据服务器返回创建成功的消息;
管理服务器将数据服务器的地址返回给客户端(chunkIP|port|chunkid);
客户端向数据服务器写数据;
数据服务器返回给客户端写成功的消息;
客户端将此次写完成结束信号和一些信息发送到管理服务器来更新文件的长度和最后修改时间
MFS的删除文件过程:
客户端有删除操作时,首先向Master发送删除信息;
Master定位到相应元数据信息进行删除,并将chunk server上块的删除操作加入队列异步清理;
响应客户端删除成功的信号
MFS修改文件内容的过程:
客户端有修改文件内容时,首先向Master发送操作信息;
Master申请新的块给.swp文件,
客户端关闭文件后,会向Master发送关闭信息;
Master会检测内容是否有更新,若有,则申请新的块存放更改后的文件,删除原有块和.swp文件块;
若无,则直接删除.swp文件块。
MFS重命名文件的过程:
客户端重命名文件时,会向Master发送操作信息;
Master直接修改元数据信息中的文件名;返回重命名完成信息;
实验环境:
主机 | ip |
---|---|
server1 | 172.25.254.1 |
server2 | 172.25.254.2 |
server3 | 172.25.254.3 |
配置MFS文件系统:
server1:
[1].在server1安装master和web图形界面
[[email protected] ~]# yum install -y 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
[2].主节点解析
[[email protected] ~]# vim /etc/hosts
172.25.254.1 server1 mfsmaster # 表明server1是master的身份 master上是存储的元数据
172.25.254.2 server2
172.25.254.3 server3
[3].开启服务
[[email protected] ~]# /etc/init.d/moosefs-master start
[[email protected] ~# netstat -antlp ##9419 9420 9421端口
[4].打开图形处理工具
[[email protected] ~]# /etc/init.d/moosefs-cgiserv start ## 9425端口打开
server2和server3:
[1].安装MFS的客户端软件:
[[email protected] ~]# yum install -y moosefs-chunkserver-3.0.97-1.rhsysv.x86_64.rpm
[[email protected] ~]# yum install -y moosefs-chunkserver-3.0.97-1.rhsysv.x86_64.rpm
[2].加server1解析
[[email protected] ~]# vim /etc/hosts
172.25.254.1 server1 mfsmaster
[[email protected] ~]# vim /etc/hosts
172.25.254.1 server1 mfsmaster
[3].挂载并开启服务
[[email protected] mfs]# mkdir /mnt/chunk1
[[email protected] mfs]# cd /mnt
[[email protected] mnt]# chown mfs.mfs chunk1/
[[email protected] mnt]# cd /etc/mfs/
[[email protected] mfs]# vim mfshdd.cfg
/mnt/chunk1 ##最后一行写入挂载点
[[email protected] mfs]# /etc/init.d/moosefs-chunkserver start
[[email protected] ~]# mkdir /mnt/chunk2
[[email protected] ~]# cd /mnt
[[email protected] ~]# chown mfs.mfs /mnt/chunk2 修改该挂载目录的所有人和所有组,这样才可以在目录中进行读写操作
[[email protected] ~]# vim /etc/mfs/mfshdd.cfg
/mnt/chunk2 ##最后一行写入挂载点
[[email protected] ~]# /etc/init.d/moosefs-chunkserver start
物理主机:
[1].安装客户端软件:
[[email protected] ~]# yum install moosefs-client-3.0.97-1.rhsystemd.x86_64.rpm
[[email protected] ~]# rpm -qa | grep moosefs
moosefs-client-3.0.97-1.rhsystemd.x86_64 ## 显示已经安装
[2].加入server1的解析
作用:是确定server1的master位置,而且客户端在访问其中的数据时候,是先来master端取得存储数据得元数据,再去server2或server3上取数据
[[email protected] ~]# vim /etc/hosts
172.25.245.1 server1 mfsmaster
[3].创建在真机挂载数据的目录并编辑配置文件
[[email protected] mfs]# mkdir /mnt/mfs
[[email protected] mfs]# cd /etc/mfs
[[email protected] mfs]# vim mfsmount.cfg
/mnt/mfs
[4].客户端挂载文件系统
[[email protected] mfs]# mfsmount 挂载
[[email protected] mfs]# df 查看是否挂载上
[[email protected] mfs]# cd /mnt/mfs/
[[email protected] mfs]# mkdir dir1 dir2 在该目录下建立目录
[[email protected] mfs]# mfsgetgoal dir1/ 查看该目录中的文件存储的份数
[[email protected] mfs]# mfsgetgoal dir2/
[5]. 修改dir1的文件备份份数为1
[[email protected] mfs]# mfssetgoal -r 1 dir1 修改dir1的文件备份份数为1
dir1:
inodes with goal changed: 1
[[email protected] mfs]# mfsgetgoal dir1
dir1: 1
[[email protected] mfs]# mfsgetgoal dir2
dir2: 2
[[email protected] mfs]# cd dir1
[[email protected] dir1]# cp /etc/passwd . ## passwd 移动到dir1
[[email protected] dir1]# mfsfileinfo passwd
passwd:
chunk 0: 0000000000000001_00000001 / (id:1 ver:1)
copy 1: 172.25.254.3:9422 (status:VALID)
[[email protected] dir1]# cd ..
[[email protected] mfs]# cd dir2
[[email protected] dir2]# cp /etc/fstab . ## fstab 移动到dir2
[[email protected] dir2]# mfsfileinfo fstab
fstab:
chunk 0: 0000000000000002_00000001 / (id:2 ver:1)
copy 1: 172.25.254.2:9422 (status:VALID)
copy 2: 172.25.254.3:9422 (status:VALID)
在浏览器中查看:172.25.245.1:9425
[6]. 删除dir1中的文件passwd,之后恢复passwd
[[email protected] ~]# cd /mnt/mfs/dir1
[[email protected] dir1]# dd if=/dev/zero of=bigfile bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.171047 秒,613 MB/秒
[[email protected] dir1]# mfsfileinfo bigfile
bigfile:
chunk 0: 0000000000000003_00000001 / (id:3 ver:1)
copy 1: 172.25.254.2:9422 (status:VALID)
chunk 1: 0000000000000004_00000001 / (id:4 ver:1)
copy 1: 172.25.254.3:9422 (status:VALID)
[[email protected] dir1]# mfsgettrashtime passwd
passwd: 86400
[[email protected] dir1]# rm -f passwd
恢复:
[[email protected] dir1]# cd /mnt
[[email protected] mnt]# mkdir mfsmeta 在/mnt下建立目录mfsmeta
[[email protected] mnt]# mfsmount -m /mnt/mfsmeta
mfsmaster accepted connection with parameters: read-write,restricted_ip
[[email protected] mnt]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
[[email protected] mnt]# cd mfsmeta/
[[email protected] mfsmeta]# ls
sustained trash
[[email protected] mfsmeta]# cd trash/
[[email protected] trash]# find -name *passwd*
./004/00000004|dir1|passwd
[[email protected] trash]# cd ./004/
[[email protected] 004]# ls
00000004|dir1|passwd undel
[[email protected] 004]# mv 00000004\|dir1\|passwd undel
[[email protected] 004]# cd /mnt/mfs/dir1/
[[email protected] dir1]# ls
bigfile passwd
自动恢复moosefs-master异常
在不正常情况下关闭moosefs-master
[[email protected] ~]# ps ax
[[email protected] ~]# kill -9 1154 #结束进程
[[email protected] ~]# /etc/init.d/moosefs-master start
[[email protected] ~]# vim /etc/init.d/moosefs-master
31 $prog start >/dev/null 2>&1 || $prog -a >/dev/null 2>&1 && success
#异常关闭moosefs-master时,脚本会自动恢复正常并且开启master
[[email protected] ~]# /etc/init.d/moosefs-master start
Starting mfsmaster: