原文地址:Nginx 整合 FastDFS 实现文件服务器

博客地址:http://www.extlight.com

一、前言

本篇衔接《FastDFS 环境搭建》内容进行讲解,上篇文章我们实现了图片上传的功能,但是无法通过 http 进行访问,本篇将解决该问题。

建议读者先浏览《FastDFS 环境搭建》再继续浏览本篇文章。

二、安装

2.1 下载 fastdfs-nginx-module

Nginx 整合 FastDFS 需要依赖 fastdfs-nginx-module 模块,我们需要将其下载下来。

git clone https://github.com/happyfish100/fastdfs-nginx-module.git

查看下载文件:

[root@fastdfs ~]# pwd
/root
[root@fastdfs ~]# ll
total 1048
drwxr-xr-x. 11 root root 270 Oct 16 22:19 fastdfs
drwxr-xr-x. 4 root root 59 Oct 17 02:56 fastdfs-nginx-module
drwxr-xr-x. 6 root root 147 Oct 16 22:22 libfastcommon
-rw-r--r--. 1 root root 49608 Oct 17 01:51 test.jpg

2.2 安装 nginx/fastdfs-nginx-module

笔者通过 yum 方式安装 nginx,具体操作可以访问 《Nginx 快速入门》

现在出现一个尴尬的问题:nginx 安装第三方模块需要通过 configure 命令,因此我们还得下载 nginx 源码对第三方模块进行编译安装。

由于笔者已经提前安装 nginx ,键入命令:

[root@fastdfs ~]# nginx -V
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --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.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

可以看到 nginx 的版本以及安装好的 nginx 模块,我们需要下载 nginx/1.14.0 的源码:

wget http://nginx.org/download/nginx-1.14.0.tar.gz

tar -zxvf nginx-1.14.0.tar.gz

cd nginx-1.14.0

进入到 nginx-1.14.0 目录后,我们就看到 configure 命令了。

通过源码编译 nginx 模块需要安装依赖包(如果之前通过源码方式安装 nginx 可以忽略该步骤):

yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel

安装完成后,我们现在需要拼接执行命令。

./configure 已安装的模块 --add-module=/root/fastdfs-nginx-module/src,最终的结果如下:

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --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.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/root/fastdfs-nginx-module/src

执行上边的命令,编译好之后再执行 make 即可。注意,不需要 make install

最后替换 nginx 命令:

cp /usr/sbin/nginx /usr/sbin/nginx.bak
cp ./objs/nginx /usr/sbin/

三、配置

3.1 修改 fastdfs-nginx-module 配置文件

复制 mod_fastdfs 配置文件:

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

修改 vim /etc/fdfs/mod_fastdfs.conf:

base_path=/data/fastdfs/tmp

tracker_server=192.168.10.110:22122

group_name=light

url_have_group_name = true

store_path0=/data/fastdfs/storage

注意:请确保 /etc/fdfs 有如下 .conf 文件:

[root@fastdfs fdfs]# pwd
/etc/fdfs
[root@fastdfs fdfs]# ll
total 84
-rw-r--r--. 1 root root 1462 Oct 17 01:50 client.conf
-rw-r--r--. 1 root root 1461 Oct 16 22:26 client.conf.sample
-rw-r--r--. 1 root root 955 Oct 17 04:34 http.conf
-rw-r--r--. 1 root root 31172 Oct 17 04:35 mime.types
-rw-r--r--. 1 root root 3744 Oct 17 04:22 mod_fastdfs.conf
-rw-r--r--. 1 root root 7976 Oct 17 01:57 storage.conf
-rw-r--r--. 1 root root 7978 Oct 16 22:26 storage.conf.sample
-rw-r--r--. 1 root root 105 Oct 16 22:26 storage_ids.conf.sample
-rw-r--r--. 1 root root 7442 Oct 16 23:34 tracker.conf
-rw-r--r--. 1 root root 7441 Oct 16 22:26 tracker.conf.sample

缺少配置文件,可能会造成后边启动 nginx 失败,如果根据笔者介绍的步骤,应该不会出现缺漏文件的情况。

3.2 修改 nginx 配置文件

vim /etc/nginx/conf.d/default.conf ,新增 location 配置:

server {

    server_name  192.168.10.110;

    location /light/M00 {
root /data/fastdfs/storage/data;
ngx_fastdfs_module;
} ...
}

保存文件,重启 nginx :

nginx -s reload

四、测试

打开浏览器访问 http://192.168.10.110/light/M00/00/00/wKgKblvG1hmAafZBAADByGKuVUM369.jpg (上篇文章中笔者上传图片后 fdfs 返回的 url 地址),显示效果:

图片正常访问,大功告成。

如果访问不通,检查是否是防火墙问题,或者查看 nginx 日志。

