mongodb setup remote connection

This article mainly introduces how to connect to mongodb remotely.

If you have not installed mongodb, you can refer to the following articles:

https://blog.csdn.net/wild46cat/article/details/79455705

OK, let's load it up below.

1. Set the /etc/mongod.conf file

mongodb does not allow remote connections by default and needs to be configured in the configuration file

vim /etc/mongod.conf

Note what's inside:

net:
  port: 27017
  bindIp: 127.0.0.1  # Listen to local interface only, comment to listen on all interfaces.

We need to change this bindIp to 0.0.0.0 to allow access from any remote host.

Modified as follows:

net:
  port: 27017
  bindIp: 0.0.0.0  # Listen to local interface only, comment to listen on all interfaces.

Then start mongodb.

systemctl restart mongodb.service


2. Turn off the firewall, or allow 27017 to access externally.

Under normal circumstances, this is OK, but you need to pay attention to whether your firewall allows 27017 (or the port you configured) to support external access.

We can turn off the firewall violently first:

systemctl stop firewalld

3. Test the connection

mongo 192.168.0.11:27017

If the configuration is correct, then you can enter the mongoshell.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325590796&siteId=291194637