Redis报错:DENIED Redis is running in protected mode

Redis默认配置是不需要密码认证的,也就是说只要连接的Redis服务器的host和port正确,就可以连接使用。这在安全性上会有一定的问题,所以需要启用Redis的认证密码,增加Redis服务器的安全性。

1. 修改配置文件

Redis的配置文件默认在/etc/redis.conf,找到如下行:

#requirepass foobared

去掉前面的注释,并修改为所需要的密码:

requirepass myPassword (其中myPassword就是要设置的密码)

2. 重启Redis

如果Redis已经配置为service服务,可以通过以下方式重启:

service redis restart

如果Redis没有配置为service服务,可以通过以下方式重启:

/usr/local/bin/redis-cli shutdown
/usr/local/bin/redis-server /etc/redis.conf

3. 登录验证

设置Redis认证密码后,客户端登录时需要使用-a参数输入认证密码,不添加该参数虽然也可以登录成功,但是没有任何操作权限。如下:

$ ./redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.

使用密码认证登录,并验证操作权限:

$ ./redis-cli -h 127.0.0.1 -p 6379 -a myPassword
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "myPassword"

看到类似上面的输出,说明Reids密码认证配置成功。

除了按上面的方式在登录时,使用-a参数输入登录密码外。也可以不指定,在连接后进行验证:

$ ./redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> auth myPassword
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "myPassword"
127.0.0.1:6379> 

4. 在命令行客户端配置密码(redis重启前有效)

前面介绍了通过redis.conf配置密码,这种配置方式需要重新启动Redis。也可以通命令行客户端配置密码,这种配置方式不用重新启动Redis。配置方式如下:

127.0.0.1:6379> config set requirepass newPassword
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "newPassword"

注意使用命令行客户端配置密码,重启Redis后仍然会使用redis.conf配置文件中的密码。

5. 在Redis集群中使用认证密码

如果Redis服务器,使用了集群。除了在master中配置密码外,也需要在slave中进行相应配置。在slave的配置文件中找到如下行,去掉注释并修改与master相同的密码即可:

# masterauth master-password

文章转自:http://itbilu.com/linux/management/Ey_r7mWR.html

原文地址:https://www.cnblogs.com/HHHAI/p/11116674.html

时间: 2024-08-08 21:30:42

Redis报错:DENIED Redis is running in protected mode的相关文章

连接redis报错MISCONF Redis is configured to save RDB s

连接redis报错MISCONF Redis is configured to save RDB snapshots date: Mon Nov 11 16:11:24 CST 2019 笔者:张首富 程序报错如下 redis.exceptions.ResponseError: MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands t

python操作redis报错:redis.exceptions.DataError: ZADD allows either 'nx' or 'xx', not both解决方案

一.问题描述 sorted set操作执行:print(connect.zadd('grade', 'bob', 98, 'mike' ,100))时报错redis.exceptions.DataError: ZADD allows either 'nx' or 'xx', not both 二.出现该问题原因 上面的connect.zadd('key','value1','score1','value2','score2')写法是redis-py 3.0之前的版本 在redis-py 3.0版

mac brew install redis 报错

mac brew install redis 报错 /usr/local/opt/php55/bin/phpize /usr/local/opt/php55/bin/phpize: line 61: /usr/local/Library/ENV/4.3/sed: No such file or directory /usr/local/opt/php55/bin/phpize: line 62: /usr/local/Library/ENV/4.3/sed: No such file or di

LogStash启动报错:<Redis::CommandError: ERR unknown command 'script'>与batch_count 的 配置

环境条件: 系统版本:centos 6.8 logstash版本:6.3.2 redis版本:2.4 logstash  input配置: input { redis { host => "172.16.73.33" #redis ip port => "52611" #redis 端口 password =>"123456" #redis 密码 db => 9 # 指定redis 库编号 data_type =>

redis报错: redis.exceptions.ResponseError: value is not an integer or out of range

问题描述 今天在使用python的redis客户端时碰到了这样的报错:redis.exceptions.ResponseError: value is not an integer or out of range,是在使用setex函数时出的问题. 问题分析 明明在我的开发环境上跑的好好着,怎么到测试环境就有问题了?然后试着看了下我的开发环境和测试环境的redis客户端版本,一个是2.x,一个是3.x,测试环境的redis客户端是新安装的,那就把3.x卸了装个2.x吧,再跑的就ok了,看来是版本

Redis报错“ OOM command not allowed when used memory > 'maxmemory' ”

生产环境上遇到这个问题,控制台不停打印 “OOM command not allowed when used memory > 'maxmemory' ”; 起初不知道是什么,经过一番搜索: 1.登陆redis客户端:./redis-cli -h IP -p port -a passwd 2.执行命令:redis>info memory 若配置文件中,最大内存的策略设置为 maxmemory-policy volatile-lru 此配置只是清楚设置过期时间的key值,然而本应用并没有设置过期

c# 传递Null的string值导致的调用C++的dll报错 Attempted to read or write protected memory.

c# 调用C++的dll报错 Attempted to read or write protected memory:   原因是:c# 传递Null的string值导致的,将Null改为string.empty即可

安装mysql_sniffer报错undefined reference to symbol '[email protected]@GLIBC_2.2.5'问题

按照https://github.com/Qihoo360/mysql-sniffer上的安装方法进行安装,make是报错如下 Linking CXX executable mysql-sniffer /usr/bin/ld: /root/mysql-sniffer/lib/libgthread-2.0.a(gthread-impl.o): undefined reference to symbol '[email protected]@GLIBC_2.2.5' //usr/lib64/libp

redis 报错 "CONFIG REWRITE failed: Permission denied"

无意中看到了redis的config rewrite这个命令.闲来无聊,所以打算自己做个实验.下面的文章是redis关于config rewrite的描述信息: CONFIG REWRITE 命令对启动 Redis 服务器时所指定的 redis.conf 文件进行改写: 因为 CONFIG SET 命令可以对服务器的当前配置进行修改, 而修改后的配置可能和 redis.conf 文件中所描述的配置不一样, CONFIG REWRITE 的作用就是通过尽可能少的修改, 将服务器当前所使用的配置记录

redis解决(DENIED Redis is running in protected mode because prote)

早上一个应用日志打印报错信息: 在应用上telnet端口和ping都没有问题,为什么还获取不到值呢. 先安装一个redis客户端进行测试:yum -y install redis redis-cli -h 192.168.32.12 -p 6887 然后就报错了: (error) DENIED Redis is running in protected mode because protected mode is-- 后来就查看配置发现redis.conf 该行也是注释的: # requirep