1、下载fastdfs-nginx-module并解压缩
# cd /usr/local
# wget https://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
2、编辑config文件
# cd fastdfs-nginx-module/src/
# vi config
编辑config文件,执行如下命令进行批量替换并保存退出
:%s+/usr/local/+/usr/+g
(按回车键进行替换)
3、拷贝fastdfs-nginx-module模块中配置文件到/etc/fdfs目录中并编辑
# cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
# vi /etc/fdfs/mod_fastdfs.conf
修改内容如下:
connect_timeout=10(默认2)
base_path=/data/fast_data/(默认为/tmp,修改为你的fastdfs存储地址)
tracker_server=192.168.121.110:22122(默认为tracker:22122,修改为你自己的tracker地址)
storage_server_port=23000(默认配置为23000 修改为跟你stroage.conf中一致)
group_name=group1(默认配置为group1,修改为跟你storage.conf中一致)
url_have_group_name = true(默认为false,修改为true)
store_path0=/data/fast_data/(默认为/home/yuqing/fastdfs)
group_count = 0 (默认,如有多个group则填对应数字)
4、安装nginx依赖库
# yum install -y pcre-devel zlib-devel
5、安装nginx
# cd 到你安装的nginx根目录
# ./configure --prefix=/usr/local/nginx/ --add-module=../fastdfs-nginx-module/src/
# make && make install
6、拷贝FastDFS中的部分配置文件到/etc/fdfs目录中
# cp /usr/local/FastDFS/conf/http.conf /etc/fdfs/
# cp /usr/local/FastDFS/conf/mime.types /etc/fdfs/
7、配置nginx
# vi /usr/local/nginx/conf/nginx.conf
user root;
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]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
说明:
(1)"user root"是解决下载操作时报404的问题
(2)8888端口号与/etc/fdfs/storage.conf中的http.server_port=8888相对应(很多地方都这么说,但是好像经过测试发现不一致也可以访问)
(3)storage对应有多个group的情况下,访问路径带group名称,例如:/group1/M00/00/00/**,对应nginx配置:
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
8、拷贝nginx服务到/etc/init.d/目录下并启动
# cp /application/nginx/sbin/nginx /etc/init.d/
# /etc/init.d/nginx
# ss -lntup | grep 8888
tcp LISTEN 0 128 *:8888 *:* users:(("nginx",7308,6),("nginx",7309,6))
9、通过浏览器访问之前已经上传的文件
在浏览器中输入
http://xxx.xxx.xxx.xxx:8888/group1/M00/00/00/wKh5blkcHpiAAEBkAAC7L7_PW5E715.jpg