当前位置: 首页 > 工具软件 > nginx-gridfs > 使用案例 >

安装nginx + nginx-gridfs + mongodb

顾宸
2023-12-01

1.安装依赖包

yum -y install pcre-devel openssl-devel zlib-devel git gcc gcc-c++
git clone https://github.com/mdirolf/nginx-gridfs.git
cd nginx-gridfs/
git checkout v0.8
git branch
git submodule init
git submodule update

2.安装nginx

wget http://nginx.org/download/nginx-1.7.9.tar.gz
tar -zxvf nginx-1.7.9.tar.gz
cd nginx-1.7.9/
./configure --prefix=/usr/local/nginx   --with-openssl=/usr/include/openssl --add-module=/usr/local/nginx-gridfs
make && make install 

3.修改配置文件

vi /usr/local/nginx/conf/nginx.conf
#添加以下内容
location /voice/ {
            gridfs vtest root_collection=fs;
            mongo 127.0.0.1:27017;
        }
 location /package/ {
            gridfs vtest root_collection=vp;
            mongo 127.0.0.1:27017;
        }
#修改完毕以后,启动nginx
/usr/local/nginx/sbin/nginx
#配置修改后重新加载
/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<br>mongodb的配置文件中的bind_ip 默认为127.0.0.1,默认只有本机可以连接。  此时,需要将bind_ip配置为0.0.0.0,表示接受任何IP的连接。
启动mongodb :systemctl start mongod.service
停止mongodb :systemctl stop mongod.service

安装如果出错

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..
#解决方法:
rm /var/run/mongodb/mongod.pid -f
systemctl start mongod.service

5.使用mongofiles工具进行测试

[root@localhost local]# mongofiles  put 1.png -d vtest -t png
2019-07-22T23:37:11.546-0700    connected to: localhost
added file: 1.png
[root@localhost local]# mongofiles list -d vtest
2019-07-22T23:38:31.949-0700    connected to: localhost
1.png   566915
[root@localhost local]# mongofiles -d vtest get 1.png
2019-07-22T23:38:56.741-0700    connected to: localhost
finished writing to: 1.png

转载于:https://www.cnblogs.com/alan319/p/11232077.html

 类似资料: