简体   繁体   English

在单独的 ec2 实例上连接到 mongodb

[英]connect to mongodb on separate ec2 instance

I am running two different instances on AWS, one for node application and other for mongoDB.我在 AWS 上运行两个不同的实例,一个用于节点应用程序,另一个用于 mongoDB。 I am trying to connect to mongoDB on other instance but not able to and failing with "504 Gateway timed out".我正在尝试连接到其他实例上的 mongoDB,但无法连接并且因“504 网关超时”而失败。

My db_conf.js to connect to node application is like below:我连接到节点应用程序的 db_conf.js 如下所示:

var express = require('express');
var mongodb = require('mongodb');

var url = "mongodb://<PUBLIC IP of mongoDB instance>:27017/local";

module.exports = url;

I have commented the "bind_ip" in mongodb.conf and restarted mongoDB.我在 mongodb.conf 中注释了“bind_ip”并重新启动了 mongoDB。

Also, I have opened the port 27017 for the node application server's public IP from the security groups of mongoDB instance for both inbound and outbound but of no use.另外,我已经从 mongoDB 实例的安全组为节点应用程序服务器的公共 IP 打开了端口 27017,用于入站和出站,但没有用。

Please suggest a way to achieve this(if there is any).请提出一种实现这一目标的方法(如果有的话)。 Thanks in advance :)提前致谢 :)

All looks correct here, you do correctly open port 27017 on the mongoDB instance.这里看起来一切正常,您在 mongoDB 实例上正确打开了端口 27017。 Also, you may want to try and kill the original mongod server process, and restart it explicitly pointing to your config file so that it knows to use those settings.此外,您可能想尝试杀死原始的 mongod 服务器进程,并明确指向您的配置文件重新启动它,以便它知道使用这些设置。 Something like the following should accomplish this (assuming your on a linux machine and your config file is in the default folder)-类似以下的内容应该可以完成此操作(假设您在 linux 机器上并且您的配置文件位于默认文件夹中)-

sudo kill mongod PID须藤杀死mongod PID

and then进而

sudo mongod --fork --config /etc/mongod.conf须藤 mongod --fork --config /etc/mongod.conf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM