2013-08-29 67 views
1

我有一些麻煩從我的java/scala worker連接到我的mysql服務器。試圖連接到tomcat6上的mysql服務器:java.net.UnknownHostException

這裏是堆棧跟蹤我:

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. 
    at sun.reflect.GeneratedConstructorAccessor25.newInstance(Unknown Source) ~[na:na] 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.6.0_27] 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532) ~[na:1.6.0_27] 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:355) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2479) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source) ~[na:na] 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.6.0_27] 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532) ~[na:1.6.0_27] 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at java.sql.DriverManager.getConnection(DriverManager.java:620) ~[na:1.6.0_27] 
    at java.sql.DriverManager.getConnection(DriverManager.java:200) ~[na:1.6.0_27] 
    at listen$IndexTransactionWorkerImpl.run(listen.scala:38) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at net.greghaines.jesque.worker.WorkerImpl.execute(WorkerImpl.java:630) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at net.greghaines.jesque.worker.WorkerImpl.process(WorkerImpl.java:600) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at net.greghaines.jesque.worker.WorkerImpl.poll(WorkerImpl.java:491) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at net.greghaines.jesque.worker.WorkerImpl.run(WorkerImpl.java:230) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at java.lang.Thread.run(Thread.java:679) [na:1.6.0_27] 
Caused by: java.net.UnknownHostException: mysql-vip 
    at java.net.InetAddress.getAllByName0(InetAddress.java:1229) ~[na:1.6.0_27] 
    at java.net.InetAddress.getAllByName(InetAddress.java:1156) ~[na:1.6.0_27] 
    at java.net.InetAddress.getAllByName(InetAddress.java:1092) ~[na:1.6.0_27] 
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:249) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:305) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    ... 29 common frames omitted 

它正常工作,直到某一點,工人是無法解析主機。如果我重新啓動工作人員,它將再次工作。

重要的事情:我能夠從機器ping主機!

我試圖使用IPv4與替代Djava.net.preferIPv4Stack=true,但我用的IPv4棧得到了同樣的錯誤。

到目前爲止我還沒有任何線索!謝謝你們的幫助!

+0

您是否已經嘗試使用主機名而不是IP地址? – Ankit

+0

@Ankit的IP地址是動態的,我只能用主機名是 – dbaq

+0

你有一個完整的主機名,而不是僅僅「的mysql-VIP」嘗試的mysql-VIP(從機器ping命令)?域搜索路徑可能存在問題。 – chrylis

回答

0

可以有這多種原因嘛,如果你不恰當地管理你的連接池可能會發生。從某種意義上說,如果你自己維護一個連接池(或者說使用apache dhcp或者某些東西),那麼你要麼打開太多的連接,以致於一切都被阻塞,或者不能很好地管理資源。

另一個原因可能是這樣的:(它發生和我們過了一個月後)。一次執行太多的長查詢時。我們在過程方面做了一些優化,並開始工作(通過禁用讀鎖)。