Java Connection virtual machine Redis Error problem solving method __redis.clients.jedis.

Source: Internet
Author: User
Tags iptables

Straight to the topic, the Java Connection virtual machine error, the code is as follows:


public class Testping {

public static void Main (string[] args) {
Jedis Jedis = new Jedis ("192.168.201.128", 6379);
System.out.println (Jedis.ping ());
}
}

To run the error, the console information is as follows:

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException:java.net.SocketTimeoutException : Connect timed out


For reference to some users of the solution:

Turn off the virtual machine's firewall

1) Temporarily shutdown firewall:/etc/init.d/iptables stop

2 Restart the virtual machine for effective: chkconfig iptables off or/sbin/chkconfig--level 2345 iptables off

The landlord uses the second method, as shown in the following figure:

After you restart the virtual machine, view the firewall status as shown in the following illustration



Continue running the above code with the following error:

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException:java.net.ConnectException: Connection Refused:connect

Solution, modify the redis.conf configuration file, and comment out the port number 127.0.0.1 so that any IP can be accessed, as shown in the following figure:



After you save the exit, run the code and find the error continues because the Redis service has not been started and the Redis service is started, as shown in the following illustration:



Run the code, at which point the error is as follows:

<span style= "color: #ff0000;" >exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: </span>
<span style= "color: #ff0000;" >denied Redis is running in protected mode because protected mode are enabled, no bind address was specified, no authent Ication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you are want to connect from external computers to redis your may adopt one of the following solutions: </span>
<span style= "color: #ff0000;" >1) Just disable protected mode sending the command ' CONFIG SET protected-mode No ' from the loopback interface by Conne Cting to Redis from the same host the server is running, however make sure Redis are not publicly accessible from internet If you did so. Use CONFIG REWRITE The to make this change permanent. </span>
<span style= "color: #ff0000;" >2) Alternatively can just disable the protected mode by editing the Redis configuration file, and setting the prot ected mode option to ' No ', and then restarting the server. </span>
<span style= "color: #ff0000;" >3) If You are started the server manually just for testing, restart it with the '--protected-mode no ' option. </span>
<span style= "color: #ff0000;" >4) Setup A bind address or a authentication password. Note:you only need to does one of the above things in order for the server to start accepting connections. </span>

The above exception roughly means: Reject Redis in protected mode, no binding IP address, no authorization password, if you want to connect Redis from external computer, you have to adopt one of the following solutions

The second method that the landlord uses, modifies the redis.conf configuration file, changes Protected-mode Yes to No, as shown in the following figure


Reboot the virtual machine and start the Redis service, as shown in the following figure


Run code, console output Pong, as shown in the following figure:

To this, the problem is solved.



Digression: I have a question is that the firewall and redis.conf configuration file has been commented on the IP, why the red error, through the Internet access to information, found that other netizens have similar problems, but most people use the Red error fourth solution, here to give a link


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.