zoukankan      html  css  js  c++  java
  • Redis远程连接报错解决

    今天测试了一下在本机(win10系统)远程连接 centos下的redis,结果报了以下错误:

    Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions:
    1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.
    2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server
    3) If you started the server manually just for testing, restart it with the '--protected-mode no' option.
    4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
    at redis.clients.jedis.Protocol.processError(Protocol.java:127)
    at redis.clients.jedis.Protocol.process(Protocol.java:161)
    at redis.clients.jedis.Protocol.read(Protocol.java:215)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
    at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
    at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:196)
    at com.example.redis.JedisTest.main(JedisTest.java:24)

    英语勉强及格的我勉强看了一下这段恼人的英文,貌似有以下解决方案:

    1.修改redis.conf配置文件,将绑定的ip地址端口号给注释掉。(redis默认绑定本机地址,所以其他IP连接不上,将这一行注释掉:# bind 127.0.0.1) 

             

    2.Linux上的redis默认处于安全保护模式,因此我们无法建立连接,提供了两种解决方法,

      2.1 一在redis.conf中设置保护模式为no(protected-mode no),如下图:

      2.2 redis默认是不需要密码的,可以直接登录,在这里我们加上安全认证,即加上连接密码(requirepass "my_keyword"),见下图 :

     

    值得注意的是,这样修改后,在测试代码中要加上密码:jedis.auth("my_keyword");完整测试代码为:

    import redis.clients.jedis.Jedis;

    public class TestPing {

    public static void main(String[] args)
    {
    Jedis jedis = new Jedis("12.345.678.789",6379);

    jedis.auth("my_keyword");

    System.out.println(jedis.ping());
    }
    }

    最后,杀掉redis的相关进程并重启服务,记得启动时一定要指定配置文件。我的启动命令为:/usr/local/redis/bin/redis-server  /usr/local/redis/etc/redis.conf

    完美解决!

    来都来了,点个推荐再走呗!

  • 相关阅读:
    顺序查找
    折半查找
    KMP
    php长时间的脚本,报502
    AcWing 27. 数值的整数次方
    acwing 25. 剪绳子
    Best Cow Line <挑战程序设计竞赛> 习题 poj 3617
    acwing 23. 矩阵中的路径
    AcWing 34. 链表中环的入口结点
    AcWing 33. 链表中倒数第k个节点
  • 原文地址:https://www.cnblogs.com/doufuyu/p/10861282.html
Copyright © 2011-2022 走看看