none
Cannot establish connection to Redis (by Jetware) from Spring boot application RRS feed

  • Question

  • I have a VM that is running Spring boot java application and needs to talk to two other VMs - one running Mongodb (connection is established and works) and the other is running Redis (CONNECTION COULD NOT BE ESTABLISHED). Here is some information that may help.

    byteeats@ByteEatsVMLinux:~/tomcat8/logs$ sudo lsof -i -n -P | more

    COMMAND     PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

    systemd-n   903 systemd-network   19u  IPv4  33130      0t0  UDP 10.0.1.6:68 

    systemd-r   928 systemd-resolve   12u  IPv4  32480      0t0  UDP 127.0.0.53:53 

    systemd-r   928 systemd-resolve   13u  IPv4  32481      0t0  TCP 127.0.0.53:53 (LISTEN)

    sshd       1777            root    3u  IPv4  38751      0t0  TCP *:22 (LISTEN)

    sshd       1777            root    4u  IPv6  38753      0t0  TCP *:22 (LISTEN)

    java      22733        byteeats    4u  IPv4 122431      0t0  TCP 127.0.0.1:8000 (LISTEN)

    java      22733        byteeats   57u  IPv6 122452      0t0  TCP *:8080 (LISTEN)

    java      22733        byteeats   62u  IPv6 122456      0t0  TCP *:8009 (LISTEN)

    java      22733        byteeats   81u  IPv6 122512      0t0  TCP 127.0.0.1:8005 (LISTEN)

    java      22733        byteeats  146u  IPv6 511369      0t0  TCP 10.0.1.6:44192->10.0.1.7:27017 (ESTABLISHED)

    java      22733        byteeats  147u  IPv6 511370      0t0  TCP 10.0.1.6:44194->10.0.1.7:27017 (ESTABLISHED)

    sshd      54933            root    3u  IPv4 473095      0t0  TCP 10.0.1.6:22->75.49.253.59:60459 (ESTABLISHED)

    sshd      55003        byteeats    3u  IPv4 473095      0t0  TCP 10.0.1.6:22->75.49.253.59:60459 (ESTABLISHED)

    sshd      59069            root    3u  IPv4 524033      0t0  TCP 10.0.1.6:22->218.92.0.138:36780 (ESTABLISHED)

    sshd      59070            sshd    3u  IPv4 524033      0t0  TCP 10.0.1.6:22->218.92.0.138:36780 (ESTABLISHED)


    In the above 10.0.1.6 is the private IP of VM that runs Mongodb, but interestingly the private IP of VM having Redis is 10.0.1.8 is not in the above list. But, I am able to ping it from the VM that runs Spring boot app.

    This is the error log:

    <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #ff0000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} span.Apple-tab-span {white-space:pre} </style>

    Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)

    at redis.clients.jedis.Connection.connect(Connection.java:207)

    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)

    at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)

    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:276)

    ... 61 common frames omitted

    Caused by: java.net.ConnectException: Connection refused (Connection refused)

    at java.net.PlainSocketImpl.socketConnect(Native Method)

    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)

    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)

    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)

    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

    at java.net.Socket.connect(Socket.java:589)

    at redis.clients.jedis.Connection.connect(Connection.java:184)

    <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #ff0000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures; color: #2fb41d} span.s2 {font-variant-ligatures: no-common-ligatures} span.s3 {font-variant-ligatures: no-common-ligatures; color: #400bd9} </style>
    Friday, September 13, 2019 7:54 PM

Answers

  • This issue has been resolved. The thing is that redis-server is binded to listed by default on localhost. so, find redis.conf and find then bind setting (bind 127.0.0.1 - its something like this). Replace the ip address with the private ip address of the VM where redis is running. Then, restart the redis server.

    This issue can be marked as resolved.

    Saturday, September 14, 2019 5:15 AM