目錄:
- 一.介紹
- 二.MFS的部署
-
- 1.下載下傳
- 2.master部署和啟動
- 3.chunk server
- 4.client
- 5.client端存儲
- 注意,若是啟動失敗:
- 三.檔案問題
-
- 1.檔案的寫入
- 2.檔案的恢複
- 四.存儲類
-
- 1.添加chunk server節點e
一.介紹
MFS是一個具有容錯性的網絡分布式檔案系統,它把資料分散存放在多個實體伺服器上,而呈現給使用者的則是一個統一的資源。
MFS的組成:
中繼資料伺服器(Master),中繼資料日志伺服器(MetaLogger),資料存儲伺服器(Chunk Server),用戶端(Client)。
中繼資料伺服器 | 在整個體系中負責管理檔案系統,維護中繼資料。所謂中繼資料記錄的是整個分布式檔案系統的變化,比如說記錄檔案存儲在哪個主機,有多少個副本、每個檔案大小多少、檔案名字、檔案被分成多少個塊兒進行存儲等資訊,這些資料消耗的是伺服器的記憶體資源,是以中繼資料不在于存儲的資料有多大,而在于其數量。 |
---|---|
中繼資料日志伺服器(MetaLogger) | 備份Master伺服器的變化日志檔案,當master伺服器損壞,可以從日志伺服器中取得檔案恢複。 |
資料存儲伺服器(Chunk Server) | 真正存儲資料的伺服器,伺服器越多,容量就越大,可靠性越高,性能越好。 |
用戶端(Client) | 可以像挂載NFS一樣 挂載MFS檔案系統 |
二.MFS的部署
1.下載下傳
首先需要配置自己的yum 源:
[[email protected] yum.repos.d]# vim MooseFS.repo
[MooseFS]
name=MooseFS
baseurl=http://ppa.moosefs.com/moosefs-3/yum/el7
gpgcheck=0
然後把yum 源傳到三台虛拟機都有!
scp /etc/yum.repos.d/MooseFS.repo server2:/etc/yum.repos.d/
然後就可以直接下載下傳所需要的包了:
[[email protected] yum.repos.d]# yum install moosefs-master moosefs-cgi moosefs-cgiserv moosefs-cli -y

