MooseFs-分布式文件系統系列(一)之了解並安裝它


preface

在上上家公司,曾維護過公司的MFS文件系統,主要用來存儲系統日志文件,單純的把日志當作文件存儲,在當時的架構下,MFS就像一個中間站一樣,這邊程序生成的日志放入MFS,那邊日志分析程序從里面取出日志文件來。
翻開塵封多年的筆記,借助下相關的文檔資料,特意寫下MFS的一丁點知識。

MFS概論與讀寫過程

MFS的官方網站是http://www.moosefs.org,我們可以從這里獲取權威的幫助信息,官方MFS網絡組成以及原理如下所示:
MFS Read Process:

MFS Write Process:

how the system works:

All file operations on a client computer that has mounted MooseFS are exactly the same as they would be with other file systems. The operating system kernel transfers all file operations to the FUSE module, which communicates with the mfsmount process. The mfsmount process communicates through the network subsequently with the managing server and data servers (chunk servers). This entire process is fully transparent to the user.

mfsmount communicates with the managing server every time an operation on file metadata is required:

  1. creating files
  2. deleting files
  3. reading directories
  4. reading and changing attributes
  5. changing file sizes
  6. at the start of reading or writing data
  7. on any access to special files on MFSMETA

mfsmount uses a direct connection to the data server (chunk server) that stores the relevant chunk of a file. When writing a file, after finishing the write process the managing server receives information from mfsmount to update a file's length and the last modification time.

Furthermore, data servers (chunk servers) communicate with each other to replicate data in order to achieve the appropriate number of copies of a file on different machines.

通過上面官網的解釋,我相信大家應該指定MFS一個工作流程了。

文件系統

如上圖所示,MFS文件系統共有4個角色,分別是

  1. 管理服務器 --- Master Server
  2. 元數據日志服務器 --- Metalogger
  3. 數據存儲服務器 --- Chunk Server
  4. 客戶端 --- Client

4種角色作用如下:

  1. 管理服務器--mfsmaster
    有時也稱為元數據服務器,負責管理各個數據存儲服務器,調度文件讀寫,回收文件空間以及恢復多節點拷貝。

  2. 元數據服務器-mfsmetalogger
    負責備份管理服務器的變化日志,文件類型為changelog_ml.*.mfs,以便於在管理服務器出現問題時接替期進行工作。這類服務器是在mfs1.6版本后新增的服務,可以把元數據日志保留在管理服務器中,也可以單獨存在一台服務器中。為保證數據的安全性和可靠性,建議單獨使用一台服務器來存放元數據日志,需要注意的是,元數據日志守護進程跟管理服務器在同一個服務器,備份元數據日志服務器作為它的客戶端,從管理服務器取得日志文件進行備份。

  3. 數據存儲服務器-mfschunkserver
    這類是真正存儲用戶數據的服務器。在存儲文件時,首先把文件分成塊,然后把這些塊在數據存儲服務器之間互相復制,同事,數據存儲服務器還負責連接管理服務器,聽從管理服務器調度,並為客戶提供數據傳輸。數據存儲服務器可以有多個,並且數量越多,可靠性越高。MFS可用的磁盤空間也越大。

  4. 客戶端-mfsclient
    客戶端通過fuse內核接口掛載遠程服務器上所管理的數據存儲服務器,使共享的文件系統和使用本地linux文件系統的效果看起來一樣的。

MFS的安裝

我在這里拿一套實驗環境來進行部署,機器信息如下:

IP 角色
172.16.22.142 MfsChunkServer
172.16.160.191 MfsMaster
172.16.160.192 Mfsmetadata
172.16.22.81 MfsClient
yum安裝過程

想采用yum安裝,那么就按照官網資料操作吧:
yum安裝參考官方資料:https://moosefs.com/download/centosfedorarhel.html

Important!

If you already upgraded your Chunkservers to v. 3.0.83 or higher, please DO NOT downgrade them!

In MooseFS Chunkserver v. 3.0.83 we changed Chunk header from 5k to 8k (see changelog) - it means, that Chunkserver older than 3.0.83 cannot "understand" new Chunk header, which may lead to potential data loss!

