FastDFS 安裝筆記


相關文章地址:

FastDFS的配置、部署與API使用解讀:http://blog.csdn.net/poechant/article/details/6977407

http://www.open-open.com/lib/view/open1435468300700.html

1,關於FastDFS

摘自:http://www.oschina.net/p/fastdfs 
FastDFS是一個開源的分布式文件系統,她對文件進行管理,功能包括:文件存儲、文件同步、文件訪問(文件上傳、文件下載)等,解決了大容量存儲和負載均衡的問題。特別適合以文件為載體的在線服務,如相冊網站、視頻網站等等。

FastDFS服務端有兩個角色:跟蹤器(tracker)和存儲節點(storage)。跟蹤器主要做調度工作,在訪問上起負載均衡的作用。

存儲節點存儲文件,完成文件管理的所有功能:存儲、同步和提供存取接口,FastDFS同時對文件的meta data進行管理。所謂文件的meta data就是文件的相關屬性,以鍵值對(key value pair)方式表示,如:width=1024,其中的key為width,value為1024。文件meta data是文件屬性列表,可以包含多個鍵值對。

GitHub:https://github.com/happyfish100/fastdfs 
一個寫的不錯的博客:http://tech.uc.cn/?p=221

2,安裝FastDFS

參考文檔: 
https://github.com/happyfish100/fastdfs/blob/master/INSTALL

2.1,安裝編譯工具

yum -y groupinstall 'Development Tools' yum -y install wget 
  • 1
  • 2

2.2,安裝libfastcommon類庫

必須先按照這個,否則報錯:

cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ../common/fdfs_global.o ../common/fdfs_global.c -I../common -I/usr/include/fastcommon ../common/fdfs_global.c:20:20: fatal error: logger.h: No such file or directory #include "logger.h" ^ compilation terminated. ........
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

直接下載安裝即可:

wget https://github.com/happyfish100/libfastcommon/archive/master.zip unzip master.zip cd libfastcommon-master ./make.sh ./make.sh install
  • 1
  • 2
  • 3
  • 4
  • 5

2.3,安裝FastDFS

wget  https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz tar -zxvf V5.05.tar.gz cd fastdfs-5.05/ ./make.sh ./make.sh install 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

2.4,啟動FastDFS

安裝之后配置文件在目錄/etc/fdfs。

mv storage.conf.sample storage.conf mv tracker.conf.sample tracker.conf
  • 1
  • 2

首先修改配置文件:  /etc/fdfs/tracker.conf,修改路徑到/data/fdfs目錄。

# the base path to store data and log files base_path=/data/fdfs
  • 1
  • 2

啟動:  /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start

修改配置文件:  /etc/fdfs/storage.conf,修改路徑到/data/fdfs目錄,同時配置tracker_server地址。

# the base path to store data and log files base_path=/data/fdfs # 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/fdfs #store_path1=/home/yuqing/fastdfs2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

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

啟動的時候,看日志沒有錯誤就說明啟動成功。  查看fdfs進程:

#ps -ef | grep fdfs root 19880 1 0 21:42 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start root 20050 1 0 22:08 ? 00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start root 20060 19915 0 22:08 pts/1 00:00:00 grep --color=auto fdfs
  • 1
  • 2
  • 3
  • 4

2.5 安裝nginx + lua + fastdfs module  下載fastdfs-nginx-module模塊  https://github.com/happyfish100/fastdfs-nginx-module  下載openresty nginx +lua包

wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip unzip fastdfs-nginx-module-master.zip wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz tar -zxvf ngx_openresty-1.7.10.1.tar.gz
  • 1
  • 2
  • 3
  • 4

編譯安裝:這里注意下,需要增加參數。  一個是stub_status統計模塊,一個是realip模塊。  參考地址:  http://blog.danielss.com/?p=80  http://wiki.nginx.org/HttpRealipModuleChs

yum -y install pcre-devel openssl openssl-devel cd ngx_openresty-1.7.10.1 ./configure --with-luajit --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=/root/fastdfs-nginx-module-master/src gmake gmake install
  • 1
  • 2
  • 3
  • 4
  • 5

