第一步:libfastcommon安裝
FastDFS_v5.05依賴libfastcommon,不再依賴libevent
unzip libfastcommon-master.zip -d /usr/localcd /usr/local/libfastcommon-master
./make.sh
./make.sh install
libfastcommon.so默認安裝到了/usr/lib64/libfastcommon.so,而FastDFS主程序設置的lib目錄是/usr/local/lib,所以設置軟連接
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
第二步:FastDFS安裝
1)tar -zxvf FastDFS_v5.05.tar.gz -C /usr/local
cd /usr/local/FastDFS
./make.sh
./make.sh install
cd /etc/fdfs
2) FastDFS安裝完畢後,修改tracker.conf、storage.conf、client.conf配置文件。將/etc/fdfs 下的3個配置文件的名字去掉sample。
在/usr/local 目錄下創建目錄:
mkdir /home/fastdfs/tracker
mkdir /home/fastdfs/storage
mkdir /home/fastdfs/data
mkdir /home/fastdfs/client
mkdir /home/fastdfs/mod
首先修改tracker.conf配置文件
base_path=/home/fastdfs/tracker #用於存放日誌。
其次修改storage.conff配置文件
base_path=/home/fastdfs/storage #用於存放日誌。
store_path0=/home/fastdfs/data #存放數據,若不設置默認爲前面那個。
tracker_server=192.168.0.230:22122 #指定tracker服務器地址。
最後修改client.conff配置文件
base_path=/home/fastdfs/client #用於存放日誌。
tracker_server=192.168.0.230:22122 #指定tracker服務器地址。
3) 啓動tracker、storage
fdfs_trackerd /etc/fdfs/tracker.conf
fdfs_storaged etc/fdfs/storage.conf
4) 檢查進程
ps -ef |grep fdfs
5) 上傳/刪除 測試
使用自帶的fdfs_test來測試,使用格式如下:
fdfs_test /etc/fdfs/client.conf upload /home/01.jpg
成功
group_name=group1, ip_addr=192.168.29.132, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580.jpg
...
example file url: http://192.168.29.132/group1/M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580_big.jpg
...
example file url: http://192.168.29.132/group1/M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580_big.jpg
使用fdfs_delete_file來刪除文件,格式如下:
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgdhFTV11uAXgKWAPk-Io7D4w8667.jpg
可以看到,上傳ok了,這裏會生成兩個文件,這是fastdfs的主/從文件特性,以後再介紹。example file url是不能在瀏覽器中直接打開的,除非配合nginx使用,這裏我不需要了。刪除文件需要完整的group_name和
第三步:在所有storage節點安裝fastdfs-nginx-module
fastdfs-nginx-module
作用說明
FastDFS 通過 Tracker 服務器,將文件放在 Storage 服務器存儲,但是同組存儲服務器之間需要進入 文件複製,有同步延遲的問題。假設 Tracker 服務器將文件上傳到了 ip01,上傳成功後文件 ID 已經返回給客戶端。此時 FastDFS 存儲集羣機制會將這個文件同步到同組存儲 ip02,在文件還 沒有複製完成的情況下,客戶端如果用這個文件 ID 在 ip02 上取文件,就會出現文件無法訪問的 錯誤。而 fastdfs-nginx-module 可以重定向文件連接到源服務器取文件,避免客戶端由於複製延遲導致的
文件無法訪問錯誤。(解壓後的 fastdfs-nginx-module 在 nginx 安裝時使用)
1)解壓 fastdfs-nginx-module_v1.16.tar.gz
2)修改 fastdfs-nginx-module 的 config 配置文件
cd fastdfs-nginx-module/src
vim config
將
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
修改爲:
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
3)複製 fastdfs-nginx-module
源碼中的配置文件到/etc/fdfs 目錄,並修改
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
4)修改/etc/fdfs/mod_fastdfs.conf文件
connect_timeout=10
base_path=/home/fastdfs/mod
tracker_server=192.168.0.230:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path0=/home/fastdfs/data
5)
複製 FastDFS 的部分配置文件到/etc/fdfs 目錄
cd /usr/local/src/FastDFS/conf
cp http.conf mime.types /etc/fdfs/
第四步:編譯安裝nginx
需要文件:1). openssl-1.0.2k 2). pcre-8.40 3). zlib-1.2.11
./configure --prefix=/usr/local/nginx-1.10.1 --add-module=/usr/local/src/fastdfs-nginx-module/src--with-zlib=/usr/local/zlib-1.2.8/ --with-pcre=/usr/local/pcre-8.40/ --with-openssl=/usr/local/openssl-1.0.2k/ --with-mail --with-mail_ssl_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_realip_module --with-http_ssl_module
第五步:配置nginx
user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8888;
server_name localhost;
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
A、8888 端口值是要與/etc/fdfs/storage.conf 中的 http.server_port=8888 相對應, 因爲 http.server_port 默認爲 8888,如果想改成 80,則要對應修改過來。
B、Storage 對應有多個 group 的情況下,訪問路徑帶 group 名,如/group1/M00/00/00/xxx, 對應的 Nginx 配置爲:
location ~/group([0-9])/M00 { ngx_fastdfs_module; }
C、如查下載時如發現老報 404,將 nginx.conf 第一行 user nobody 修改爲 user root 後重新啓動。
第六步:啓動nginx
在/fastdfs/storage 文件存儲目錄下創建軟連接,將其鏈接到實際存放數據的目錄
ln
-s /home/fastdfs/storage/data/
/home/fastdfs/storage/data/M00