1. 程式人生 > >FastDFS安裝配置

FastDFS安裝配置

FastDFS是一個開源的輕量級分散式檔案系統,它對檔案進行管理,功能包括:檔案儲存、檔案同步、檔案訪問(檔案上傳、檔案下載)等,解決了大容量儲存和負載均衡的問題。特別適合以檔案為載體的線上服務,如相簿網站、視訊網站等等。詳細介紹請自行百度(www.baidu.com)。

接下來我們就來具體配置和安裝,我的伺服器是LNMP

  • 在此之前首先要確定LAMP或LNMP環境已經搭建好

libfastcommon安裝

[email protected]:~# wget https://github.com/happyfish100/libfastcommon/archive/master.zip
[email protected]
:~# unzip master.zip [email protected]:~# cd libfastcommon-master [email protected]:~/libfastcommon-master# ./make.sh ... [email protected]:~/libfastcommon-master# ./make.sh install ...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

FastFDS安裝

[email protected]:~# wget https://github.com/happyfish100/fastdfs/archive/master.zip
[email protected]
:~# unzip fastdfs-master.zip [email protected]:~# cd fastdfs-master.zip [email protected]:~/fastdfs-master# ./make.sh ... [email protected]:~/fastdfs-master# ./make.sh install ...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

至此FastFDS已經成功安裝到伺服器上了,接下來就需要做一些配置

FastDFS配置

root@test:~# cd /etc/fdfs/
root@test:/etc/fdfs/# ls
client.conf.sample  storage.conf.sample  tracker.conf.sample
root@test
:/etc/fdfs/# cp client.conf.sample client.conf root@test:/etc/fdfs/# cp storage.conf.sample storage.conf root@test:/etc/fdfs/# cp tracker.conf.sample tracker.conf root@test:/etc/fdfs/# find ~/fastdfs-master/ -name http.conf /root/fastdfs-master/conf/http.conf root@test:/etc/fdfs/# cp /root/fastdfs-master/conf/http.conf /etc/fdfs/http.conf root@test:/etc/fdfs/# vim tracker.conf
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在tracker.conf中找到


# the base path to store data and log files

base_path=/home/yuqing/fastdfs
...
http.server_port=80
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

改為


# the base path to store data and log files

base_path=/data/fastdfs
...
http.server_port=8088
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

儲存退出,如果80埠不被佔用可以不做更改 
並在根目錄下新建data資料夾和data資料夾下的字資料夾fastdfs

root@test:/etc/fdfs/# mkdir /data
root@test:/etc/fdfs/# mkdir /data/fastdfs
  • 1
  • 2
  • 1
  • 2
root@test:/etc/fdfs/# vim storage.conf
  • 1
  • 1

在storage.conf中找到


# the base path to store data and log files

base_path=/home/yuqing/fastdfs

# tracker_server can ocur more than once, and tracker_server format is


#  "host:port", host can be hostname or ip address

tracker_server=192.168.1.36:22122

# store_path#, based 0, if store_path0 not exists, it's value is base_path


# the paths must be exist

store_path0=/home/yuqing/fastdfs
...
http.server_port=80
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

改為


# the base path to store data and log files

base_path=/data/fastdfs

# tracker_server can ocur more than once, and tracker_server format is


#  "host:port", host can be hostname or ip address

tracker_server=192.168.1.36:22122

# store_path#, based 0, if store_path0 not exists, it's value is base_path


# the paths must be exist

store_path0=/data/fastdfs
...
http.server_port=8088
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

其中tracker_server部分的IP為自己的tracker伺服器IP,如果沒有改成localhost也是可以的

FastDFS啟動

接下來就是激動人心的時刻了,輸入以下命令來啟動服務

root@test:~# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
root@test:~# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
  • 1
  • 2
  • 1
  • 2

通過ps -ef | grep fdfs來檢視fdfs程序是否存在

root@test:~# ps -ef | grep fdfs
root      2973     1  0 11:16 ?        00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
root      2988     1  0 11:16 ?        00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
root      2993  2803  0 11:17 pts/0    00:00:00 grep fdfs
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

測試上傳