nginx +lua安裝路徑:

  nginx path prefix: "/usr/local/openresty/nginx" nginx binary file: "/usr/local/openresty/nginx/sbin/nginx" nginx configuration prefix: "/usr/local/openresty/nginx/conf" nginx configuration file: "/usr/local/openresty/nginx/conf/nginx.conf" nginx pid file: "/usr/local/openresty/nginx/logs/nginx.pid" nginx error log file: "/usr/local/openresty/nginx/logs/error.log" nginx http access log file: "/usr/local/openresty/nginx/logs/access.log"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

啟動,重啟nginx

#啟動 /usr/local/openresty/nginx/sbin/nginx #重啟 /usr/local/openresty/nginx/sbin/nginx -s restart
  • 1
  • 2
  • 3
  • 4

3,測試FastDFS

配置服務:

cd /etc/fdfs
mv client.conf.sample client.conf
  • 1
  • 2

修改配置:

# the base path to store log files base_path=/data/fdfs # 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

配置nginx:

cp /root/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/ mkdir /data/ngx
  • 1
  • 2

修改mod_fastdfs.conf配置文件:修改tracker端口,否則nginx啟動不了。路徑也必須修改,否則找不到文件。

# the base path to store log files base_path=/data/ngx # FastDFS tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address # valid only when load_fdfs_parameters_from_tracker is true 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 # must same as storage.conf store_path0=/data/fdfs
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

拷貝配置文件,否則nginx啟動不了,報錯:

[2015-04-28 11:30:14] ERROR - file: ini_file_reader.c, line: 315, include file "http.conf" not exists, line: "#include http.conf" [2015-04-28 11:30:14] ERROR - file: /root/fastdfs-nginx-module-master/src/common.c, line: 155, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2 2015/04/28 11:30:14 [alert] 19969#0: worker process 2753 exited with fatal code 2 and cannot be respawned 
  • 1
  • 2
  • 3
  • 4

解決辦法:

cp /root/fastdfs-master/conf/http.conf /root/fastdfs-master/conf/mime.types /etc/fdfs
  • 1

nginx配置修改vi /usr/local/openresty/nginx/conf/nginx.conf

    server {
        listen       80; server_name localhost; charset utf8; location /M00 { alias /data/fdfs/data; ngx_fastdfs_module; } ......
  • 1
  • 2
  • 3
  • 4
  • 5
  •  

創建連接

ln -s /data/fdfs/data /data/fdfs/data/M00
  • 1

重啟nginx。  測試命令:

echo "test fastdfs" > test.html /usr/bin/fdfs_test /etc/fdfs/client.conf upload test.html
  • 1
  • 2

上傳成功,執行結果:


This is FastDFS client test program v5.05 Copyright (C) 2008, Happy Fish / YuQing FastDFS may be copied only under the terms of the GNU General Public License V3, which may be found in the FastDFS source kit. Please visit the FastDFS Home Page http://www.csource.org/ for more detail. [2015-04-25 18:06:09] DEBUG - base_path=/data/fdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0 tracker_query_storage_store_list_without_group: server 1. group_name=, ip_addr=192.168.1.36, port=23000 group_name=group1, ip_addr=192.168.1.36, port=23000 storage_upload_by_filename group_name=group1, remote_filename=M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01.html source ip address: 192.168.1.36 file timestamp=2015-04-25 18:06:09 file size=13 file crc32=3418468952 example file url: http://192.168.1.36/group1/M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01.html storage_upload_slave_by_filename group_name=group1, remote_filename=M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01_big.html source ip address: 192.168.1.36 file timestamp=2015-04-25 18:06:09 file size=13 file crc32=3418468952 example file url: http://192.168.1.36/group1/M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01_big.html
  •  

測試訪問:

curl http://192.168.1.36/M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01_big.html
  • 1

如果返回“test fastdfs”說明配置成功。上面的每一步修改都要正確才可以。

查看nginx錯誤日志:  tail -f /usr/local/openresty/nginx/logs/error.log

4,總結

FastDFS非常好的分布式文件系統。配置簡單,可以多機器部署,同時官方給了一個Nginx模塊,可以直接用nginx訪問,非常方便。這樣減少了中間的tomcat層,效率高。  接下來繼續研究lua的圖片壓縮。直接在nginx層進行圖片壓縮。效率更高,同時圖片讀取FastDFS的文件。


免責聲明!

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



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