源碼包安裝

下面開始源碼 ,我們安裝3.0這個版本的包,安裝過程可以參考官網, 或者下面的PDF:
PDF地址:https://moosefs.com/Content/Downloads/moosefs-3-0-users-manual.pdf
地址是:https://moosefs.com/download/sources.html
源碼包下載地址是:http://ppa.moosefs.com/src/moosefs-3.0.84-1.tar.gz

Notice

  1. 安裝之前/etc/hosts文件做好解析,在這我們將使用mfsmaster,所以一定要在/etc/hosts里面加入這條記錄。
  2. 所有服務器時間同步。
172.16.160.191安裝master server-管理服務器
[root@localhost tmp]# tar zxf moosefs-3.0.84-1.tar.gz 
[root@localhost tmp]# cd moosefs-3.0.84
[root@localhost moosefs-3.0.84]# useradd mfs -s /sbin/nologin 
[root@localhost moosefs-3.0.84]# ./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs
[root@localhost moosefs-3.0.84]# make && make install

編譯沒有問題,那么就安裝成功了,我們在/usr/local/mfs/下找到配置文件,更改配置文件:
mfsmaster.cfg

[root@localhost moosefs-3.0.84]# cd /usr/local/mfs/etc/mfs
[root@localhost mfs]# cp sbin/mfs* /usr/sbin/    #復制命令到系統下面
[root@localhost mfs]# cp -a mfsmaster.cfg.sample  mfsmaster.cfg
[root@localhost mfs]# grep ^[a-Z] mfsmaster.cfg
WORKING_USER = mfs
WORKING_GROUP = mfs
SYSLOG_IDENT = mfsmaster  #在syslog中的表示,說明這是mfsmaster產生的
LOCK_MEMORY = 0    # 是否執行mlockall()以避免mfsmaster內存溢出(默認為0)
NICE_LEVEL = -19     # 運行的優先級(默認-19,注意,這進程必須是root啟動 )
DATA_PATH = /usr/local/mfs/var/mfs      #數據存放路徑,該目錄下有三大類文件,changelog,sessions,stats
EXPORTS_FILENAME = /usr/local/mfs/etc/mfs/mfsexports.cfg     #被掛載目錄以及其權限控制文件的存放位置
BACK_LOGS = 50     #元數據的改變日志文件數量(默認是50)
MATOML_LISTEN_HOST = *     # 元數據日志服務器監聽的IP地址(默認是*,代表任何IP)
MATOML_LISTEN_PORT = 9419   # 元數據日志服務器監聽的端口地址,默認是9419
MATOCS_LISTEN_HOST = *       # 用於存儲服務器(Chunk Server)連接的IP地址
MATOCS_LISTEN_PORT = 9420    # 是存儲服務器(Chunk server)連接的端口地址
REPLICATIONS_DELAY_INIT = 300   # 延遲復制的時間(默認是300)
CHUNKS_LOOP_MIN_TIME = 300  #  chunks 的回環率
CHUNKS_SOFT_DEL_LIMIT = 10    
CHUNKS_WRITE_REP_LIMIT = 2,1,1,4   在一個循環里復制到一個CHUNK Server的最大chunks數目
CHUNKS_READ_REP_LIMIT = 10,5,2,5
MATOCL_LISTEN_HOST = *
MATOCL_LISTEN_PORT = 9421
以上配置不需要修改,直接把配置文件copy之后就可以了。

mfsexports.cfg

[root@localhost mfs]# cp mfsexports.cfg.sample mfsexports.cfg
[root@localhost mfs]# tail mfsexports.cfg
172.16.160.0/24    .         rw,alldirs,maproot=0

參數解釋:

  1. 第一部分 172.16.160.0/24表示客戶端的IP地址,可以有以下幾種表現形式:
    • 表示所有的IP
  • n.n.n.n 單個IP
  • n.n.n.n/b IP網絡地址/位數掩碼
  • n.n.n.n/m.m.m.m IP網絡地址/子網掩碼
  • f.f.f.f-t.t.t.t ip段
  1. 第二部分 / 表示被掛接的目錄
  • /表示MooseFS的根
  • .表示MFSMETA文件系統
  1. 第三部分 rw.alldirs,maproot=0 表示客戶端擁有的權限。
    權限部分選項如下:
  • ro 只讀模式共享
  • rw 讀寫方式共享
  • alldirs 允許掛載任何指定的子目錄
  • maproot 映射為root用戶還是指定的用戶
  • password 指定客戶端密碼

