Mohitt
Mohitt

Reputation: 2977

Mongodb on Azure VM : Mongodb not reachable

Case 1. I installed mongo on my machine (Mac OS), and mongo is configured with bind-ip : 127.0.0.1. A remote machine in LAN can connect to my mongodb using my IP. (Wrong observation : See UPDATE section)

Case 2. I installed mongo on Azure Ubuntu VM, mongo configured with bind-ip:127.0.0.1. No remote machine from the same VNet can connect to that mongo using private vnet IP.

MongoDB Network Setting (both case 1 and case 2):

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1  

Exception (Case 2):

2018-04-03 06:35:29.948 INFO 44518 --- [72.17.1.4:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 172.17.1.4:27017

com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.4.1.jar!/:na] at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.4.1.jar!/:na] at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongodb-driver-core-3.4.1.jar!/:na] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151] Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_151] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_151] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_151] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_151] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_151] at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_151] at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[mongodb-driver-core-3.4.1.jar!/:na] at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongodb-driver-core-3.4.1.jar!/:na] ... 3 common frames omitted

Whats is different in Azure VM that it behaves differently from a Mac OS installation?

Note: Changing the bindIp to the IP (172.17.1.4) or 0.0.0.0 works.

UPDATE:

Case 1: The remote access on my local machine's mongo was because of the distribution I picked which was configured to allow remote connections.

Upvotes: 1

Views: 1116

Answers (1)

Shui shengbao
Shui shengbao

Reputation: 19195

Based on my knowledge, 127.0.0.1 only works inside machine. You could check this blog.

By default, MongoDB bind to local interface only, it will restrict the remote connections. If you don’t care about security, just comment out to accept any remote connections (NOT Recommend).

I suggest you could configure Mongodb like bind_ip = 127.0.0.1,172.17.1.4.

Upvotes: 2

Related Questions