下載下傳不了的話,做解析。
vim /etc/resolv.conf
nameserver 114.114.114.114
在server2,3上隻需要下載下傳
yum install -y moosefs-chunkserver
2.master部署和啟動
[[email protected] mfs]# vim /etc/hosts
添加server1的解析 172.25.1.1 server1 mfsmaster
[[email protected] mfs]# scp /etc/hosts server2:/etc/
[[email protected] mfs]# scp /etc/hosts server3:/etc/
[[email protected] mfs]# systemctl start moosefs-master.service %啟動服務
[email protected] mfs]# netstat -antulp %檢視開啟的端口
[[email protected] mfs]# systemctl start moosefs-cgiserv.service %開啟相關cgi服務(提供可視化界面)
[[email protected] mfs]# netstat -antulp
systemctl start moosefs-master.service
systemctl start moosefs-cgiserv.service
接着在網頁通路:
172.25.1.1:9425
3.chunk server
前面說了,chunk server是真正存儲資料的地方!
我們首先要劃出來一個區域來提供存儲
server2上操作:
添加一塊兒10G的硬碟并設定分區、格式化檔案系統,設定開機自動挂載
fdisk /dev/vdb
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): w
The partition table has been altered!
[[email protected] yum.repos.d]# mkfs.xfs /dev/vdb1 %格式化檔案系統
[[email protected] yum.repos.d]# mkdir /mnt/chunk1 %建立挂載目錄
[[email protected] yum.repos.d]# cd
[[email protected] ~]# chown mfs.mfs /mnt/chunk1/ %更改存儲的使用者及使用者組
[[email protected] ~]# blkid %檢視裝置uid,通過uid來設定開機自動挂載
[[email protected] ~]# vim /etc/fstab %設定開機自動挂載
查到的id是多少就寫多少
UUID=a18fbb2f-cb4b-4c51-a659-cb58503860f6 /mnt/chunk1 xfs defaults 0 0
[[email protected] ~]# mount -a
[[email protected] ~]# df
[[email protected] ~]# systemctl start moosefs-chunkserver %啟動服務
[[email protected] mfs]# ls
mfschunkserver.cfg mfschunkserver.cfg.sample mfshdd.cfg mfshdd.cfg.sample
[[email protected] mfs]# vim mfshdd.cfg %編輯配置檔案,指定mfs存儲檔案
/mnt/chunk1 %添加這行内容
[[email protected] mfs]# systemctl reload moosefs-chunkserver.service %reload服務
重新整理網頁,檢視:
在server3上:
mkdir /mnt/chunk2
chown mfs.mfs /mnt/chunk2/
systemctl start moosefs-chunkserver
cd /etc/mfs/
vim mfshdd.cfg
/mnt/chunk2 %添加這行内容
systemctl reload moosefs-chunkserver.service
然後重新整理頁面:
4.client
就是在自己的真機上操作:
[[email protected] mnt]# yum install -y moosefs-client-3.0.115-1.rhsystemd.x86_64.rpm %先配置好源,然後下載下傳相應rpm包
[[email protected] mnt]# vim /etc/hosts %添加server1的mfsmaster解析
[[email protected] mnt]# cd /etc/mfs/
[[email protected] mfs]# ls
mfsmount.cfg mfsmount.cfg.sample
[[email protected] mfs]# vim mfsmount.cfg
/mnt/mfs
[[email protected] mfs]# cd
[[email protected] ~]# mkdir /mnt/mfs -p
[[email protected] ~]# mfsmount %挂載mfs存儲
mfsmaster accepted connection with parameters: read-write,restricted_ip,admin ; root mapped to root:root
[[email protected] ~]# df
5.client端存儲
[[email protected] ~]# cd /mnt/mfs/
[[email protected] mfs]# ls
[[email protected] mfs]# mkdir dir1
[[email protected] mfs]# mkdir dir2
[[email protected] mfs]# mfsgetgoal dir1 %因為有兩個chunk server,是以預設存儲的資料備份兩份,server2和server3上各一份
dir1: 2
[[email protected] mfs]# mfsgetgoal dir2
dir2: 2
[[email protected] mfs]# mfsgetgoal dir1
dir1: 2
[[email protected] mfs]# mfssetgoal -r 1 dir1 %備份的份數可以自己設定
dir1:
inodes with goal changed: 1
inodes with goal not changed: 0
inodes with permission denied: 0
[[email protected] mfs]# mfsgetgoal dir1
dir1: 1
[[email protected] mfs]# cp /etc/passwd dir1/
[[email protected] mfs]# cp /etc/fstab dir2/
[[email protected] mfs]# cd dir1
[[email protected] dir1]# mfsfileinfo passwd %檢視檔案的存儲配置設定資訊
[[email protected] dir1]# cd ..
[[email protected] mfs]# cd dir2
[[email protected] dir2]# ls
fstab
[[email protected] dir2]# mfsfileinfo fstab
[[email protected] mfs]# systemctl stop moosefs-chunkserver
[[email protected] dir2]# mfsfileinfo fstab %當某個存儲節點down掉之後,另外一台節點上的存儲不會收到影響
fstab:
chunk 0: 0000000000000002_00000001 / (id:2 ver:1)
copy 1: 172.25.1.2:9422 (status:VALID)
[[email protected] dir2]# cd ..
[[email protected] mfs]# cd dir1
[[email protected] dir1]# mfsfileinfo passwd
passwd:
chunk 0: 0000000000000001_00000001 / (id:1 ver:1)
copy 1: 172.25.1.2:9422 (status:VALID)
當把server2服務停掉後,再次執行會發現fstab隻會複制一份了!
注意,若是啟動失敗:
因為虛拟機同時挂了,導緻腦裂!
啟動服務失敗,執行
mfsmaster -a
mfsmaster stop
systemctl start moosefs-master
三.檔案問題
1.檔案的寫入
mfs預設的單個chunk大小為50M,如果寫入檔案大于50M,則mfs會為其配置設定多個chunk來存儲
在真機上操作:
可以看到我們直接寫入一個200M的檔案,那麼會自動分為四個來儲存!
[[email protected] mnt]# cd /mnt/mfs/
[[email protected] mfs]# ls
dir1 dir2
[[email protected] mfs]# cd dir2/
[[email protected] dir2]# ls
fstab
[[email protected] dir2]# dd if=/dev/zero of=bigfile bs=1M count=200
[[email protected] dir2]# mfsfileinfo bigfile
2.檔案的恢複
[[email protected] mnt]# mkdir mfsmeta
[[email protected] mnt]# cd mfsmeta/
[[email protected] mfsmeta]# ls
[[email protected] mfsmeta]# mfsmount -m /mnt/mfsmeta/
再次檢視垃圾箱中出現了檔案!
[[email protected] mnt]# cd mfs
[[email protected] mfs]# cd dir1
[[email protected] dir1]# ls
passwd
[[email protected] dir1]# rm -rf passwd
[[email protected] mnt]# cd mfsmeta/
[[email protected] mfsmeta]# ls
撤銷删除的檔案:
cd trash/
ls
find -name *passwd*
cd 004/
ls
mv 00000004\|dir1\|passwd undel/
cd /mnt/mfs/dir1/
ls
四.存儲類
master記憶體的開銷主要取決于整個分布式檔案系統中檔案的數量而不是大小,cpu的消耗主要來源于使用者的操作。為了更合理的利用系統資源,我們需要來建立存儲類來對存儲進行管理
1.添加chunk server節點e
和前面配置一樣!
[[email protected] mfs]# yum install -y moosefs-chunkserver.x86_64
[[email protected] mfs]# vim mfshdd.cfg
[[email protected] mfs]# mkdir /mnt/chunk3
[[email protected] mfs]# vim /etc/hosts
[[email protected] mfs]# chown mfs.mfs /mnt/chunk3
[[email protected] mfs]# systemctl start moosefs-chunkserver
vim mfschunkserver.cfg
改為如下A
然後再server3上修改:
然後再server2上修改:
[[email protected] mfs]# vim mfschunkserver.cfg
重新開機服務
systemctl reload moosefs-chunkserver
網頁上檢視
接着在真機上操作:
[[email protected] mfs]# cd dir2
[[email protected] dir2]# ls
[[email protected] dir2]# mfsscadmin create 2A class_2A %建立存儲類,2A表示存兩份,兩份都在有标簽A的節點上
[[email protected] dir2]# mfsscadmin create AB class_AB %AB表示存一份,在具有A和B标簽的節點上
[[email protected] dir2]# mfsfileinfo fstab %檢視檔案的存儲資訊
[[email protected] dir2]# mfssetsclass class_2A fstab %設定檔案的存儲類
[[email protected] dir2]# mfsfileinfo bigfile
[[email protected] dir2]# mfssetsclass class_AB bigfile %設定檔案的存儲類
[[email protected] dir2]# mfsscadmin create A,B classAB %A,B表示存兩份,一份在具有标簽A的節點上,一份在具有标簽B的節點上
[[email protected] dir2]# mfssetsclass classAB bigfile %設定檔案的存儲類
通路網頁檢視:
删除節點
在server2,3,4上:
[[email protected] mfs]# vim mfschunkserver.cfg
LABELS = A S %更改标簽
[[email protected] mfs]# systemctl reload moosefs-chunkserver.service
server3上:
[[email protected] mfs]# vim mfschunkserver.cfg
LABELS = A B S H %更改标簽
[[email protected] mfs]# systemctl reload moosefs-chunkserver.service
server4上:
[[email protected] ~]# vim /etc/mfs/mfschunkserver.cfg
LABELS = A H %更改标簽
[[email protected] ~]# systemctl reload moosefs-chunkserver.service
用戶端:
[[email protected] dir2]# mfsscadmin create AS,BS class_ASBS %建立存儲類
storage class make class_ASBS: ok
[[email protected] dir2]# ls
bigfile fstab
[[email protected] dir2]# mfssetsclass class_ASBS fstab %設定檔案以指定存儲類型存儲
fstab: storage class: 'class_ASBS'
[[email protected] dir2]# mfsfileinfo fstab
fstab:
chunk 0: 0000000000000002_00000001 / (id:2 ver:1)
copy 1: 172.25.1.2:9422 (status:VALID)
copy 2: 172.25.1.3:9422 (status:VALID)
[[email protected] dir2]# mfsscadmin create BS,2A[S+H] class4
storage class make class4: ok
[[email protected] dir2]# mfssetsclass class4 fstab
fstab: storage class: 'class4'
[[email protected] dir2]# mfsfileinfo fstab
fstab:
chunk 0: 0000000000000002_00000001 / (id:2 ver:1)
copy 1: 172.25.1.2:9422 (status:VALID)
copy 2: 172.25.1.3:9422 (status:VALID)
copy 3: 172.25.1.4:9422 (status:VALID)
[[email protected] dir2]# mfsscadmin create -C 2AS -K AS,BS -A AH,BH -d 30 class5 %表示建立一個存儲類class5,存儲兩份,在AS上,-K參數指定資料保留在AS和BS上各一份,-d指定30天後,-A指定遷移到AH和BH上
storage class make class5: ok
[[email protected] dir2]# mfssetsclass class5 fstab
fstab: storage class: 'class5'
[[email protected] dir2]# mfsfileinfo fstab
fstab:
chunk 0: 0000000000000002_00000001 / (id:2 ver:1)
copy 1: 172.25.1.2:9422 (status:VALID)
copy 2: 172.25.1.3:9422 (status:VALID)
重新整理網頁通路: