>데이터 베이스 >MySQL 튜토리얼 >java链接服务器上的mongodb出现connecttimeout问题

java链接服务器上的mongodb出现connecttimeout问题

WBOY
WBOY원래의
2016-06-07 16:12:341482검색

异常信息 十二月 22, 2014 5:27:58 下午 com.mongodb.DBTCPConnector initDirectConnection 警告: Exception executing isMaster command on /192.168.1.249:10003 java.io.IOException: couldnt connect to [/192.168.1.249:10003] bc:java.net.SocketTimeo

异常信息

十二月 22, 2014 5:27:58 下午 com.mongodb.DBTCPConnector initDirectConnection
警告: Exception executing isMaster command on /192.168.1.249:10003
java.io.IOException: couldn't connect to [/192.168.1.249:10003] bc:java.net.SocketTimeoutException: connect timed out
at com.mongodb.DBPort._open(DBPort.java:214)
at com.mongodb.DBPort.go(DBPort.java:107)
at com.mongodb.DBPort.go(DBPort.java:88)
at com.mongodb.DBPort.findOne(DBPort.java:143)
at com.mongodb.DBPort.runCommand(DBPort.java:148)
at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:539)
at com.mongodb.Mongo.getMaxBsonObjectSize(Mongo.java:600)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:233)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:205)
at com.mongodb.DBCollection.insert(DBCollection.java:57)
at com.mongodb.DBCollection.insert(DBCollection.java:100)
at fileUpload.UploadFileTest.test(UploadFileTest.java:35)
at fileUpload.UploadFileTest.main(UploadFileTest.java:41)


十二月 22, 2014 5:28:08 下午 com.mongodb.DBTCPConnector initDirectConnection
警告: Exception executing isMaster command on /192.168.1.249:10003
java.io.IOException: couldn't connect to [/192.168.1.249:10003] bc:java.net.SocketTimeoutException: connect timed out
at com.mongodb.DBPort._open(DBPort.java:214)
at com.mongodb.DBPort.go(DBPort.java:107)
at com.mongodb.DBPort.go(DBPort.java:88)
at com.mongodb.DBPort.findOne(DBPort.java:143)
at com.mongodb.DBPort.runCommand(DBPort.java:148)
at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:539)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:518)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:174)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:155)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:249)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:205)
at com.mongodb.DBCollection.insert(DBCollection.java:57)
at com.mongodb.DBCollection.insert(DBCollection.java:100)
at fileUpload.UploadFileTest.test(UploadFileTest.java:35)
at fileUpload.UploadFileTest.main(UploadFileTest.java:41)

 

一些常规的解决方法,比如因网络原因连接超时等可以这么解决。讲的还挺详细

http://lingqi1818.iteye.com/blog/1317433

但是如果设置了这些东西还不能链接,说明服务器上的某些端口未打开造成不可连接。

解决方法要先配置ip表打开某些端口,再restart server即可。

root 进入server

vi /etc/sysconfig/iptables

添加

-A INPUT -m state --state NEW -m tcp -p tcp --dport 10002 -j ACCEPT (这里打开的端口为10002)

保存退出

service iptables restart

再试试代码,搞定!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.