root@test:~# cd /etc/fdfs/
root@test:/etc/fdfs/# vim client.conf
  • 1
  • 2
  • 1
  • 2

在client.conf中找到


# the base path to store log files

base_path=/home/yuqing/fastdfs

# tracker_server can ocur more than once, and tracker_server format is


#  "host:port", host can be hostname or ip address

tracker_server=192.168.0.197:22122
...
http.tracker_server_port=80
...

##include http.conf
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

改為

># the base path to store log files
base_path=/data/fastdfs

# tracker_server can ocur more than once, and tracker_server format is


#  "host:port", host can be hostname or ip address

tracker_server=192.168.0.197:22122
...
http.tracker_server_port=8088
...

#include http.conf
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

這裡的埠號http.tracker_server_port=8088一定要和tracker.conf中的埠號一致

[email protected]:~# echo 'fastDFS_test' >/tmp/test.txt
[email protected]:~# fdfs_test /etc/fdfs/client.conf upload /tmp/test.txt
...
example file url: http://114.215.131.59:8088/group1/M00/00/00/cteDO1cCB1eAFeqeAAAADVt_Kt4115_big.txt
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

如果出現最下面的URL則說明環境搭建成功

php FastDFS擴充套件安裝

root@test:~# cd /fastdfs/php_client/
root@test:/fastdfs/php_client/# phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
root@test:/fastdfs/php_client/# ./configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /bin/grep
...
config.status: creating config.h
config.status: executing libtool commands
root@test:/fastdfs/php_client/# make
...
Build complete.
Don`t forget to run 'make test'.
root@test:/fastdfs/php_client/# make install
Installing shared extensions:     /usr/lib/php5/20100525/
root@test:/fastdfs/php_client/# cat /root/fastdfs/php_client/fastdfs_client.ini >> /etc/php5/fpm/php.ini
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

至此PHP FastDFS擴充套件已經安裝完成,重啟伺服器後進行測試

php FastDFS測試驗證

root@test:~# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
root@test:~# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
root@test:~# cp /root/fastdfs/php_client/fastdfs_test.php /usr/share/nginx/www/
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

然後用瀏覽器開啟,http://遠端伺服器地址/fasrdfs_test.php 
如果出現

5.08 fastdfs_tracker_make_all_connections result: 1 array(1) { ["group1"]=> array(12) { ["total_space"]=> int(80632) ... { ["color"]=> string(6) "yellow" ["font"]=> string(4) "Aris" ["size"]=> string(2) "32" } delete file group1/M00/00/00/cteDO1cCjI-ATDFJAAAAD61kmgs438.bin return: 1 bool(true) tracker_close_all_connections result: 1
  • 1
  • 1

則表示整個擴充套件已經安裝完成並可以使用了。 


常見錯誤及解決辦法

瀏覽器端測試時出現

5.08 fastdfs_tracker_make_all_connections result: bool(false) bool(false)
  • 1
  • 1

重啟伺服器後未啟動storage和tracker服務,解決辦法:

root@test:~# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
root@test:~# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
  • 1
  • 2
  • 1
  • 2


安裝FastFDS時出現

../common/fdfs_global.c:20:20: fatal error: logger.h: No such file or directory
  • 1
  • 1

未安裝libfastcommon,解決辦法:

[email protected]:~# wget https://github.com/happyfish100/libfastcommon/archive/master.zip
[email protected]:~# unzip master.zip
[email protected]:~# cd libfastcommon-master
[email protected]:~/libfastcommon-master# ./make.sh
...
[email protected]:~/libfastcommon-master# ./make.sh install
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7


測試上傳時出現

ERROR - file: ini_file_reader.c, line: 394, include file "http.conf" not exists, line: "#include http.conf"
  • 1
  • 1

雖然引入了http.conf檔案,但在指定配置目錄下並未找到,解決辦法:

root@test:/etc/fdfs/# find ~/fastdfs-master/ -name http.conf
/root/fastdfs-master/conf/http.conf
root@test:/etc/fdfs/# cp /root/fastdfs-master/conf/http.conf /etc/fdfs/http.conf