Redis
官方网站
https://redis.io
教程
https://www.yiibai.com/redis/redis_java.html
redis解决(DENIED Redis is running in protected mode because prote)
(error) 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 lookback 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 --portected-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.conf
1)打开配置文件把下面对应的注释掉
#bind 127.0.0.1
2)Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程,设置为no daemonize no
3)保护模式 protected-mode no
报错处理:
一、
在对应配置conf文件中去掉注释,把yes改为no
#protected-mode yes protected-mode no
重启redis(注意有数据时慎重启)
kill -9 进程号
redis-cli -h 192.168.32.12 -p 6887 shutdown
二、添加认证,设置密码
#requirepass foobared
requirepass redis123456
验证
再次用Java程序建立连接池,没有报错,且可以对redis server进行数据正常处理。程序报错日志不再显示
问题解决
如何给redis设置密码
redis没有实现访问控制这个功能,但是它提供了一个轻量级的认证方式,可以编辑redis.conf配置来启用认证。
1、初始化Redis密码:
在配置文件中有个参数: requirepass 这个就是配置redis访问密码的参数;
比如 requirepass 123456;
(Ps:需重启Redis才能生效)
redis的查询速度是非常快的,外部用户一秒内可以尝试多大150K个密码;所以密码要尽量长(对于DBA 没有必要必须记住密码);
2、不重启Redis设置密码:
在配置文件中配置requirepass的密码(当redis重启时密码依然有效)。
redis 127.0.0.1:6379> config set requirepass 123456
查询密码:
redis 127.0.0.1:6379> config get requirepass (error) ERR operation not permitted
密码验证:
redis 127.0.0.1:6379> auth 123456 OK
再次查询:
redis 127.0.0.1:6379> config get requirepass
- "requirepass"
- "123456"
PS:如果配置文件中没添加密码 那么redis重启后,密码失效;
3、登陆有密码的Redis:
在登录的时候的时候输入密码:
redis-cli -p 6379 -a 123456
先登陆后验证:
redis-cli -p 6379
redis 127.0.0.1:6379> auth 123456 OK
AUTH命令跟其他redis命令一样,是没有加密的;阻止不了攻击者在网络上窃取你的密码;
认证层的目标是提供多一层的保护。如果防火墙或者用来保护redis的系统防御外部攻击失败的话,外部用户如果没有通过密码认证还是无法访问redis的。
参考
https://blog.csdn.net/Ay_Ly/article/details/92768453