今天测试了一下在本机(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

完美解决!

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

Redis远程连接报错解决的更多相关文章

  1. redis远程连接报错记录

    错误如下 redis可视化工具连接测试 telnet ip 6379 修改关键参数如下 #开通外网访问 # bind 127.0.0.1 #以后台方式运行 daemonize no #取消保护模式,保 ...

  2. Mysql远程连接报错:SQL Error (1130): Host '192.168.61.128' is not allowed to connect to this MySQL server

    Mysql远程连接报错:SQL Error (1130): Host '192.168.0.18' is not allowed to connect to this MySQL server     ...

  3. VS Code远程链接报错Could not establish connection to “hz.matpool.com”

    VS Code远程链接报错Could not establish connection to "hz-t2.matpool.com" 输出的部分内容 安装Git git for w ...

  4. 远程桌面报错解决:No Remote Desktop License Servers Available

    摘 要 用户发来反馈,使用部门Windows跳板机报错:The remote session was disconnected because there are no Remote Desktop ...

  5. mysq远程连接报错,host..

    在本机登入mysql后,更改"mysql"数据库里的"user"表里的"host"项,从"localhost"改为'%' ...

  6. windows 远程连接报错

    在windows7上或者windows10上远程连接服务器报错("连接错误"),试了网上的方法,发现是服务器安装ssl证书关闭了ssh服务,开启ssh服务后,重启电脑就可以解决这个 ...

  7. redis远程连接不上解决办法

    结构:PC-A 运行redis client,PC-B运行redis server PC-B方面 在server中,修改配置文件redis.windows-service.conf中的: 1.注释 # ...

  8. Mysql远程连接报错:SQL Error (1130): Host '192.168.6.128' is not allowed to connect to this MySQL server

    通过SQLyog连接linux中的MySQL报错问题:SQL Error (1130): Host '192.168.6.128' is not allowed to connect to this ...

  9. pymysql模块操作数据库及连接报错解决方法

    import pymysql sql = "select host,user,password from user" #想要执行的MySQL语句 #sql = 'create da ...

随机推荐

  1. Win7如何显示文件后缀

    有些时候,我们需要修改文件的后缀名,但是Windows7系统默认不显示文件后缀.我们怎样显示和修改文件后缀呢?请接着往下看. 工具/原料   一个win7系统 方法/步骤   1 如图所示,此时是无法 ...

  2. POJ2406 Power Strings 题解 KMP算法

    题目链接:http://poj.org/problem?id=2406 题目大意:给你一个字符串 \(t\) ,\(t\) 可以表示为另一个小字符串循环了 \(K\) 了,求最大的循环次数 \(K\) ...

  3. P1111 朋友关系判定

    题目描述 有n个人和m对关系,这n个人的编号从1到n. 而m对关系中,每对关系都包含两个人的编号A和B(1<=A,B<=n),用于表示A和B是好友关系. 如果两个数A和B不在好友关系中,则 ...

  4. git把某个文件去除版本控制

    谢谢@jessicway 同学的提醒.我之前没考虑只需要删除服务器上已提交的文件,但是本地不想删除的情况. 我们先看看 git rm 命令的说明 可以看到其实加上 --cached 参数就可以实现只去 ...

  5. Character.digit()的意义

    最近在阅读Integet.parseInt()源码时,遇到了Character.digit()这个方法,以前没有遇到过,更没使用过,这里查了资料就记录一下. 官方说法是: java.lang.Char ...

  6. tomcat下的work目录和temp目录

    1. tomcat下的work目录 1    用tomcat作web服务器的时候,部署的程序在webApps下,这些程序都是编译后的程序(发布到tomcat的项目里含的类,会被编译成.class后才发 ...

  7. linux进程睡眠的介绍

    对于一个进程"睡眠"意味着什么? 当一个进程被置为睡眠, 它被标识为处于一个特殊的状 态并且从调度器的运行队列中去除. 直到发生某些事情改变了那个状态, 这个进程将不被 在任何 C ...

  8. Linux 内核PC/104 和 PC/104+

    当前在工业世界中, 2 个总线体系是非常时髦的: PC/104 和 PC/104+. 2 个在 PC-类 的 单板计算机中都是标准的. 2 个标准都是印刷电路板的特殊形式, 包括板互连的电子的/机械的 ...

  9. 2018-11-9-win2d-CanvasCommandList-使用方法

    title author date CreateTime categories win2d CanvasCommandList 使用方法 lindexi 2018-11-9 20:8:4 +0800 ...

  10. ES6必须 知道的小知识

    1.函数的默认参数 一般 我们给函数设置默认参数的时候  会在函数里用 || 运算符 比如 function show(width,height ....){ var height = height ...