I have mongodb running on Linux 7. Java client from a remote system tries using Driver 3.0.2 to connect to it using code as shown below:
mongoClient = new MongoClient(new ServerAddress("10.12.22.22", 27017),
new MongoClientOptions.Builder().connectTimeout(300000).socketTimeout(300000).build());
The result is the following exception:
**INFO: Exception in monitor thread while connecting to server 10.12.22.22:27017
com.mongodb.MongoSocketOpenException: Exception opening socket**
at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
... 3 more
Java Client running on windows: 10.12.22.116 Mongo DB running on Linux: 10.12.22.22: 27017
When the Java client is executed, tcpdump on linux system clearly shows packets reaching mongo db process but still no response from db.
[root@localhost ~]# tcpdump -i enp0s3 port 27017 -vv
tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 65535 bytes00:22:40.026816 IP (tos 0x0, ttl 128, id 8435, offset 0, flags [DF], proto TCP (6), length 52)
10.12.22.116.12364 > 10.12.22.22.27017: Flags [S], cksum 0xdd04 (correct), seq 1967333969, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
00:22:43.026954 IP (tos 0x0, ttl 128, id 8437, offset 0, flags [DF], proto TCP (6), length 52)
10.12.22.116.12364 > 10.12.22.22.27017: Flags [S], cksum 0xdd04 (correct), seq 1967333969, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
00:22:49.028216 IP (tos 0x0, ttl 128, id 8439, offset 0, flags [DF], proto TCP (6), length 48)
MongodB is listening at target port as shown below:
[root@localhost ~]# netstat -tunlep
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 0 20288 2360/master
tcp 0 0 10.12.22.22:27017 0.0.0.0:* LISTEN 1001 27947 3220/mongod**
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 1001 27945 3220/mongod
There is no firewall active as well (checked using iptables -L -n)
Please see what is missing here which is causing this issue?
ps axu | grep [m]ongodand the content of your mongod.conf. Furthermore, what is the result oftelnet 10.12.22.22 27017when executed on the client? As a side node: postfix should not be run as root, iirc.