i've got another question for you. I have Amazon EC2 instance with mondodb installed. It works great except one thing - i can't access (connect to) it from outside (my PC). I think the problem with Security Groups. It's some sort of default firewall. Does anyone know how to configure EC2 instance to have access to mongodb? Thanks in advance.
相关问题
- MongoDB can not create unique sparse index (duplic
- “Zero out” sensitive String data in Swift
- Spring Data MongoDB - lazy access to some fields
- JQ: Select when attribute value exists in a bash a
- Golang mongodb aggregation
相关文章
- mongodb有没有什么办法禁止读取数据的时候进行缓存
- mongodb-aggregate聚合查询分组后如何获得多字段
- Warning : HTML 1300 Navigation occured?
- mongodb error: how do I make sure that your journa
- How to track MongoDB requests from a console appli
- I cannot locate production log files on Elastic Be
- MongoError: cannot infer query fields to set, path
- Security concerns about CORS
You need to add a security group exception for the port 27017 if you are using default config for you to access it from outside. For security group configuration, please check the amazon EC2 documentation. And if you are using a different port on Mongo, change the security group port accordingly.
--Sai
Is your EC2 instance a Windows server by any chance? If so, in addition to EC2's Security Groups you also need to configure Windows Firewall to allow the incoming connection.
Go To Administrative Tools, Windows Firewall with Advanced Security, and configure a new Rule that allows incoming connections on port 27017 (the default mongo port) or whatever port you've chosen.
Think carefully before doing this. If you open the ports, make sure you restrict the IP numbers that can access it, otherwise anyone will be able to access your database. You can enable authentication in MongoDB, but it's not particularly safe, just a username and password. You should not have your database open to the internet, it is not a good idea.
A better way than opening up ports in the EC2 firewall is to open an SSH tunnel an forward the port, this makes sure that only you can access the database, and only while the SSH tunnel is active.
Open up a new terminal and run this command (replacing user and host with the user you use when SSH'ing to your server and the name of the server):
The command will forward the port 27017 on your computer to the same port on the server. To connect to the MongoDB instance simply run
mongo
in a terminal (if that doesn't work, trymongo --host 127.0.0.1
or evenmongo --host 127.0.0.1 --port 27017
).If you run MongoDB on your local machine you will have to change the first port, since the local server is already using it. In that case run this command instead:
and then connect with
(possibly adding
--host 127.0.0.1
if it doesn't work).When you're done working with the database, exit
mongo
and press ctrl-C in the terminal with the SSH command.