Nginx 整合 FastDFS 实现文件服务器的更多相关文章

  1. Spring Boot 整合 FastDFS 客户端

    原文地址:Spring Boot 整合 FastDFS 客户端 博客地址:http://www.extlight.com 一.前言 前两篇介绍整体上介绍了通过 Nginx 和 FastDFS 的整合来 ...

  2. 百度富文本编辑器整合fastdfs文件服务器上传

    技术:springboot+maven+ueditor   概述 百度富文本整合fastdfs文件服务器上传 详细 代码下载:http://www.demodashi.com/demo/15008.h ...

  3. FastDFS单节点安装 & FastDFS+Nginx整合

    安装环境    FastDFS_v5.05.tar.gz(http://sourceforge.net/projects/fastdfs/files/)    fastdfs-nginx-module ...

  4. FastDFS和apache/nginx整合

    因为FastDFS默认自带的http服务器性能不好, 所以一般建议用外置的apache或者nginx 来解决http下载,以应付大并发的情况 注意nginx扩展模块只支持GET和HEAD模式获取文件, ...

  5. 【转载】【JAVA秒会技术之图片上传】基于Nginx及FastDFS,完成图片的上传及展示

    基于Nginx及FastDFS,完成商品图片的上传及展示 一.传统图片存储及展示方式 存在问题: 1)大并发量上传访问图片时,需要对web应用做负载均衡,但是会存在图片共享问题 2)web应用服务器的 ...

  6. 使用nginx访问FastDFS

    文中所有~~~均为同一个自定义文件夹名字,一般使用项目名称 2.1.为什么需要用Nginx访问? FastDFS通过Tracker服务器,将文件放在Storage服务器存储,但是同组存储服务器之间需要 ...

  7. Nginx和FastDfs完整配置过程

    借鉴(https://blog.csdn.net/qq_34301871/article/details/80060235) 1.unknown directive "ngx_fastdfs ...

  8. 使用nginx访问FastDFS fastdfs nginx

    文中所有~~~均为同一个自定义文件夹名字,一般使用项目名称 2.1.为什么需要用Nginx访问? FastDFS通过Tracker服务器,将文件放在Storage服务器存储,但是同组存储服务器之间需要 ...

  9. nginx整合tomcat集群并做session共享----测试案例

    最近出于好奇心,研究了一下tomcat集群配置,并整合nginx,实现负载均衡,session共享,写篇记录,防止遗忘.---------菜鸡的自我修炼. 说明:博主采用一个web项目同时部署到两台t ...

随机推荐

  1. javascript数据结构——队列

    队列是一种先进先出的数据结.队列只能在队尾插入元素,在队首删除元素,这点和栈不一样.它用于存储顺序排列的数据.队列就像我们日常中的排队一样,排在最前面的第一个办理业务,新来的人只能在后面排队.队列这种 ...

  2. 工作中遇到的oracle分页查询问题及多表查询相关

    在工作中,有时,我们会用到oracle分页查询.这时,就需要先了解oracle的rownum.rowmun是oracle的伪列,只能用符号(<.<=.!=),而不能用这些符号(>,& ...

  3. Oracle 与Sql Server常用函数对比

    来自:http://topic.csdn.net/u/20080704/08/b2b8c42f-b0d6-4cda-98b1-6e4a279b4ff8.html 感谢楼主 函数 SQLServer和O ...

  4. linux驱动程序:控制发光二极管

      一个完整的Linux驱动包括内部处理和交互两部分.其中内部处理主要是指Linux驱动的装载.卸载.与设备文件的相关动作处理以及业务逻辑等.与硬件交互主要是指通过iowrite32.ioread32 ...

  5. DevExpress v18.1新版亮点——WinForms篇(二)

    用户界面套包DevExpress v18.1日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress WinForms v18.1 的新功能,快来下载试用新版本! ...

  6. tp 邮件发送

    1.需要phpmail邮件发送包, 2.邮件发送函数function sendMail($to, $title, $content){ require_once('./PHPMailer_v5.1/c ...

  7. TCP/IP网络知识点总结

    学完了计算机网络是时候整理一篇总结了,温故知新.注意:这篇博客很长长长(2.5万字+50图). TCP/IP网络知识点总结 一.总述 1.定义:计算机网络是一些互相连接的.自治的计算机的集合.因特网是 ...

  8. fluent nhibernate映射的数值类型问题

    fluent nhibernate中,数值类型设置不当,就可能会引发一些意想不到错误. 一.引发映射错误 比如,oracle数据库中,字段ID类型是number,结果用codesmith生成代码,实体 ...

  9. Vue实例的的data对象

    介绍 Vue的实例的数据对象data 我们已经用了很多了,数据绑定离不开data里面的数据.也是Vue的核心属性. 它是Vue绑定数据到HTML标签的数据源泉,另外Vue框架会自动监视data里面的数 ...

  10. Python高手之路 ------读书有感

    最近忙中偷闲把前些年买的<Python高手之路>翻了出来,大致看完了一遍,其中很多内容并不理解,究其原因应该是实践中的经验不足,而这对于现如今的我仍是难以克服的事情,对此也就只能说是看会了 ...