Jedis运行异常

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.
	
	

 
这可能是两个原因造成的,首先可能是redis的6379端口无法访问,请先在cmd中输入命令 
telnet 127.0.0.1 6379 

看看可不可以访问redis-server 机器的6379端口,如果不能访问,需要在远程机器关掉防火墙或者添加允许通过

我将该端口设置为允许通过,如图所示:


第二个问题:

DENIED Redis is running in protected mode 
because protected mode is enabled

报错信息很长,但是主要是说redis开启了protected mode,这也是Redis3.2加入的新特性,开启保护模式的redis只允许本机登录,同样设置在配置文件redis.conf中,

这里原来是yes代表开启了保护模式,后面可以填密码也可以填no代表关闭,我们这里选择关闭保护模式,wq保存退出后再重启redis-server。

本来我以为可以了,但是还是出现了相同错误,我有想绑定的IP地址注释了:

这时我满怀欣喜,以为这次总行了吧,我****,又出现了相同的错误。

最后研究发现问题所在:之前启动redis-server并没有指定配置文件,而Linux上的redis比较操蛋的一点就是如果你不指定配置文件去启动,那么你做的修改就没有用,会读取默认配置(PS:至于这个默认配置在哪我也不清楚),于是用下面这种方式启动就可以使修改的配置文件生效。

终于成功了。

ps:这里在说一个快速查找要修改位置的方法:

先用vim编辑,然后需要按空格,再加/protected(即要修改的protected),按enter键,就找到。如果文件中有多个protected,按N键就可以找到下一个protected,只到找到为止。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值