一、環境部署
1、準備工作
創建程序報下載目錄:/home/Package
mkdir -pv/home/Package
下載程序包:
cd /home/Package wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz wget http://zlib.net/zlib-1.2.8.tar.gz wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz wget http://iweb.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.15.tar.gz wget http://nginx.org/download/nginx-1.9.14.tar.gz
2、關聯包安裝
1)yum安裝系統lib包
yum -y installgcc automake autoconf libtool make yum -y installgcc gcc-c++ yum -y installgc-devel
2)安裝pcre
cd /home/Package/ tar fvxz pcre-8.37.tar.gz -C /usr/src/ cd /usr/src/pcre-8.37/ ./configure make && make install
3)安裝zlib
cd /home/Package/ tar fvxz zlib-1.2.8.tar.gz -C /usr/src/ cd /usr/src/zlib-1.2.8/ ./configure make && make install
4)安裝openssl
cd /home/Package/ tar fvxz openssl-1.0.1c.tar.gz -C /usr/src/ cd /usr/src/openssl-1.0.1c/ ./configure make && make instal
5)安裝fastdfs-nginx-module
cd /home/Package/ tar fvxz fastdfs-nginx-module_v1.15.tar.gz -C /usr/src/
6)創建軟鏈接
ln -s /usr/lib64/libfastcommon.so /usr/lib/ ln -s /usr/lib64/libfastcommon.so /usr/local/lib/ ln -s /usr/lib64/libfastcommon.so /usr/local/lib64/ ln -s /usr/lib64/libfdfsclient.so /usr/lib/ ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/ ln -s /usr/lib64/libfdfsclient.so /usr/local/lib64/
二、應用部署
1、Nginx
cd /home/Package/ tar fvxnginx-1.9.14.tar.gz -C /usr/src cd/usr/src/nginx-1.9.14 ./configure --prefix=/opt/nginx --user=www --group=www --sbin-path=/opt/nginx/sbin/nginx --pid-path=/opt/nginx/pid/nginx.pid --with-http_ssl_module --with-pcre=/usr/src/pcre-8.37 --with-zlib=/usr/src/zlib-1.2.8 --with-openssl=/usr/src/openssl-1.0.1i --add-module=/usr/src/fastdfs-nginx-module/src --with-http_image_filter_module --with-http_stub_status_module make && make install
2、FastDFS
tar fvx FastDFS_v4.06.tar -C /usr/src/ cd/usr/src/FastDFS/ ./make.sh ./make.shinstall
三、應用配置
1、配置nginx
ln -s/data/fdfs_store/data /usr/local/nginx/html/group1/M00
僅到需要進行動態縮略圖顯示的時候需要創建這個軟連接
vim /usr/local/nginx/conf/nginx.conf # 顯示動態縮略圖 location ~*/group1/M00/(\w+)/(\w+)/(.+).(png|jpg|gif)_(\d+)x(\d+)\.(png|jpg|gif) { root"/usr/local/nginx/html/"; ngx_fastdfs_module; set $iw"$5"; set $ih"$6"; image_filterresize $iw $ih; image_filter_buffer2M; try_files/group1/M00/$1/$2/$3.$4 /404.html; } # 顯示原圖 location /group1/M00 { root"/usr/local/nginx/html/"; ngx_fastdfs_module; }
2、配置FastDFS
mv /etc/fdfs/root/fdfs.bak ln -s/usr/local/FastDFS/conf /etc/fdfs vim /etc/fdfs/tracker.conf (只列出需要修改的項目) bind_addr=192.168.0.3 port=22122 base_path=/data/fastdfs vim /etc/fdfs/storage.conf (只列出需要修改的項目) bind_addr=192.168.0.3 client_bind=true port=23000 base_path=/data/fastdfs_storage store_path0=/data/fastdfs_store tracker_server=192.168.0.3:22122 http.server_port=80 vim /etc/fdfs/client.conf (只列出需要修改的項目) base_path=/data/fastdfs tracker_server=192.168.0.3:22122 http.tracker_server_port=80 vim /etc/fdfs/mod_fastdfs.conf (只列出需要修改的項目) base_path=/data/fastdfs tracker_server=192.168.0.3:22122 storage_server_port=23000 store_path0=/data/fastdfs_store log_filename=/var/log/fdfs/mod_fdfs.log
附錄一、問題及修復
1、[error] 30000#0: *1 open() "/usr/local/nginx/html/group1/M00/00/00/wKgAA1cLh12AI0kfAAAADzbdjmQ50_big.html"failed (2: No such file or directory), client: 192.168.0.181, server:localhost, request: "GET/group1/M00/00/00/wKgAA1cLh12AI0kfAAAADzbdjmQ50_big.html HTTP/1.1", host:"192.168.0.3"
原因:具體原因不明,可能是在做alias匹配的時候路徑出現的問題
修復:修改nginx.conf中的location配置爲:
location/group1/M00/ {
alias /home/FastDFS/data;
ngx_fastdfs_module;
}
2、ERROR - file: ../common/fdfs_global.c, line:52, the format of filename "group1/M00/00/00/wKgAA1cLh12AI0kfAAAADzbdjmQ50_big.html"is invalid
原因:nginx的fdfs的MOD裏面默認沒有開啓url_have_group_name
修復:開啓mod_fastdfs.conf文件中的url_have_group_name選項,後重啓nginx
3、/usr/src/fastdfs-nginx-module/src/common.c:21:25:致命錯誤:fdfs_define.h:沒有那個文件或目錄
#include "fdfs_define.h"
^
編譯中斷。
原因:編譯安裝nginx的fastdfs插件的頭文件沒有找到,由於編譯nginx時候系統會到/usr/local/include,而編譯安裝fastdfs-nginx-module時則默認保存在了/usr/include目錄。
修復:ln -s /usr/include/fast* /usr/local/include/
4、nginx啓動後error.log日誌報錯
ERROR - file:../storage/trunk_mgr/trunk_shared.c, line: 177, "No such file ordirectory" can't be accessed, error info: /data/fastdfs
ERROR - file:../storage/trunk_mgr/trunk_shared.c, line: 177, "No such file ordirectory" can't be accessed, error info: /data/fastdfs
ERROR - file:../storage/trunk_mgr/trunk_shared.c, line: 177, "No such file ordirectory" can't be accessed, error info: /data/fastdfs
ERROR - file:../storage/trunk_mgr/trunk_shared.c, line: 177, "No such file ordirectory" can't be accessed, error info: /data/fastdfs
原因:nginx的fdfs插件沒有在/etc/fdfs目錄中找到http.conf和mime.types。
修復:複製或者創建對應文件的軟連接
cp/usr/local/FastDFS/conf/http.conf /etc/fdfs/
cp/usr/local/FastDFS/conf/mime.types /etc/fdfs/
5、頁面訪問動態縮略圖返回415
原因:首先需要排除文件類型的問題,image_filter只支持jpg、git和png三種格式的圖片文件,調用其他格式的圖片文件會返回415。其次要確認設置的image_filter緩存是否小於上傳的圖片大小,如果小於同樣會報415錯誤。如果排除以上兩種可能性,那麼出現的問題應該是沒有在Nginx頁面的DocumentRoot目錄創建FastDFS數據存儲的軟連接。
修復:執行下列命令創建軟連接:
# mkdir -pv/usr/local/nginx/html/group1
# ln -s /data/fastdfs_store/data/usr/local/nginx/html/group1/M00