当前位置:   article > 正文

linux下部署单节点FastDFS及fdfs整合nginx_linux fastdfs

linux fastdfs

      (一)安装前准备

        检查Linux上是否安装了 gcc、libevent、libevent-devel

        yum list installed | grep gcc

        yum list installed | grep libevent

        yum list installed | grep libevent-devel

        没有执行安装命令:

        yum install libevent-devel -y

      (二)安装 libfastcommon 库

        libfastcommon 库是 FastDFS 文件系统运行需要的公共 C 语言函数库

        下载地址:

        https://github.com/happyfish100/libfastcommon/releases/tag/V1.0.36

        在/usr/local下创建fastdfs文件夹

        libfastcommon-1.0.36.tar.gz包上传到/usr/local/fastdfs

        依次执行以下命令:

                tar -zxvf libfastcommon-1.0.36.tar.gz

                cd libfastcommon-1.0.36

        编译并安装:

                ./make.sh

                ./make.sh install

      (三)安装fastdfs

        下载地址:

        https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz

        fastdfs-5.11.tar.gz包上传到/usr/local/fastdfs

        依次执行以下命令:

                tar -zxvf fastdfs-5.11.tar.gz

                cd fastdfs-5.11

        编译并安装:

                ./make.sh

                ./make install

         编译报错解决办法安装插件:

        yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget

        拷贝配置文件:

                cd conf/

                cp http.conf  /etc/fdfs/

                cp mime.types  /etc/fdfs/

                cp storage.conf  /etc/fdfs/

                cp tracker.conf  /etc/fdfs/

                cp client.conf  /etc/fdfs/

        修改配置文件:

        ① 配置tracker

        cd /etc/fdfs/

        vi tracker.conf

        修改以下项:

                base_path=/usr/local/fastdfs/tracker

                store_group=group1

                http.server_port=3445          #与nginx配置端口一致

        修改后保存,在/usr/local/fastdfs下创建tracker文件夹

        ② 配置storage

        cd /etc/fdfs/

        vi storage.conf

        修改以下项:

                base_path=/usr/local/fastdfs/storage

                group_name=group1

                store_path_count=1

                store_path0=/usr/local/fastdfs/file

                tracker_server=127.0.0.1:22122

                http.server_port=3445         #与nginx配置端口一致

        修改后保存,在/usr/local/fastdfs下创建storage、file文件夹

        ③ 配置client

        cd /etc/fdfs/

        vi client.conf

        修改以下项:

                base_path=/usr/local/fastdfs/client

                tracker_server=127.0.0.1:22122

        修改后保存,在/usr/local/fastdfs下创建client文件夹

        启动fdfs:

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

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

        查看storage服务器是否已经登记到 tracker服务器

        /usr/bin/fdfs_monitor  /etc/fdfs/storage.conf

      (四)安装fastdfs-nginx-module

        下载地址:

        https://github.com/happyfish100/fastdfs-nginx-module/releases/tag/V1.20

        fastdfs-nginx-module-1.20.tar.gz包上传到/usr/local/fastdfs

        tar -zxvf fastdfs-nginx-module-1.20.tar.gz

        修改配置:

        cd /usr/local/fastdfs/fastdfs-nginx-module-1.20/src

        vi /usr/local/fastdfs/fastdfs-nginx-module-1.20/src/config

        如图以下标红项修改如下:

         拷贝配置文件:

        cp mod_fastdfs.conf  /etc/fdfs/

        cd /etc/fdfs

        vi mod_fastdfs.conf

        下图中标红配置项修改如下:

       (五)安装nginx,fastdfs-nginx-module插件加入到Nginx

        下载nginx:nginx: download

        nginx-1.24.0.tar.gz包上传到/usr/local/fastdfs

        tar -zxvf nginx-1.24.0.tar.gz

        fastdfs-nginx-module插件添加到Nginx中

        cd /usr/local/fastdfs/nginx-1.24.0/

        ./configure --add-module=/usr/local/fastdfs/fastdfs-nginx-module-1.20/src

        编译安装nginx:

                make

                make install

        修改配置文件:

        cd /usr/local/nginx/conf/

        vi nginx.conf

        添加如下配置:

         启动nginx:

        cd cd /usr/local/nginx/sbin/

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

        至此fdfs与nginx配置完成,验证是否能上传文件并访问

        /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /etc/fdfs/1.jpg

        查看图片:

        http://服务器IP:3445/group1/M02/00/00/wKgTpmSJUs2AfEEUAAj5iLHbrAQ798.jpg

        (六)遇到的问题

        ① fastdfs整合nginx报错

        nginx添加fastdfs-nginx-module插件后,编译报错如下:

        /fastdfs-ngxin-modile/src/common.c:351:32:错误:在非结构或联合中请求成员‘path’

        出现以上错误信息的原因是fastdfs和fastdfs-nginx-module的版本问题,本文中版本匹配。

        ② 通过nginx访问图片失败,nginx日志如下:

        ERROR - file: /usr/local/fastdfs/fastdfs-nginx-module-1.20/src/common.c, line: 111, section: group1, you must set parameter: group_name!

         出现以上错误信息是fastdfs-nginx-module的配置文件mod_fastdfs.conf未配置分组信息,找到配置文件中下图位置进行配置,与storage.conf一致。

        ③ 下载文件CORS error问题,配置nginx跨域请求

        在nginx.conf中添加配置:

                add_header 'Access-Control-Allow-Origin' '*';

                add_header 'Access-Control-Allow-Credentials' 'true';

                add_header "Access-Control-Allow-Methods" "GET, POST, HEAD, PUT, DELETE, OPTIONS, PATCH";

                add_header "Access-Control-Allow-Headers" "Origin, No-Cache, Authorization, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type,DNT,X-CustomHeader,Keep-Alive,User-Agent,";

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/441453
推荐阅读
相关标签
  

闽ICP备14008679号