Linux搭建FastFDFS文件管理系統搭建,部署及上傳材料


昨天下午花了三四個小時在Linux centos 6 上搭建了一個分布式文件系統。純粹是搭建來做自己的文件備份。所以把一些自己在其中遇到的一些問題給總結出來,免得更多人走錯路。

 

 FastDFS 的一些介紹(英文來自官方github):

 

FDFS , 開源分布式文件系統。主要的功能是:文件存儲,同步,存取(上傳和下載),它可以解決高容量和運載平衡的問題。FastDFS是符合了那些 圖片,視頻,照片分享的網站的需求。

FDFS 有分別有 tracker 和 storage 兩個角色。tracker 負責安排和平衡文件的操作。storage 負責存儲文件和其它對文件的操作(文件的保存,同步,提供訪問文件的接口)。通過key&value文件的方式進行展現元數據。例如:width=1024,key為width 則 value為"1024" 

trackerd 可以是一個或者多個的服務器。在 tracker 集群或者 storaged 集群中你可以隨時隨地可以添加或者移除集群而絲毫不影響在線的網站。tracker 集群變得越來越流行了。

storaged  組合文件的容量或者群組去獲得高容量。storage 系統包含着一個或者多個在這些沒有任何聯系的容量卷。整個storage 系統的容量相當於所有容量的總和。一個文件卷可以包含一個或更多的存儲類型是相同的storaged 服務器。

當整個storage 的容量爆了,你可以繼續添加更多的卷去擴大內存。所以,你需要更多的服務器。...

卷名和文件名是組成身份認證的兩個部分。

客戶端測試的代碼請參考目錄:client / test

 

 

FastDFS的搭建過程:

從搭建部署到測試成功需要 9 步:

 

#step 1. download libfastcommon source package from github and install it,

   the github address:

   https://github.com/happyfish100/libfastcommon.git

  下載libfastcommon 資源包 

 

#step 2. download FastDFS source package and unpack it, 

tar xzf FastDFS_v5.x.tar.gz

#for example:

tar xzf FastDFS_v5.08.tar.gz

  下載FastDFS 的資源包並解壓

 

#step 3. enter the FastDFS dir

cd FastDFS

   進入FastDFS解壓后的文件夾

#step 4. execute:

./make.sh

   安裝

   

 

#step 5. make install

./make.sh install

   安裝

#step 6. edit/modify the config file of tracker and storage

   修改 tracker.conf 和 storage.conf 兩個配置文件 

 

#step 7. run server programs

#start the tracker server:

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

#in Linux, you can start fdfs_trackerd as a service:

/sbin/service fdfs_trackerd start

 

 

#start the storage server:

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

#in Linux, you can start fdfs_storaged as a service:

/sbin/service fdfs_storaged start

   其中storage 和 tracker 兩個服務

 

#step 8. run test program

#run the client test program:

/usr/bin/fdfs_test <client_conf_filename> <operation>

/usr/bin/fdfs_test1 <client_conf_filename> <operation>

#for example, upload a file:

/usr/bin/fdfs_test conf/client.conf upload /usr/include/stdlib.h

    測試 

  

#step 9. run monitor program

#run the monitor program:

/usr/bin/fdfs_monitor <client_conf_filename>

    通過moniter檢測項目運行情況

 

 

 

 

接下來我們進行正確的步驟:

 

所需軟件包的github地址:

FastDFS       : https://github.com/happyfish100/fastdfs.git  

libfastcommon : https://github.com/happyfish100/libfastcommon.git  

 

所需的的環境:

Linux centos 6.5或者以上

如果系統沒有gcc,那就命令行( yum install gcc )進行安裝

 

 

 

下載:

 

cd /opt && mkdir fastdfs && cd fastdfs                            #在opt目錄下建立文件夾 fastdfs 
git clone https://github.com/happyfish100/fastdfs.git                  #下載FastDFS
git clone https://github.com/happyfish100/libfastcommon.git               #下載libfastcommon
cd /opt/fastdfs/libfastcommon                                #進入目錄進行安裝
./make.sh && ./make.sh install  
cd /opt/fastdfs/fastdfs  
./make.sh && ./make.sh install  

 

 

配置文件:

所有的配置文件都在 /usr/bin/fdfs/ 下 :

client.conf.sample  storage.conf.sample  storage_ids.conf.sample  tracker.conf.sample

 

cd /etc/fdfs
mv tracker.conf.sample  tracker.conf
mv storage.conf.sample storage.conf.sample
mv client.conf.sample client.conf.sample

 

 

 

修改配置文件的內容如下:

storage.conf

# the base path to store data and log files
base_path=/mnt/xfsd/fastdfs/storage

# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/mnt/xfsd/fastdfs/storage

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=host:22122


#standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=debug

# the port of the web server on this storage server
http.server_port=80

 

 

bash_path 是storage存儲的數據和日志的地址

store_path0 和bash_path一樣,只不過這個是優先存儲的地址,如果不存在,默認是bash_path

tracker_server 是指tracker服務角色的 地址:端口。(如果tracker 和 storage 是同一個服務器的話,那么就填寫服務器的ip和地址。)

log_level 是輸出日志的級別設計

http.server_port 是http服務的接受端口

 

tracker.conf

# the tracker server port
port=22122

# the base path to store data and log files
base_path=/mnt/xfsd/fastdfs/tracker/


# HTTP port on this tracker server
http.server_port=80

 

 

修改后可以啟動服務了

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf  (start | restart | stop)
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf  (start | restart | stop)

 

檢查服務:

/usr/bin/fdfs_moniter /etc/fdfs/storaged.conf 

開啟端口(我用的是iptables,簡單便捷就可以配置了,可以去網上看下怎么安裝iptables):

 

 

最后,進行測試:

fdfs_delete_file              # 刪除文件       
fdfs_upload_file               #上傳文件
fdfs_test                         # 測試文件
fdfs_download_file                    #下載文件

 

拿fdfs_test來測試:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /目標文件路徑 

 

成功后會有以下信息:

 


免責聲明!

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



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