FastDFS之nginx插件

通过FastDFS的客户端API来进行文件的上传、下载、删除等操作。同时通过FastDFS的HTTP服务器来提供HTTP服务。但是FastDFS的HTTP服务较为简单,无法提供负载均衡等高性能的服务,所以FastDFS的开发者——淘宝的架构师余庆,为我们提供了Nginx上使用的FastDFS模块。
1.安装nginx
安装依赖:yum -y install  zlib pcre pcre-devel zlib-devel
下载配置fastdfs-nginx-module
https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip
unzip master.zip
mv fastdfs-nginx-module-master fastdfs-nginx-module
cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

vi /etc/fdfs/mod_fastdfs.conf
base_path=/home/fastdfs/nginx
tracker_server=192.168.18.178:22122
group_name=group1
store_path0=/home/fastdfs/storage0
log_filename=/home/fastdfs/nginx/nginx-fastdfs.log
创建目录软连接,将其链接到实际存放数据的目录,方便多目录的管理
cd /home/fastdfs/storage0
ln -s data/ M00
复制FastDFS的配置到/etc/fdfs
cd /usr/local/fastdfs/conf
cp http.conf mime.types /etc/fdfs/

配置安装nginx:
wget http://nginx.org/download/nginx-1.9.0.tar.gz
tar -zxvf nginx-1.9.0.tar.gz 
cd nginx-1.9.0
./configure --prefix=/usr/local/nginx --add-module=/root/fastdfs-nginx-module/src
cd /usr/local/nginx/conf
vi nginx.conf
user  root;

location /M00{
    root /home/fastdfs/storage0;
    ngx_fastdfs_module;
}

二、测试
上传一个图片:

fdfs_test /etc/fdfs/client.conf upload  /home/fastdfs/201504121227112783.jpg 

This is FastDFS client test program v5.06

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-05-26 02:44:38] DEBUG - base_path=/home/fastdfs/client, 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.18.178, port=23000

group_name=group1, ip_addr=192.168.18.178, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgSslVkQIaACGN9AAA7C3cSq_Y416.jpg
source ip address: 192.168.18.178
file timestamp=2015-05-26 02:44:38
file size=15115
file crc32=1997712374
example file url: http://192.168.18.178/group1/M00/00/00/wKgSslVkQIaACGN9AAA7C3cSq_Y416.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgSslVkQIaACGN9AAA7C3cSq_Y416_big.jpg
source ip address: 192.168.18.178
file timestamp=2015-05-26 02:44:38
file size=15115
file crc32=1997712374
example file url: http://192.168.18.178/group1/M00/00/00/wKgSslVkQIaACGN9AAA7C3cSq_Y416_big.jpg
访问nginx地址,显示正常。
http://192.168.18.178/M00/00/00/wKgSslVkQIaACGN9AAA7C3cSq_Y416_big.jpg

你可能感兴趣的:(分布式文件系统,fastDFS)