java 連結的伺服器上的 mongodb 出現 connect time out 問題

來源:互聯網
上載者:User

標籤:mongodb connect time

異常資訊

十二月 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


再試試代碼,搞定!

java 連結的伺服器上的 mongodb 出現 connect time out 問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.