爲fdfs添加nginx模塊

由於fdfs是應用的fdfs協議,當用web訪問時,需要提供http協議的接口,所以要在storage節點上編譯安裝nginx

git clone https://github.com/happyfish100/fastdfs-nginx-module.git
tar xf nginx-1.8.0.tar.gz
cd nginx-1.8.0
yum install -y pcre
yum install -y pcre-devel
./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx  --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --add-module=../fastdfs-nginx-module/src
make && make install
groupadd -r nginx
useradd -g nginx -r nginx

nginx編譯安裝完畢

設置fastdfs-nginx-module:

ln -sv /data/fdfs/storage/data/ /data/fdfs/storage/data/M00

靠譜模塊的配置文件:

 cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

編寫配置文件:

[root@node2 ~]# cat /etc/fdfs/mod_fastdfs.conf
connect_timeout=2
network_timeout=30
base_path=/data/fdfs/storage
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=192.168.145.93:22122        //此處爲tracker的地址和端口
storage_server_port=23000
group_name=group1
url_have_group_name = true                //默認爲false,要改爲true
store_path_count=1
store_path0=/data/fdfa/storage
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 1                        //啓用存儲節點,有幾個配置幾個
[group1]                                //節點相關信息配置
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/fdfs/storage

之前使用rpm包的方式安裝的fdfs,所以需要拷貝配置文件到/etc/fdfs

cp /root/fastdfs-5.0.11/conf/http.conf /etc/fdfs/
cp /root/fastdfs-5.0.11/conf/mime.types /etc/fdfs/

配置nginx.conf,添加location

 location ~ /group[0-9]+/M00/ {
    root /data/fdfs/storage/data/;
    ngx_fastdfs_module;
  }

重啓fdfs的存儲節點,並啓動nginx

service fdfs_storaged restart
/usr/local/ngins/sbin/nginx

上傳圖片並測試

fdfs_upload_file /etc/fdfs/storage.conf /tmp/a.jpg
存儲信息:group1/M00/00/00/wKiRXVi-rhOAWDyBAAJOvgO1aMA061.jpg

通過web訪問成功


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章