zoukankan      html  css  js  c++  java
  • fastdfs-nginx-module安装和配置

    fastdfs-nginx-module安装和配置

    为什么要在fastdfs的storage端,安装fastdfs-nginx-module?

    答案:https://www.cnblogs.com/littleatp/p/4361318.html

    答案摘要:在每一台storage服务器主机上部署Nginx及FastDFS扩展模块,由Nginx模块对storage存储的文件提供http下载服务, 仅当当前storage节点找不到文件时会向源storage主机发起redirect或proxy动作。

    个人理解:当一个文件A被上传到group1里的节点机器M后,group1里有节点机器M和节点机器N,节点N会从节点M下载文件A到自己节点下。如果又来了一个访问文件A的请求,并且tracker把这个请求让节点N来处理,这时节点N还没有从节点M下载到文件A,这样就无法处理,会出错误。

    插件fastdfs-nginx-module就是为了解决这个错误。怎么解决呢?就是把请求重定向到节点M上,也就是提供重定向的功能。

    前提是已经安装好了nginx和fastdfs了

    STEP1

    下载包(https://github.com/happyfish100/fastdfs-nginx-module ),并解压

    STEP2:去nginx源码的解压目录,运行下面的命令

    ./configure --add-module=/home/ys2/fastdfs/fastdfs-nginx-module-1.20/src
    

    如果执行结果里有下面的语句,则说明configure成功

    adding module in /home/ys2/fastdfs/fastdfs-nginx-module-1.20/src
     + ngx_http_fastdfs_module was configured
    

    STEP3:make

    发现出下面的错误:

    /usr/include/fastdfs/fdfs_define.h:15:10: fatal error: common_define.h: No such file or directory
     #include "common_define.h"
    

    解决办法:修改objs/Makefile文件,在ALL_INCS的最后面添加【-I /usr/include/fastcommon】,注意在原来的最后一行的后面加上【】。

    因为上面的错误原因是找不到common_define.h文件,所以通过添加-I,就可以找到这个文件了。如果不知道common_define.h在哪个目录,可以用【find /usr -name common_define.h】找到它所在的目录。

    ALL_INCS = -I src/core 
            -I src/event 
            -I src/event/modules 
            -I src/os/unix 
            -I objs 
            -I src/http 
            -I src/http/modules 
            -I /usr/local/include 
            -I /usr/include/fastcommon
    
    

    然后再执行make,一般就会成功了,如果还提示找不到某个.h文件,解决办法同上。

    STEP4:sudo make install

    在目录【/usr/local/nginx/sbin/】下,如果生产了nginx,并把原来的nginx重命名为nginx.old了,则说明安装成功了。

    -rwxr-xr-x  1 root root 4499888 9月   2 20:41 nginx*
    -rwxr-xr-x  1 root root 4375032 8月  30 10:56 nginx.old*
    

    分割线 到此说明安装已经OK了,下面是配置

    STEP5:启动nginx

    sudo nginx
    

    然后用【ps aux | grep nginx】,确认nginx进程是否成功启动

    root      9126  0.0  0.0  32980   436 ?        Ss   20:52   0:00 nginx: master process nginx
    

    发现结果如上,发现只有master进程,而没有worker进程,说明启动出了问题。

    解决办法:去看nginx的log文件【/usr/local/nginx/logs/error.log】,log内容如下

    2019/09/02 20:52:26 [notice] 8956#0: signal process started
    ngx_http_fastdfs_process_init pid=9127
    [2019-09-02 20:52:41] ERROR - file: shared_func.c, line: 968, file /etc/fdfs/mod_fastdfs.conf not exist
    [2019-09-02 20:52:41] ERROR - file: /home/ys2/fastdfs/fastdfs-nginx-module-1.20/src/common.c, line: 163, load con
    f file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2
    2019/09/02 20:52:41 [alert] 9126#0: worker process 9127 exited with fatal code 2 and cannot be respawned
    

    发现没有找到/etc/fdfs/mod_fastdfs.conf 文件。mod_fastdfs.conf 文件在解压后的src文件夹里,所以拷贝到/etc/fdfs目录下。

    STEP6:编辑/etc/fdfs/mod_fastdfs.conf 文件。发现此文件和storage.conf文件十分类似。所以照着storage.conf文件修改此文件。

    • 修改base_path=,让值和storage.conf一样。

    • 修改tracker_server=,让值和storage.conf一样。

    • 修改storage_server_port=,让值和storage.conf里的port一样。

    • 修改group_name=,让值和storage.conf一样。

    • 修改url_have_group_name ,让值为true。目的是在浏览器的URL里,显示group_name的值,也就是能看到访问的storage的哪个group。

    • 修改store_path_count=,让值和storage.conf一样。

    • 修改store_path0=,让值和storage.conf一样。

    • 修改group_count =,fastdfs文件系统里有几个组就写几,只有一个组就写1.

    • 如果group_count =1,则必须设置[group1],如果group_count =2,则必须设置[group1]和[group2],以此类推。

      然后,再把[group1]下的所以设置,再写一遍。

    把上面都修改好后,再次启动nginx,发现还是没有worker进程,再去看log内容,发现log内容和上一次不一样了,就说明上面的问题已经修改好了,又有别的问题了,已经在向成功迈进了。

    [2019-09-02 23:37:19] ERROR - file: ini_file_reader.c, line: 824, include file "http.conf" not exists, line: "#include http.conf"
    [2019-09-02 23:37:19] ERROR - file: /home/ys2/fastdfs/fastdfs-nginx-module-1.20/src/common.c, line: 163, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2
    2019/09/02 23:37:19 [alert] 9383#0: worker process 9384 exited with fatal code 2 and cannot be respawned
    

    说明没找到http.conf文件,

    解决办法:拷贝fastdfs源码安装包里的http.conf文件(在conf文件夹里),到/etc/fdfs/文件夹里。

    修改好后,再次启动nginx,发现还是没有worker进程,再去看log内容,发现log内容和上一次不一样了,就说明上面的问题已经修改好了,又有别的问题了,已经在向成功迈进了。

    2019/09/02 23:53:59 [notice] 9532#0: signal process started
    ngx_http_fastdfs_process_exit pid=9497
    ngx_http_fastdfs_process_init pid=9536
    [2019-09-02 23:54:05] ERROR - file: shared_func.c, line: 968, file /etc/fdfs/mime.types not exist
    2019/09/02 23:54:05 [alert] 9535#0: worker process 9536 exited with fatal code 2 and cannot be respawned
    

    说明没找到/etc/fdfs/mime.types文件

    解决办法:拷贝nginx源码安装包里的mime.types文件(在conf文件夹里),到/etc/fdfs/文件夹里。

    修改好后,再次启动nginx,发现有worker进程了,说明nginx启动成功了。

    STEP7:修改nginx.conf文件,添加下面

    location /group1/M00 {
        root   /home/ys2/fastdfs/data;
        ngx_fastdfs_module;
    }
    

    最后,在浏览器里直接访问storage节点下的某个文件,比如下面,如果能成功显示在浏览器中,则说明配置成功了。

    http://10.210.65.129/group1/M00/00/00/CtJBgV1s1m2AatCZAAAADCHxdNo922.txt
    

    c/c++ 学习互助QQ群:877684253

    本人微信:xiaoshitou5854

  • 相关阅读:
    ubuntu12.04 死机 卡屏 画面冻结解决方案
    Install Firefox 20 in Ubuntu 13.04, Ubuntu 12.10, Ubuntu 12.04, Linux Mint 14 and Linux Mint 13 by PPA
    ListView1.SelectedItems.Clear()
    android studio 下载地址
    jquery.slider.js jquery幻灯片测试
    jquery.hovermenu.js
    jquery.tab.js选项卡效果
    适配 placeholder,jquery版
    jquery.autoscroll.js jquery自动滚动效果
    将 Google Earth 地图集成到自己的窗体上的 简单控件
  • 原文地址:https://www.cnblogs.com/xiaoshiwang/p/11453625.html
Copyright © 2011-2022 走看看