metadata.mfs
默認的元數據文件為metadata.mfs.empty,啟動master server,需要重命名下

[root@localhost mfs]# cp /usr/local/mfs/var/mfs/metadata.mfs.empty /usr/local/mfs/var/mfs/metadata.mfs

啟動master server
啟動master server的命令為mfsmaster,其參數如下所示。

-v : print version number and exit
-f : run in foreground
-u : log undefined config variables
-n : do not attempt to increase limit of core dump size
-t locktimeout : how long wait for lockfile  等待lockfile的時長
-c cfgfile : use given config file
-i : ignore some metadata structure errors (attach orphans to root, ignore names without inode, etc.)
-a : automatically restore metadata from change logs
-x : produce more verbose output
-xx : even more verbose output

master server可以單獨啟動,即使沒有任何數據存儲服務器(chunk server)也能夠正常工作。啟動master server的命令如下:

[root@localhost mfs]# mfsmaster start
[root@localhost mfs]# netstat -lnpt  #查看監聽端口,確保啟動成功
Active Internet connections (only servers)
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      5944/mfsmaster      
tcp        0      0 0.0.0.0:9420                0.0.0.0:*                   LISTEN      5944/mfsmaster      
tcp        0      0 0.0.0.0:9421                0.0.0.0:*                   LISTEN      5944/mfsmaster 
'''

停止master server
安全停止master server是非常必要的,千萬不要kill,而是利用自帶的命令mfsmaster來安全停止master server。

[root@localhost mfs]# mfsmaster stop

我們安裝后采用默認的配置,沒有做任何更改,所以默認的日志是寫入/var/log/messages。

172.16.160.192安裝元數據日志服務器

下載代碼包后,解壓后開始編譯。

[root@localhost moosefs-3.0.84]# useradd mfs -s /sbin/nologin 
[root@localhost moosefs-3.0.84]# ./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs
[root@localhost moosefs-3.0.84]# make && make install

mfsmetalogger.cfg
更改配置文件

[root@localhost mfs]# cp mfsmetalogger.cfg.sample mfsmetalogger.cfg
[root@localhost mfs]# vim mfsmetalogger.cfg
[root@localhost mfs]# grep ^[a-Z] mfsmetalogger.cfg
META_DOWNLOAD_FREQ = 2         # 元數據備份文件下載請求頻率,默認是24小時,即每2小時從master server上下載一個metadata.mfs文件,當元數據服務器關閉或者故障的時候,metadata.mfs.back文件將消失,此時需要從元數據日志服務器中取得這個文件。注意,這個文件和日志文件共同使用才能恢復整個已損壞的分布式文件系統
...只需要更改上面2行就行了,其他保持默認即可如果沒有特殊要求。
MASTER_HOST = 172.16.160.191  # master server的地址

啟動元數據服務器
啟動,停止命令是mfsmetalogger :

root@localhost mfs]# cp /usr/local/mfs/sbin/mfsmetalogger /usr/sbin/
[root@localhost mfs]# mfsmetalogger start   # 啟動命令
[root@localhost mfs]# ps -ef |grep mfs 
mfs       7446     1  0 01:43 ?        00:00:00 mfsmetalogger start
root      7449  1583  0 01:43 pts/0    00:00:00 grep mfs
[root@localhost mfs]# lsof -i :9419                   # 確保端口在使用中
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mfsmetalo 7446  mfs    8u  IPv4  19768      0t0  TCP 172.16.160.192:48103->172.16.160.191:9419 (ESTABLISHED)

[root@localhost mfs]# cd /usr/local/mfs/var/mfs/      # 查看工作目錄下是否有元數據文件生成
[root@localhost mfs]# ls
changelog_ml_back.0.mfs  changelog_ml_back.1.mfs  metadata.mfs.empty  metadata_ml.mfs.back


[root@localhost mfs]# mfsmetalogger stop     # 停止服務
172.16.22.142安裝數據存儲服務器(Chunk Server)

下載代碼包后,解壓后開始編譯。

[root@salt moosefs-3.0.84]# useradd mfs -s /sbin/nologin 
[root@salt moosefs-3.0.84]# ./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs   && make && make install 

mfschunkserver

[root@salt moosefs-3.0.84]# cd /usr/local/mfs/etc/mfs/
[root@salt mfs]# cp mfschunkserver.cfg.sample mfschunkserver.cfg
[root@salt mfs]# vim mfschunkserver.cfg
[root@salt mfs]# grep ^[a-Z] mfschunkserver.cfg
MASTER_HOST = mfsmaster        # 指明master server服務器地址
MASTER_PORT = 9420             #指明master server 端口
HDD_CONF_FILENAME = /usr/local/mfs/etc/mfs/mfshdd.cfg     # 這個指明哪個配置文件來配置共享磁盤的

mfshdd

[root@salt etc]# mkdir /mnt/sdb1
[root@salt mfs]# grep ^/ mfshdd.cfg
/mnt/sdb1    # 必須把磁盤掛載在某個目錄下,直接使用硬盤或者分區是不行的。
[root@salt etc]# mkfs.ext4 /dev/sdb1
[root@salt etc]# mount /dev/sdb1 /mnt/sdb1/
[root@salt etc]# chown -R  mfs.mfs /mnt/sdb1/

啟動服務

[root@salt etc]# mfschunkserver start
[root@salt etc]# ps -ef |grep mfs
mfs       40568      1  0 02:14 ?        00:00:00 mfschunkserver start
root      40625  17565  0 02:15 pts/0    00:00:00 grep mfs

要停止服務,請使用mfschunkserver stop來停止。

172.16.22.72 安裝客戶端

安裝fuse

[root@localhost libfuse-master]# yum -y install fuse fuse-devel fuse-libs
我的yum源是CentOs6.6 安裝好后自帶的。

需要注意的是,如果采用源碼安裝fuse,那么出現 configure error,mfsmount build was forced,but the fuse development package is not installed ..

這樣的錯誤不能正確安裝MFS客戶端,是因為沒有設置環境變量,通過下面兩種方法可以解決:

第一 編輯/etc/profile ,在此文件中加入下面的內容:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

第二 直接在命令行執行
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

掛載磁盤並且使用
注意,如果使用mfsmount掛載磁盤后,df出現不了掛載MFS的記錄,那么請檢查/etc/hosts有沒有添加mfsmaster這條記錄。因為我踩的坑就是沒有添加這條記錄導致雖然提示掛載上去 了,但是無法使用mfs的盤,df也顯示不了新掛載的盤。

[root@localhost ~]# mfsmount /mnt/mfsclient/ -H mfsmaster   # mfsmaster是在/etc/hosts有記錄。
mfsmaster accepted connection with parameters: read-write,restricted_ip,admin ; root mapped to root:root
[root@localhost ~]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda2      ext4       28G  2.5G   24G  10% /
tmpfs          tmpfs     238M     0  238M   0% /dev/shm
/dev/sda1      ext4      283M   28M  240M  11% /boot
mfsmaster:9421 fuse.mfs  8.5G  278M  8.2G   4% /mnt/mfsclient   # 新增掛載的記錄

[root@localhost mfsclient]# 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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
mfsmaster:9421 on /mnt/mfsclient type fuse.mfs (rw,nosuid,nodev,allow_other)

卸載磁盤
老規矩,umount卸載即可。

[root@localhost mfsclient]# umount /mnt/mfsclient/

測試

至此,MFS已經搭建完成,我們可以來個簡單的文件寫入。

[root@localhost mfsclient]# dd if=/dev/zero of=/mnt/mfsclient/haha.iso count=100 bs=20M
100+0 records in
100+0 records out
2097152000 bytes (2.1 GB) copied, 7.14513 s, 294 MB/s

如有疑問請與本人聯系,18500777133@sina.cn


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM