淺析Caused by: java.net.SocketTimeoutException: connect timed out的原因及解決
阿新 • • 發佈:2021-08-03
部署時碰到一個錯誤,如下:
java.net.SocketTimeoutException: connect timed out
at redis.clients.jedis.Connection.connect(Connection.java:)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:)
at redis.clients.jedis.Connection.sendCommand(Connection.java:)
at redis.clients.jedis.Connection.sendCommand(Connection.java:)
at redis.clients.jedis.BinaryClient.multi(BinaryClient.java:)
at redis.clients.jedis.BinaryJedis.multi(BinaryJedis.java:)
at cn.edu.aynu.redis.TestTx.main(TestTx.java:)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:)
at java.net.Socket.connect(Socket.java:)
at redis.clients.jedis.Connection.connect(Connection.java:)
... more
這個其實是 redis 的連線錯誤,不是資料庫的連線報錯哦,資料庫的連線報錯是這個:jdbc connection refused
具體原因是有多種,比如:ip 寫錯了,埠沒開放,ip無法ping通不允許訪問等
我這裡是因為伺服器 ip 無法 ping 通,在安全組裡放開即可解決。