• 图床项目之nginx-fastdfs和upload-module安装详细教程


    模块包的安装

    全部安装条件在确保之前的FastDFS 的tracker、storage和client可以正常使用。
    模块包源码包下载地址

    备份原有nginx

    为避免端口直接的冲突,建议备份原有的nginx服务。

    cd /usr/local
    sudo mv nginx bk-nginx-20221106
    
    • 1
    • 2

    下载fastdfs-nginx-module

    wget https://github.com/happyfish100/fastdfs-nginx-module/archive/refs/tags/V1.22.tar.gz
    tar -zxvf V1.22.tar.gz 
    cd fastdfs-nginx-module-1.22/
    
    • 1
    • 2
    • 3

    cd fastdfs-nginx-module-1.22/ 会发现里面有个INSTALL 和 src目录,这个不需要make而是需要重新编译一下storage的Nginx模块。

    查看fastdfs-nginx-module模块src决对路径(后面要用决对路径):

    # pwd
    /home/fly/fastdfs-nginx-module-1.22
    
    • 1
    • 2

    下载nginx-upload-module

    (1)下载原始的版本(原始版本有bug):

    wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz
    
    • 1

    (2)解压:

    tar -zxvf nginx_upload_module-2.2.0.tar.gz
    
    • 1

    (3)下载修改过的nginx upload模块,替换部分原始的文件:

    git clone https://github.com/winshining/nginx-upload-module.git
    
    
    • 1
    • 2

    (4)拷贝当前该目录的内容到nginx_upload_module-2.2.0:

    cd nginx-upload-module
    cp -arf * ../nginx_upload_module-2.2.0
    
    • 1
    • 2

    (5)获取到路径:

    cd ../nginx_upload_module-2.2.0
    pwd
    
    • 1
    • 2

    显示:

    /home/fly/nginx_upload_module-2.2.0
    
    • 1

    安装和编译Nginx 并添加FastDFS模块

    进入到nginx源码目录(笔者路径:/home/fly/nginx-1.16.1)配置添加模块:

    #进入到nginx源码目录,(笔者路径:/home/fly/nginx-1.16.1)
    cd nginx-1.16.1/
    # 配置添加模块:
    ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_v2_module --with-openssl=../openssl-1.1.1g --add-module=/home/fly/fastdfs-nginx-module-1.22/src --add-module=/home/fly/nginx_upload_module-2.2.0
    
    • 1
    • 2
    • 3
    • 4

    注意–add-module的路径,用自己的路径,最好是绝对路径,防止错误。
    其中/home/fly/fastdfs-nginx-module-1.22/src 是刚才下载的的fastdfs_nginx_module模块的绝对路径,就是在编译Nginx时候,连同这个模块一起编译。

    configure时, 出现以下信息表示添加成功:

    configuring additional modules
    adding module in /home/fly/fastdfs-nginx-module-1.22/src
     + ngx_http_fastdfs_module was configured
    adding module in /home/fly/nginx_upload_module-2.2.0
     + ngx_http_upload_module was configured
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    给 nginx 目录下的 objs/Makefile 文件中增加头文件目录

    (1)打开objs/Makefile 文件:

    vim objs/Makefile
    
    • 1

    (2)添加:

    ALL_INCS = -I src/core \
    	-I /usr/include/fastdfs \
    	-I /usr/include/fastcommon \
    	-I src/event \
    	-I src/event/modules \
    	-I src/os/unix \
    	-I ../openssl-1.1.1g/.openssl/include \
    	-I objs \
    	-I src/http \
    	-I src/http/modules \
    	-I src/http/v2 \
    	-I /usr/local/include
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    在这里插入图片描述
    特别需要注意加入两行后 -I 和 \ 的颜色要和原来一致,否则报错:

    Makefile:8: recipe for target 'build' failedmake: *** [build] Error 2
    
    • 1

    重新编译及安装nginx

    make
    sudo make install
    
    • 1
    • 2

    安装成功后:通过nginx -V 测试编译是否正常。

    sudo /usr/local/nginx/sbin/nginx -V
    
    • 1

    显示:

    nginx version: nginx/1.16.1
    built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12) 
    built with OpenSSL 1.1.1g  21 Apr 2020
    TLS SNI support enabled
    configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_v2_module --with-openssl=../openssl-1.1.1g --add-module=/home/fly/fastdfs-nginx-module-1.22/src --add-module=/home/fly/nginx_upload_module-2.2.0
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    fastdfs-nginx-module 的配置(注意细节)

    拷贝fastdfs-nginx-module配置文件

    (1)切换到fastdfs-nginx-module-1.22/src路径(笔者的路径是/home/fly/fastdfs-nginx-module-1.22/src):

    cd /home/fly/fastdfs-nginx-module-1.22/src
    # 查看文件
    ls
    
    • 1
    • 2
    • 3

    (2)将fastdfs-nginx-module-1.22/src/mod_fastdfs.conf 拷贝到/etc/fdfs/下:

    sudo cp mod_fastdfs.conf /etc/fdfs/
    
    • 1

    因为/etc/fdfs/是默认的加载路径。

    拷贝fastdfs/conf 配置文件

    (1)切换到fastdfs源码路径(笔者的路径是/home/fly/fastdfs):

    cd /home/fly/fastdfs
    
    • 1

    (2)拷贝相关文件conf/http.conf和conf/mime.types到/etc/fdfs/。

    sudo cp conf/http.conf /etc/fdfs/
    sudo cp conf/mime.types /etc/fdfs/
    
    • 1
    • 2

    修改配置文件

    创建目录(一定要记得):

    mkdir -p /home/fastdfs/mod_fastdfs
    
    • 1

    修改配置:

    vim /etc/fdfs/mod_fastdfs.conf
    
    • 1

    base_path =/home/fastdfs/mod_fastdfs :保存日志目录
    tracker_server =114.215.169.66:22122 :tracker服务器的IP地址以及端口号, 确保跟storage.conf一致即可。
    store_path0=/home/fastdfs/storage:确保路径正确并存在。

    base_path =/home/fastdfs/mod_fastdfs
    # Tracker 服务器IP和端口修改
    tracker_server=114.215.169.66:22122
    # url 中是否包含 group 名称,改为 true,包含 group
    url_have_group_name = true
    # store_path0的路径必须和storage.conf的配置一致
    store_path0=/home/fastdfs/storage
    # 其它的一般默认即可,例如
    group_name=group1
    storage_server_port=23000
    store_path_count=1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    主要修改base_path 、tracker_server、url_have_group_name、store_path0。

    配置nginx

    vim /usr/local/nginx/conf/nginx.conf
    
    • 1

    配置为支持 group0-group9,以及 M00-M99,以便于以后扩容。

    location ~/group([0-9])/M([0-9])([0-9]) {
    	ngx_fastdfs_module;
    }
    
    • 1
    • 2
    • 3

    具体位置:
    ngx_fastdfs_module

    重启nginx

    配置完fastdfs-nginx-module后需要重启nginx。

    # 停止:
    sudo /usr/local/nginx/sbin/nginx -s stop
    # 启动:
    sudo /usr/local/nginx/sbin/nginx
    
    • 1
    • 2
    • 3
    • 4

    如果出现如下错误。需要先停止nginx再启动nginx:

    nginx: [emerg] unknown directive "ngx_fastdfs_module" in
    /usr/local/nginx/conf/nginx.conf:92
    
    • 1
    • 2

    指定配置文件的方式启动:

    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    
    • 1

    查看nginx是否启动正常:

    ps -ef | grep nginx
    
    • 1

    成功则显示:

    root      53763      1  0 22:13 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
    nobody    53764  53763  0 22:13 ?        00:00:00 nginx: worker process
    
    
    • 1
    • 2
    • 3

    如果木有work进程说明启动是异常的,一般有以下原因:

    1. base_path对应的路径木有创建。
    2. tracker_server 配置错误。
    3. store_path0 配置错误。

    测试环境

    服务器中测试上传。

    touch fly.txt
    
    echo "You are not strong, no one brave for you" > fly.txt
    
    sudo /usr/bin/fdfs_upload_file /etc/fdfs/client.conf fly.txt
    
    • 1
    • 2
    • 3
    • 4
    • 5

    得到:

    group1/M00/00/00/wKgAaGNnwtmAYy4NAAAAKTIQHvk741.txt
    
    • 1

    拿到存储位置:group1/M00/00/00/wKgAaGNnwtmAYy4NAAAAKTIQHvk741.txt,如果是group1开头,查看group1中storage文件是否存在。

    浏览器输入:

    http://192.168.10.104/group1/M00/00/00/wKgAaGNnwtmAYy4NAAAAKTIQHvk741.txt
    
    • 1

    浏览器能显示对应的文本信息。

    在这里插入图片描述

  • 相关阅读:
    HTML5期末考核大作业,电影网站——橙色国外电影 web期末作业设计网页
    分布式--Redis的安装与数据类型的使用
    49.集群节点维护—滚动升级-2
    【MySQL 安装】基本操作命令
    2021-arXiv-The Power of Scale for Parameter-Efficient Prompt Tuning
    java计算机毕业设计小福星宠物领养演示视频源程序+mysql+系统+lw文档+远程调试
    视觉任务相关的问题汇总
    [U3D ShaderGraph] 全面学习ShaderGraph节点 | 第三课 | Input/Gradient
    极简二叉树
    使用IDEA时遇到java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver报错的解决方案
  • 原文地址:https://blog.csdn.net/Long_xu/article/details/127720603