安装nginx和nginx-gridfs和mongodb
Posted amoyzhu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安装nginx和nginx-gridfs和mongodb相关的知识,希望对你有一定的参考价值。
1.安装依赖包:
[[email protected]_rs1 ~]# yum -y install pcre-devel openssl-devel zlib-devel git gcc gcc-c++
[[email protected]_rs1 zhuyr]# git clone https://github.com/mdirolf/nginx-gridfs.git [[email protected]_rs1 zhuyr]# cd nginx-gridfs/ [[email protected]_rs1 nginx-gridfs]# git checkout v0.8 [[email protected]_rs1 nginx-gridfs]# git branch [[email protected]_rs1 nginx-gridfs]# git submodule init #子模组 ‘mongo-c-driver‘ (git://github.com/mongodb/mongo-c-driver.git) 已为路径 ‘mongo-c-driver‘ 注册 [[email protected]_rs1 nginx-gridfs]# git submodule update 正克隆到 ‘mongo-c-driver‘... remote: Counting objects: 101193, done. remote: Compressing objects: 100% (128/128), done. remote: Total 101193 (delta 159), reused 195 (delta 127), pack-reused 100938 接收对象中: 100% (101193/101193), 49.45 MiB | 4.55 MiB/s, done. 处理 delta 中: 100% (88309/88309), done. 子模组路径 ‘mongo-c-driver‘:检出 ‘74cc0b8005fbbc84ec4a0003ff80c68f9e9cc7de‘
2.安装nginx
[[email protected]_rs1 zhuyr]# wget http://nginx.org/download/nginx-1.7.9.tar.gz [[email protected]_rs1 zhuyr]# tar -zxvf nginx-1.7.9.tar.gz [[email protected]_rs1 zhuyr]# cd nginx-1.7.9/ [[email protected]_rs1 nginx-1.7.9]# ./configure --prefix=/usr/local/nginx --with-openssl=/usr/include/openssl --add-module=/zhuyr/nginx-gridfs [[email protected]_rs1 nginx-1.7.9]# make -j8 && make install -j8
#如果报错 [[email protected]_rs1 nginx-1.7.9]# ./configure --prefix=/usr/local/nginx --with-openssl=/usr/include/openssl --add-module=/zhuyr/nginx-gridfs #把第3行的-Werror错误去掉 [[email protected]_rs1 nginx-1.7.9]# vi objs/Makefile [[email protected]_rs1 nginx-1.7.9]# make && make install
3.修改配置文件
[[email protected]_rs1 nginx-1.7.9]# vi /usr/local/nginx/conf/nginx.conf #添加以下内容 location /girdfstest/ { gridfs pics field=_id type=objectid; mongo 127.0.0.1:27017; }
#gridfstest:访问地址
#pics:数据库
#mongo 127.0.0.1:10001 #mongo的服务器地址及端口
#启动nginx [[email protected]_rs1 nginx-1.7.9]# /usr/local/nginx/sbin/nginx #配置修改后重新加载 [[email protected]_rs1 nginx-1.7.9]# /usr/local/nginx/sbin/nginx -s reload
4.安装mongodb
vi /etc/yum.repos.d/mongodb-org-3.4.repo [mongodb-org-3.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/ gpgcheck=0 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc $ yum -y install mongodb-org 查看修改配置文件 : vim /etc/mongod.conf 启动mongodb :systemctl start mongod.service 停止mongodb :systemctl stop mongod.service
如果报错:
[[email protected] nginx-1.7.9]# journalctl -xe 7月 11 10:54:03 ansible.test yum[797]: Erased: mongodb-org-3.2.20-1.el7.x86_64 7月 11 10:54:04 ansible.test systemd[1]: Reloading. 7月 11 10:54:04 ansible.test systemd[1]: Configuration file /usr/lib/systemd/system/ebtables.service is marked executable. Ple 7月 11 10:54:04 ansible.test systemd[1]: Configuration file /usr/lib/systemd/system/wpa_supplicant.service is marked executabl 7月 11 10:54:04 ansible.test yum[797]: Erased: mongodb-org-server-3.2.20-1.el7.x86_64 7月 11 10:54:04 ansible.test yum[797]: Erased: mongodb-org-shell-3.2.20-1.el7.x86_64 7月 11 10:54:04 ansible.test yum[797]: Erased: mongodb-org-mongos-3.2.20-1.el7.x86_64 7月 11 10:54:04 ansible.test yum[797]: Erased: mongodb-org-tools-3.2.20-1.el7.x86_64 7月 11 10:59:08 ansible.test systemd[1]: Reloading. 7月 11 10:59:08 ansible.test systemd[1]: Configuration file /usr/lib/systemd/system/ebtables.service is marked executable. Ple 7月 11 10:59:08 ansible.test systemd[1]: Configuration file /usr/lib/systemd/system/wpa_supplicant.service is marked executabl 7月 11 10:59:08 ansible.test yum[928]: Installed: mongodb-org-server-3.2.20-1.el7.x86_64 7月 11 10:59:08 ansible.test yum[928]: Installed: mongodb-org-mongos-3.2.20-1.el7.x86_64 7月 11 10:59:12 ansible.test yum[928]: Installed: mongodb-org-tools-3.2.20-1.el7.x86_64 7月 11 10:59:13 ansible.test yum[928]: Installed: mongodb-org-shell-3.2.20-1.el7.x86_64 7月 11 10:59:13 ansible.test yum[928]: Installed: mongodb-org-3.2.20-1.el7.x86_64 7月 11 10:59:21 ansible.test polkitd[747]: Registered Authentication Agent for unix-process:961:41855579 (system bus name :1.1 7月 11 10:59:21 ansible.test systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database.... -- Subject: Unit mongod.service has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit mongod.service has begun starting up. 7月 11 10:59:21 ansible.test mongod[966]: Error starting mongod. /var/run/mongodb/mongod.pid exists. 7月 11 10:59:21 ansible.test systemd[1]: mongod.service: control process exited, code=exited status=1 7月 11 10:59:21 ansible.test systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
#解决方法: [[email protected] mongodb]# rm /var/run/mongodb/mongod.pid -f [[email protected] mongodb]# systemctl start mongod.service
5.使用mongofiles工具
[[email protected]_rs1 tmp]# mongofiles put 1.JPG -d pics -t jpg 2018-07-11T11:34:16.002+0800 connected to: localhost added file: 1.JPG [[email protected]_rs1 tmp]# mongofiles list -d pics 2018-07-11T11:34:33.037+0800 connected to: localhost 1.JPG 138424 [[email protected]_rs1 tmp]#
6.http访问:
http://172.16.160.91/girdfstest/1.jpg
以上是关于安装nginx和nginx-gridfs和mongodb的主要内容,如果未能解决你的问题,请参考以下文章