FastDFS无法HTTP访问 (浏览器访问)


  • 现象:  

     FastDFS无法HTTP访问。

  • 前置情况及环境说明: 

       服务器上安装了fastdfs。

       服务器版本 Centos7

  • 解决方案:

       安装nginx   及 fastdfs-nginx-module-master

       fastdfs-nginx-module-master是 FastDFS提供的一个Nginx扩展模块,利用该模块,我们可以通过Nginx访问已经上传到FastDFS上的文件

  • 解决步骤:
    • 1. 安装nginx  添加fastDFS模块       
        这 个模块必须在Nginx的安装的过程中才能添加

          https://blog.csdn.net/qq_37345604/article/details/90034424

0.前置环境安装:

   1. nginx是c编写的,对于解压的源码进行编译,所以首先设置编译环境: gcc
      执行: (-y: 不询问)
              yum -y install gcc
              yum -y install gcc-c++
   2. Perl库,包括 perl 兼容的正则表达式库
           yum install -y pcre pcre-devel
   3. zlib库提供了很多种压缩和解压缩的方式
       yum install -y zlib zlib-devel
   4. OpenSSL 是一个强大的安全套接字层密码库
        yum install -y openssl openssl-devel

1. 安装nginx: 

nginx-1.18.0.tar.gz

wget http://nginx.org/download/nginx-1.18.0.tar.gz
路径同fdfs :/share/data

2. 安装

fastdfs-nginx-module_v1.16.tar.gz

wget https://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz

3.解压上面两个 压缩包

tar -zxvf  nginx-1.18.0.tar.gz

tar -zxvf  fastdfs-nginx-module_v1.16.tar.gz

-----------------------------------------------------------------------------------------------------------------------------------------------------------

如有报错:

[root@ecs data]# tar -zxvf  fastdfs-nginx-module_v1.16.tar.gz 
tar (child):  :无法 open: 没有那个文件或目录
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
====> 解决办法:

写绝对路径: 

tar -zxvf   /share/data/nginx-1.18.0.tar.gz

--------------------------------------------------------------------------------------------------------------------------------------------------------

4 配置

4.1.配置

  切换至解压后的Nginx主目录,执行配置操作

cd nginx-1.18.0

指定路径不要同nginx-1.18.0

./configure --prefix=/share/data/nginx --add-module=/share/data/fastdfs-nginx-module/src

或者

./configure  --add-module=/share/data/fastdfs-nginx-module/src --prefix=/share/data/nginx

• prefix是指定nginx安装路径

• add-module指定fastDFS的nginx模块的源代码路径

4.2 编译

make

-----------------------------------------------------------------------------------------------------------------------------------------------

make过程中 如果遇到一个致命错误,致命错误:fdfs_define.h:没有那个文件或目录
 #include "fdfs_define.h"
参考解决方案:

https://blog.csdn.net/zzzgd_666/article/details/81911892

ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

==>总结一下 就是删掉三处local 

重新./configure --prefix=/share/data/nginx-1.18.0 --add-module=/share/data/fastdfs-nginx-module/src

再make  成功!

--------------------------------------------------------------------------------------------------------------------------------------------------

4.3 安装

make install

https://blog.51cto.com/gouyc/1656454

 

tar -zxvf libfastcommon-1.0.36.tar.gz
./make.sh
./make.sh install

tar -zxvf fastdfs-5.11.tar.gz
./make.sh
./make.sh install


cp ./conf/http.conf /etc/fdfs/
cp ./conf/mime.types /etc/fdfs/
cp ./conf/anti-steal.jpg /etc/fdfs/
cp ./conf/storage_ids.conf /etc/fdfs/


/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

killall fdfs_trackerd
killall fdfs_storaged


fdfs_test /etc/fdfs/client.conf upload /root/fastdfs/1.jpg

tar -zxvf nginx-1.15.1.tar.gz
./configure --prefix=/usr/local/nginx/nginx-1.15.1 --add-module=/root/fastdfs/fastdfs-nginx-module-1.20/src/
make
make install


 /usr/local/nginx/nginx-1.15.1/sbin/nginx -c /usr/local/nginx/nginx-1.15.1/conf/nginx.conf


 分析nginx的error日志
/usr/local/nginx/nginx-1.15.1/logs/error.log

1.访问nginx首页失败,nginx启动失败:file: /root/fastdfs/fastdfs-nginx-module-1.20/src/common.c, line: 155, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2
解决办法:cp /root/fastdfs/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/

2.访问nginx首页失败,nginx启动失败:file: client_func.c, line: 112, conf file "/etc/fdfs/mod_fastdfs.conf", host "tracker" is invalid
解决办法:vim /etc/fdfs/mod_fastdfs.conf -> tracker_server=tracker:22122 (修改ip和port)

中间步骤:修改/usr/local/nginx/nginx-1.15.1/conf/nginx.conf
server {
    listen       8998;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }

    location ~ /group1/M00/ {
        root /root/fastdfs/storage/data;
        ngx_fastdfs_module;
    }
}

fdfs_test /etc/fdfs/client.conf upload /root/fastdfs/1.jpg

http://ip:8998/group1/M00/00/55/rBABIGAJm1OADhshAAW4YJAs8jI993.jpg

注意
1.跟tracker端口配置一样
listen       8998;
2.跟storage路径配置一样
root /root/fastdfs/storage/data; (注意加上data)


3.nginx启动成功,地址访问404:file: ../common/fdfs_global.c, line: 52, the format of filename "group1/M00/00/55/rBABIGAJm1OADhshAAW4YJAs8jI993.jpg" is invalid
解决办法:vim /etc/fdfs/mod_fastdfs.conf -> url_have_group_name = true   (false改成true)

4.nginx启动成功,地址访问400:file: /share/data/fastdfs-nginx-module/src/common.c, line: 870, file: /home/yuqing/fastdfs/data/00/55/rBABIGAJnt-AV0DeAAW4YJAs8jI525.jpg not exist
解决办法:vim /etc/fdfs/mod_fastdfs.conf -> store_path0=/root/fastdfs/storage   (跟storage路径配置一样,注意不要加上data)

重启fdfs_trackerd和fdfs_storaged两个服务
操作命令上面已有记录:先关闭再启动
图片地址就可以访问了







 

 

 

 

 

 

 

 


 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值