centos8下nginx-gridfs安装及踩坑纪录

nginx-gridfs是一个可以通过http请求直接访问mongodb里gridfs存储的文件的一个插件,在使用过程中踩了不少版本的坑,记录下来,需要注意的点会用黄色打底标注。
先说一下能正常使用的最新环境:Centos8nginx-1.18.0mongodb 4.0.20

  • 安装前置环境
    yum install pcre pcre-devel zlib zlib-devel openssl openssl-devel gcc-c++ make
  • 下载nginx-gridfs(用master代码,不要用v0.8的tag)
    git clone https://github.com/mdirolf/nginx-gridfs.git
  • 下载mongo-c-driver(v0.7.1)
    wget https://github.com/eagleas/mongo-c-driver/archive/v0.7.1.tar.gz
  • 解压mongo-c-driver并复制到nginx-gridfs的mongo-c-driver目录中
  • 下载nginx源码包(我用了最新的stable版是1.18.0)
    wget http://nginx.org/download/nginx-1.18.0.tar.gz
  • 解压nginx-1.18.0.tar.gz并进入目录
  • 执行config,为保证和yum仓库安装配置一致这里所有参数照抄仓库版,这样可以编译之后直接替换yum安装的nginx,其中add-module指向你自己的nginx-gridfs目录
    ./configure --add-module=/opt/nginx-gridfs --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
  • 此时nginx目录下会生成objs文件夹,其中包含MakeFile
    在这里插入图片描述
    修改MakeFile,去掉CFLAGS参数中-Werror参数,不然在编译时Waring会被认为是ERROR导致编译失败。CFLAGS参数在不同的系统环境上可能会有不一样,无碍。
    在这里插入图片描述
  • 执行make,编译完成后执行./nginx -V查看信息
    在这里插入图片描述
  • nginx配置参考作者的readme即可,注意单机与replica set的mongodb配置有所不同
    在这里插入图片描述

遇到的坑

  • Mongo connection dropped, could not reconnect
    在这里插入图片描述
    MongoDB只支持4.0版本,最高是4.0.20,4.2及以上版本是不支持的,运行的时候会报503错误,查看nginx日志会有如下纪录。
    另外注意务必先启动mongodb再启动nginx,该插件不支持自动重连,如果mongodb服务断开需要重新启动一次nginx。
  • Cannot allocate memory
    在这里插入图片描述
    这种提示一般是因为nginx配置写错了,注意单机mongo与集群mongo的配置不一样
  • 集成mongo-c-driver的时候,作者文档上写的命令是:
    git submodule init
    git submodule update
    
    不要这样做,在编译的时候会报bson的错误,手动下载mongo-c-driver并复制进去
  • 以上命令在Centos7与Centos8都编译成功,但是centos8编译的肯定不能在低版本系统上运行,依赖库不一样。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值