您好,登錄后才能下訂單哦!
MogileFS的安裝與配置
================================================================================
概述:
================================================================================
1.簡介:
MogileFS是一個(gè)開源的分布式文件存儲系統(tǒng),由LiveJournal旗下的DangaInteractive公司開發(fā)。
Danga團(tuán)隊(duì)開發(fā)了包括Memcached、MogileFS、Perlbal等多個(gè)知名的開源項(xiàng)目。
目前使用MogileFS的公司非常多,如日本排名先前的幾個(gè)互聯(lián)公司及國內(nèi)的yupoo(又拍)、digg、豆瓣、1號店、大眾點(diǎn)評、搜狗和安居客等,分別為所在的組織或公司管理著海量的圖片。
2.MogileFS特性:
★應(yīng)用層
運(yùn)行于用戶空間,無需特殊的核心組件;
★無單點(diǎn)
MogStored:存儲多個(gè)數(shù)據(jù)副本;
Tracker:多節(jié)點(diǎn);
Database:MySQL(存放元數(shù)據(jù));
★自動文件復(fù)制
★傳輸中立,無特殊協(xié)議,可通過NFS或HTTP進(jìn)行通信
★簡單的名稱空間
diomain,class,fid(即訪問文件的key);
每個(gè)文件對應(yīng)一個(gè)key:用于domain定義名稱空間;
★不用共享任何數(shù)據(jù)
元數(shù)據(jù):DB
數(shù)據(jù):MogStored,副本
★不需要RAID
3.MogileFS組件:
★MogileFS組件:
☉Tracker:追蹤元數(shù)據(jù)
MogileFS的核心,是一個(gè)調(diào)度器;
服務(wù)進(jìn)程為mogilefsd;
職責(zé):刪除、復(fù)制、監(jiān)控、查詢等;
☉MogStored:存儲數(shù)據(jù)
mogstored進(jìn)程: 數(shù)據(jù)存儲的位置,通常是一個(gè)HTTP(WebDAV)服務(wù)器,用來數(shù)據(jù)的創(chuàng)建、刪除、獲取;
存儲節(jié)點(diǎn)需定義“設(shè)備dev”用作存儲空間;每個(gè)設(shè)備在當(dāng)前集群中需通過一個(gè)唯一的DevID標(biāo)識。
☉Database:存儲元數(shù)據(jù);
用于為tracker存儲元數(shù)據(jù)信息,mogileFS
存儲mogilefs的元數(shù)據(jù),一般使用mysql,建議使用冗余方案保證可用性(MMM,MHA)
★MogileFS服務(wù)進(jìn)程
mogilfsd (Tracker)
mogstored(MogStored)
4.MogileFS的實(shí)現(xiàn)機(jī)制和工作原理:
★實(shí)現(xiàn)機(jī)制
在該文件系統(tǒng)集群中,每一個(gè)數(shù)據(jù)塊都會有多個(gè)副本,存放于多個(gè)Storage Node上,不同的文件系統(tǒng)副本的數(shù)量各不相同(一般建議為3份),在Tracker Node上會分別單獨(dú)記錄每一個(gè)數(shù)據(jù)塊的存儲位置(位于哪個(gè)Storage及路徑)。若某個(gè)Storage節(jié)點(diǎn)不在線了,客戶端向Tracker節(jié)點(diǎn)請求獲取數(shù)據(jù)時(shí),Tracker節(jié)點(diǎn)會返回用于冗余的副本的存儲位置給客戶端。這樣就保證了整個(gè)文件系統(tǒng)中數(shù)據(jù)的高可用性。當(dāng)有數(shù)據(jù)存儲至某一storage節(jié)點(diǎn)后,各storage節(jié)點(diǎn)會根據(jù)Tracker的指示通過節(jié)點(diǎn)間通信將副本發(fā)送至其他節(jié)點(diǎn)上。若某一storage下線了,該節(jié)點(diǎn)上的副本會由其他節(jié)點(diǎn)重新提供,保證副本的個(gè)數(shù)不少于指定的值。
★工作原理
客戶端需要存取數(shù)據(jù)時(shí),首先與Tracker進(jìn)行交互,Tracker通過查詢數(shù)據(jù)庫來獲取客戶端存取數(shù)據(jù)時(shí)所需要訪問的元數(shù)據(jù),然后返回給客戶端,客戶端利用Tracker返回的結(jié)果,與Storage Nodes節(jié)點(diǎn)進(jìn)行交互完成數(shù)據(jù)存?。ㄒ淮斡锌赡苈?lián)系一個(gè)也可能聯(lián)系多個(gè))。
附圖:
5.MogileFS中的術(shù)語:
☉tracker
借助數(shù)據(jù)庫保存各個(gè)節(jié)點(diǎn)文件的元數(shù)據(jù)信息, 便于檢索定位數(shù)據(jù)位置并監(jiān)控各個(gè)節(jié)點(diǎn), 告知客戶端存儲區(qū)的位置并指揮storage節(jié)點(diǎn)復(fù)制數(shù)據(jù)副本, 進(jìn)程為mogilefsd;
☉databases
為tracker節(jié)點(diǎn)存儲節(jié)點(diǎn)文件的元數(shù)據(jù)信息;
☉storage
將指定域中的鍵轉(zhuǎn)換為特有的文件名存儲于在特定的設(shè)備文件中, 轉(zhuǎn)換后文件名為值, storage自動維護(hù)鍵值之間的對應(yīng)關(guān)系, storage節(jié)點(diǎn)使用http進(jìn)行數(shù)據(jù)傳輸, 依賴于perbal, 進(jìn)程為mogstored, perbal;
☉Domain
一個(gè)域中的鍵值是唯一的, 一個(gè)MogileFS可以有多個(gè)域來存儲不同類型的文件,同一個(gè)Domain內(nèi)Key必須唯一,不同的Domain內(nèi)Key可以相同;
☉Class
一個(gè)域中的鍵值是唯一的, 一個(gè)MogileFS可以有多個(gè)域來存儲不同類型的文件,同一個(gè)Domain內(nèi)Key必須唯一,不同的Domain內(nèi)Key可以相同;
☉device
一個(gè)存儲節(jié)點(diǎn), 可以有多個(gè)device, 就是用來存放文件的目錄, 每個(gè)設(shè)備都有一個(gè)設(shè)備ID, 需要在mogstored配置文件中docroot配置, 設(shè)備不能刪除, 只能將設(shè)備的狀態(tài)置為dead, 置為dead之后數(shù)據(jù)就無法恢復(fù)了, 并且設(shè)備ID也無法再使用;
附圖:
1.perl模塊的安裝方式:
★online(在線):
yum -y install make gcc unzip perl-DBD-MySQL perl perl-CPAN perl-YAML perl-Time-HiRes
執(zhí)行命令 : perl -MCPAN -e shell 進(jìn)入 perl 依賴包安裝模式 (或執(zhí)行 cpan -i module_name::name)
cpan install App::cpanminus
cpan install MogileFS::Server
cpan install MogileFS::Utils
cpan install IO::AIO
cpan install IO::WrapTie
cpan install Danga::Socket★offline(線下):要大量解決依賴關(guān)系
$ perl Makefile.PL
$ make
$ sudo make install
★rpm
☉MogileFS安裝:
tracker:
$ yum install MogileFS-Server-VERSION.rpm MogileFS-Server-mogilefsd-VERSION.rpm
mogstored:
$ yum install perl-IO-AIO
$ yum install MogileFS-Server-VERSION.rpm MogileFS-Server-mogstored-VERSION.rpm
實(shí)驗(yàn):MofileFS的安裝和配置
環(huán)境描述:
兩臺CentOS 7的虛擬主機(jī)node1和node2,node1即作為tracker又作為mogstore存儲節(jié)點(diǎn),同時(shí)還是mysql服務(wù)器;node2為tracker和mogstaor節(jié)點(diǎn);
實(shí)驗(yàn)步驟:
1.首先在noge1上使用CPAN工具在線安裝perl模塊及mogilefs
[root@centos7 ~]# yum -y install make gcc unzip perl-DBD-MySQL perl perl-CPAN perl-YAML perl-Time-HiRes [root@centos7 ~]# perl -MCPAN -e shell cpan >install App::cpanminus cpan >install MogileFS::Server cpan >install MogileFS::Utils cpan >install IO::AIO cpan >install IO::WrapTie cpan >install Danga::Socket #========================================================================================= # 安裝后各程序版本如下: [root@centos7 ~]# cpan Sys::Syscall Reading '/root/.cpan/Metadata' Database was generated on Thu, 05 Jan 2017 18:41:02 GMT Sys::Syscall is up to date (0.25). [root@centos7 ~]# cpan MogileFS::Server Reading '/root/.cpan/Metadata' Database was generated on Thu, 05 Jan 2017 18:41:02 GMT MogileFS::Server is up to date (2.72). [root@centos7 ~]# cpan MogileFS::Utils Reading '/root/.cpan/Metadata' Database was generated on Thu, 05 Jan 2017 18:41:02 GMT MogileFS::Utils is up to date (2.29). [root@centos7 ~]# cpan IO::AIO Reading '/root/.cpan/Metadata' Database was generated on Thu, 05 Jan 2017 18:41:02 GMT IO::AIO is up to date (4.34). [root@centos7 ~]# cpan IO::WrapTie Reading '/root/.cpan/Metadata' Database was generated on Thu, 05 Jan 2017 18:41:02 GMT IO::WrapTie is up to date (2.111). [root@centos7 ~]# cpan Danga::Socket Reading '/root/.cpan/Metadata' Database was generated on Thu, 05 Jan 2017 18:41:02 GMT Danga::Socket is up to date (1.61).
2.在node1上安裝MySQL(略),創(chuàng)建數(shù)據(jù)庫,添加管理用戶
[root@centos7 ~]# mysql -ptaoxiu Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 11 Server version: 5.5.44-MariaDB MariaDB Server Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database mogfsdb; # 創(chuàng)建數(shù)據(jù)庫 MariaDB [(none)]> grant all privileges on mogfsdb.* to 'moguser'@'127.0.0.1' identified by 'mogpass'; MariaDB [(none)]> grant all privileges on mogfsdb.* to 'moguser'@'192.168.1.113' identified by 'mogpass'; MariaDB [(none)]> flush privileges;
3.初始化數(shù)據(jù)庫
[root@centos7 ~]# mogdbsetup --dbhost='127.0.0.1' --dbname=mogfsdb --dbuser=moguser --dbpass=mogpass --type=MySQL This will attempt to setup or upgrade your MogileFS database. It won't destroy existing data. Run with --help for more information. Run with --yes to shut up these prompts. Continue? [N/y]: y
查看數(shù)據(jù)庫如下:
[root@centos7 ~]# mysql -ptaoxiu Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 5.5.44-MariaDB MariaDB Server Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | Syslog | | hellodb | | jingdong | | mogfsdb | | mysql | | ultrax | | zabbix | +--------------------+ 8 rows in set (0.12 sec) MariaDB [(none)]> use mogfsdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [mogfsdb]> show tables; # 生成的表 +----------------------+ | Tables_in_mogfsdb | +----------------------+ | checksum | | class | | device | | domain | | file | | file_on | | file_on_corrupt | | file_to_delete | | file_to_delete2 | | file_to_delete_later | | file_to_queue | | file_to_replicate | | fsck_log | | host | | server_settings | | tempfile | | unreachable_fids | +----------------------+ 17 rows in set (0.00 sec) MariaDB [mogfsdb]> exit
配置tracker節(jié)點(diǎn),
1.在/etc目錄下創(chuàng)建mogilefs目錄,并提供配置文件mogilefsd.conf,如下:
[root@centos7 ~]# mkdir /etc/mogilefs [root@centos7 ~]# vim /etc/mogilefs/mogilefsd.conf # Enable daemon mode to work in background and use syslog daemonize = 1 # Where to store the pid of the daemon (must be the same in the init script) pidfile = /var/run/mogilefsd/mogilefsd.pid # 指定pid文件位置 # Database connection information db_dsn = DBI:mysql:mogfsdb:host=127.0.0.1 # 修改為上面授權(quán)的賬號和密碼 db_user = moguser # mysql用戶 db_pass = mogpass # mysql密碼 # IP:PORT to listen on for mogilefs client requests listen = 0.0.0.0:7001 # 監(jiān)聽的地址和端口(所有地址的7001端口) # Optional, if you don't define the port above. conf_port = 7001 # Number of query workers to start by default. query_jobs = 10 # 用于查詢的進(jìn)程數(shù) # Number of delete workers to start by default. delete_jobs = 1 # 用于刪除操作的進(jìn)程數(shù) # Number of replicate workers to start by default. replicate_jobs = 5 # 用于復(fù)制的進(jìn)程數(shù) # Number of reaper workers to start by default. # (you don't usually need to increase this) reaper_jobs = 1 # 用于回收資源的進(jìn)程數(shù) # Number of fsck workers to start by default. # (these can cause a lot of load when fsck'ing) #fsck_jobs = 1 # Minimum amount of space to reserve in megabytes # default: 100 # Consider setting this to be larger than the largest file you # would normally be uploading. #min_free_space = 200 # Number of seconds to wait for a storage node to respond. # default: 2 # Keep this low, so busy storage nodes are quickly ignored. #node_timeout = 2 # Number of seconds to wait to connect to a storage node. # default: 2 # Keep this low so overloaded nodes get skipped. #conn_timeout = 2 # Allow replication to use the secondary node get port, # if you have apache or similar configured for GET's #repl_use_get_port = 1
2.創(chuàng)建pid文件目錄并賦予權(quán)限,然后啟動服務(wù)。
# mogilefsd不能以root身份運(yùn)行,必須用其他用戶運(yùn)行,為此添加mogilefs用戶,然后啟動服務(wù) [root@centos7 ~]# useradd -r mogilefs # 創(chuàng)建pid文件目錄并修改屬主屬組為mogilefs [root@centos7 ~]# mkdir /var/run/mogilefsd/ -p [root@centos7 ~]# chown -R mogilefs.mogilefs /var/run/mogilefsd/ # 啟動服務(wù) [root@centos7 mogilefs]# su - mogilefs -c "mogilefsd -c /etc/mogilefs/mogilefsd.conf --daemon" su: warning: cannot change directory to /home/mogilefs: No such file or directory # 查看端口7001 [root@centos7 mogilefs]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 25 *:514 *:* LISTEN 0 50 *:3306 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 128 *:7001 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6010 *:* LISTEN 0 25 :::514 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 ::1:6010 :::*
接下來配置 mogstore節(jié)點(diǎn),
1.編輯配置文件 vim /etc/mogilefs/mogstored.conf如下:
[root@centos7 ~]# vim /etc/mogilefs/mogstored.conf maxconns = 10000 # 最大并發(fā)連接數(shù) httplisten = 0.0.0.0:7500 # 監(jiān)聽端口 mgmtlisten = 0.0.0.0:7501 # 管理端口,探測mogstore的健康狀態(tài) docroot = /data/mogstored # 數(shù)據(jù)存放位置
2.提供數(shù)據(jù)存放目錄/data/mogstored,分區(qū),格式化,掛載設(shè)備,并修改屬主屬組為mogilefs
[root@centos7 ~]# mkdir -pv /data/mogstored # 添加磁盤dev(生產(chǎn)環(huán)境中要把磁盤設(shè)備分區(qū),創(chuàng)建文件系統(tǒng),掛載到此目錄下,這里為了測試創(chuàng)建目錄dev) [root@centos7 ~]# mkdir /data/mogstored/dev{1,2} # 修改屬主屬組為mogilefs [root@centos7 ~]# chown -R mogilefs:mogilefs /data/mogstored/ [root@centos7 mogstored]# ll total 0 drwxr-xr-x 2 mogilefs mogilefs 6 Jan 5 15:52 dev1 drwxr-xr-x 2 mogilefs mogilefs 6 Jan 5 15:52 dev2 # 生產(chǎn)環(huán)境中分區(qū),格式化,掛載文件系統(tǒng),并授權(quán) # fdisk /dev/sdb # mkfs.ext4 /dev/sdb1 # mkdir /mystore/dev1 -pv # mount /dev/sdb1 /mystore/dev1 # chown -R mogilefs.mogilefs /data/mogstored/dev1
3.啟動服務(wù),并查看端口7500,7501
[root@centos7 mogstored]# su - mogilefs -c "mogstored -c /etc/mogilefs/mogstored.conf --daemon" su: warning: cannot change directory to /home/mogilefs: No such file or directory [root@centos7 mogstored]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 25 *:514 *:* LISTEN 0 50 *:3306 *:* LISTEN 0 128 *:7500 *:* LISTEN 0 128 *:7501 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 128 *:7001 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6010 *:* LISTEN 0 25 :::514 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 ::1:6010 :::*
在節(jié)點(diǎn)node2上同樣配置mogstore存儲節(jié)點(diǎn),如下:
1.同樣適用CPAN在線安裝perl相關(guān)模塊和mogilefs,存儲節(jié)點(diǎn)要解決依賴關(guān)系,安裝perl-IO-AIO
[root@centos7 ~]# yum -y install make gcc unzip perl-DBD-MySQL perl perl-CPAN perl-YAML perl-Time-HiRes perl-IO-AIO [root@centos7 ~]# perl -MCPAN -e shell cpan >install App::cpanminus cpan >install MogileFS::Server cpan >install MogileFS::Utils cpan >install IO::AIO cpan >install IO::WrapTie cpan >install Danga::Socket
2.在/etc下創(chuàng)建目錄,并提供mogstore的配置文件mogstored.conf
[root@centos7 ~]# mkdir /etc/mogilefs [root@centos7 ~]# vim /etc/mogilefs/mogstored.conf maxconns = 10000 httplisten = 0.0.0.0:7500 mgmtlisten = 0.0.0.0:7501 docroot = /data/mogstored
3.創(chuàng)建mogilefs用戶,提供數(shù)據(jù)存放目錄/data/mogstored,分區(qū),格式化,掛載設(shè)備,并修改屬主屬組為mogilefs
[root@centos7 ~]# useradd -r mogilefs [root@centos7 ~]# mkdir -pv /data/mogstored/dev{3,4} # 兩個(gè)節(jié)點(diǎn)設(shè)備不能相同,且為小寫 mkdir: created directory ‘/data/mogstored’ mkdir: created directory ‘/data/mogstored/dev3’ mkdir: created directory ‘/data/mogstored/dev4’ [root@centos7 ~]# chown -R mogilefs:mogilefs /data/mogstored/ [root@centos7 ~]# cd /data/mogstored/ [root@centos7 mogstored]# ll total 0 drwxr-xr-x 2 mogilefs mogilefs 6 Jan 5 15:22 dev3 drwxr-xr-x 2 mogilefs mogilefs 6 Jan 5 15:22 dev4
4.啟動服務(wù),查看端口
[root@centos7 ~]# su - mogilefs -c "mogstored -c /etc/mogilefs/mogstored.conf --daemon" su: warning: cannot change directory to /home/mogilefs: No such file or directory [root@centos7 ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *:3306 *:* LISTEN 0 128 *:7500 *:* LISTEN 0 128 *:7501 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6011 *:* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 ::1:6011 :::*
如上,我們就有了一個(gè)tracker和兩個(gè)mogstore,接下來我們可以在控制節(jié)點(diǎn)上使用MogileFS-Utils,進(jìn)行添加host,device,domain,class等管理操作。
1.使用mogadm命令添加存儲節(jié)點(diǎn)mogstore
[root@centos7 ~]# mogadm host add node1 --ip=192.168.1.112 --status=alive --port=7500 [root@centos7 ~]# mogadm host add node2 --ip=192.168.1.113 --status=alive --port=7500 [root@centos7 ~]# mogadm host list node1 [1]: alive IP: 192.168.1.112:7500 node2 [2]: alive IP: 192.168.1.113:7500
2.使用mogadm命令添加存儲節(jié)點(diǎn)device,注意,前面掛載的設(shè)備必須為小寫dev且個(gè)存儲節(jié)點(diǎn)名稱不能相同
[root@centos7 ~]# mogadm device add node1 1 --status=alive [root@centos7 ~]# mogadm device add node2 3 --status=alive [root@centos7 ~]# mogadm device add node2 4 --status=alive [root@centos7 ~]# mogadm device list node1 [1]: alive used(G) free(G) total(G) weight(%) dev1: alive 3.674 36.307 39.980 100 node2 [2]: alive used(G) free(G) total(G) weight(%) dev3: alive 0.398 39.582 39.980 100 dev4: alive 0.398 39.582 39.980 100
3.添加domain域或者類class
[root@centos7 ~]# mogadm domain list domain class mindevcount replpolicy hashtype -------------------- -------------------- ------------- ------------ ------- [root@centos7 ~]# mogadm domain add files [root@centos7 ~]# mogadm domain add p_w_picpaths [root@centos7 ~]# mogadm domain list domain class mindevcount replpolicy hashtype -------------------- -------------------- ------------- ------------ ------- files default 2 MultipleHosts() NONE p_w_picpaths default 2 MultipleHosts() NONE # mindevcount:默認(rèn)最小設(shè)備數(shù)為2,即默認(rèn)創(chuàng)建了兩個(gè)副本 # replpolicy:復(fù)制策略為多主機(jī)復(fù)制 # hashtype:哈希類型,NOME表示不自定義,使用默認(rèn)值 [root@centos7 ~]# mogadm class list domain class mindevcount replpolicy hashtype -------------------- -------------------- ------------- ------------ ------- files default 2 MultipleHosts() NONE p_w_picpaths default 2 MultipleHosts() NONE
4.查看檢測狀態(tài)
[root@centos7 ~]# mogadm check Checking trackers... # tracker識別OK 127.0.0.1:7001 ... OK Checking hosts... # 主機(jī)識別OK [ 1] node1 ... OK [ 2] node2 ... OK Checking devices... # 設(shè)備識別OK host device size(G) used(G) free(G) use% ob state I/O% ---- ------------ ---------- ---------- ---------- ------ ---------- ----- [ 1] dev1 39.980 3.734 36.247 9.34% writeable 0.1 [ 2] dev3 39.980 0.432 39.549 1.08% writeable 0.0 [ 2] dev4 39.980 0.432 39.549 1.08% writeable 0.0 ---- ------------ ---------- ---------- ---------- ------ total: 119.941 4.597 115.345 3.83%
5.使用mogupload命令上傳文件
[root@centos7 ~]# mogupload --help # 上傳文件 Usage: /usr/local/bin/mogupload --trackers=host --domain=foo --key='/hello.jpg' --file='./hello.jpg' [root@centos7 ~]# mogupload --trackers=192.168.1.112 --domain=files --key='/fstab.txt' --file='/etc/fstab' [root@centos7 ~]# mogupload --trackers=192.168.1.112 --domain=p_w_picpaths --key='/2.jpg' --file='/root/man.jpg' [root@centos7 ~]# moglistkeys --help # 列出文件 Usage: /usr/local/bin/moglistkeys --trackers=host --domain=foo --key_prefix='bar/' [root@centos7 ~]# moglistkeys --trackers=192.168.1.112 --domain=files /fstab.txt [root@centos7 ~]# moglistkeys --trackers=192.168.1.112 --domain=p_w_picpaths /2.jpg
6.使用mogfileinfo查看文件信息,如下:
[root@centos7 ~]# mogfileinfo --trackers=192.168.1.112 --domain=files --key='/fstab.txt' - file: /fstab.txt class: default devcount: 1 domain: files fid: 2 key: /fstab.txt length: 690 -- http://192.168.1.112:7500/dev1/0/000/000/0000000002.fid #可通過此URL訪問到相應(yīng)的資源 [root@centos7 ~]# mogfileinfo --trackers=192.168.1.112 --domain=p_w_picpaths --key='/2.jpg' - file: /man.jpg class: default devcount: 1 domain: imgs fid: 3 key: /man.jpg length: 3401017 - http://192.168.1.112:7500/dev1/0/000/000/0000000010.fid
通過URL訪問其資源如下:
注意:
上面實(shí)驗(yàn)可以看到,上傳的文件僅在一個(gè)主機(jī)設(shè)備上存放,實(shí)際上應(yīng)該是兩個(gè)節(jié)點(diǎn)都存放才對。我從網(wǎng)上查到出錯(cuò)的原因可能是由于Sys::Syscall這個(gè)模塊造成的。我們看到現(xiàn)在此模塊的版本為0.25。我上網(wǎng)搜索其解決辦法,發(fā)現(xiàn)如果將此軟件降為0.23版本可能會修復(fù)此問題,咱們試試看:
# 編譯之前安裝的版本為 0.25 [root@centos7 Sys-Syscall-0.23]# perl -MSys::Syscall -e 'print $Sys::Syscall::VERSION' 0.25
# 下載源碼包并編譯安裝
wget http://search.cpan.org/CPAN/authors/id/B/BR/BRADFITZ/Sys-Syscall-0.23.tar.gz
tar xf Sys-Syscall-0.23.tar.gz
cd Sys-Syscall-0.23
perl Makefile.PL
make
make test
make install
重啟mogilefsd進(jìn)程,然后再上傳一個(gè)文件,成功解決問題,如下:
[root@centos7 ~]# mogupload --trackers=192.168.1.112 --domain=p_w_picpaths --key='/1.jpg' --file='/root/1.jpg' [root@centos7 ~]# mogfileinfo --trackers=192.168.1.112 --domain=p_w_picpaths --key='/1.jpg' - file: /1.jpg class: default devcount: 2 domain: p_w_picpaths fid: 9 key: /1.jpg length: 31249077 - http://192.168.1.112:7500/dev1/0/000/000/0000000009.fid - http://192.168.1.113:7500/dev3/0/000/000/0000000009.fid
7.使用mogstats指明連接的數(shù)據(jù)庫,用戶和密碼,查看狀態(tài),如下:
[root@centos7 ~]# mogstats --db_dsn="DBI:mysql:mogdb:host=127.0.0.1" --db_user="moguser" --db_pass="mogpass" --stats="all" Fetching statistics... (all) Statistics for devices... device host files status ---------- ---------------- ------------ ---------- dev1 node1 5 alive dev3 node2 4 alive dev4 node2 1 alive ---------- ---------------- ------------ ---------- Statistics for file ids... Max file id: 9 Statistics for files... domain class files size (m) fullsize (m) -------------------- ----------- ---------- ----------- ------------- files default 2 0 0 p_w_picpaths default 3 32 64 -------------------- ----------- ---------- ----------- ------------- Statistics for replication... domain class devcount files -------------------- ----------- ---------- ---------- files default 2 2 p_w_picpaths default 2 3 -------------------- ----------- ---------- ---------- Statistics for replication queue... status count -------------------- ------------ -------------------- ------------ Statistics for delete queue... status count -------------------- ------------ -------------------- ------------ Statistics for general queues... queue status count --------------- -------------------- ------------ --------------- -------------------- ------------ done
如上,為node1為tracker、mogstore和mysql節(jié)點(diǎn),node2僅為mogstore節(jié)點(diǎn),現(xiàn)在添加node2也為tracker節(jié)點(diǎn),如下:
1.復(fù)制node1節(jié)點(diǎn)tracker的配置文件/etc/mogilefs/mogilefsd.conf到node2下
[root@centos7 ~]# scp /etc/mogilefs/mogilefsd.conf node2:/etc/mogilefs/mogilefsd.conf
2.在node2節(jié)點(diǎn)上編輯配置文件mogilefsd.conf,修改連接數(shù)據(jù)庫的信息,如下:
3.創(chuàng)建pid文件目錄并賦予權(quán)限,然后啟動服務(wù)。
[root@centos7 ~]# mkdir /var/run/mogilefsd/ -p [root@centos7 ~]# chown -R mogilefs.mogilefs /var/run/mogilefsd/ [root@centos7 ~]# su - mogilefs -c "mogilefsd -c /etc/mogilefs/mogilefsd.conf --daemon" # 查看端口7001 [root@centos7 ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:7500 *:* LISTEN 0 128 *:7501 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 128 *:7001 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6010 *:* LISTEN 0 128 127.0.0.1:6011 *:* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 ::1:6010 :::* LISTEN 0 128 ::1:6011 :::*
4.使用mogadm查看host,device,domain,并上傳文件,如下:
[root@centos7 ~]# mogadm host list # 查看host node1 [1]: alive IP: 192.168.1.112:7500 node2 [2]: alive IP: 192.168.1.113:7500 [root@centos7 ~]# mogadm device list node1 [1]: alive used(G) free(G) total(G) weight(%) dev1: alive 3.673 36.308 39.980 100 node2 [2]: alive used(G) free(G) total(G) weight(%) dev3: alive 0.399 39.581 39.980 100 dev4: alive 0.399 39.581 39.980 100 [root@centos7 ~]# mogadm domain list domain class mindevcount replpolicy hashtype -------------------- -------------------- ------------- ------------ ------- files default 2 MultipleHosts() NONE p_w_picpaths default 2 MultipleHosts() NONE # 上傳文件 [root@centos7 ~]# mogupload --trackers=192.168.1.113 --domain=p_w_picpaths --key='/2.jpg' --file='/root/2.jpg' [root@centos7 ~]# mogfileinfo --trackers=192.168.1.113 --domain=p_w_picpaths --key='/2.jpg' - file: /2.jpg class: default devcount: 2 domain: p_w_picpaths fid: 10 key: /2.jpg length: 1247365 - http://192.168.1.112:7500/dev1/0/000/000/0000000010.fid - http://192.168.1.113:7500/dev4/0/000/000/0000000010.fid
如上,就是整個(gè)分布式文件系統(tǒng)MogileFS安裝部署的整個(gè)過程。。。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。