转:Redis使用认证密码登录

 

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

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

  1. docker启动redis报错 oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

    docker启动redis报错 1:C 17 Jun 08:18:04.613 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo1:C 17 Jun 08 ...

  2. Redis报错:redis.exceptions.ResponseError: MISCONF Redis is configured to save RDB snap

    首先找到出现错误的原因: redis.exceptions.ResponseError: MISCONF Redis is configured to save RDB snapshots, but ...

  3. redis报错MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist

    解决方法:通过redis-cli连接到服务器后执行以下命令: config set stop-writes-on-bgsave-error no 注意:这种方法只是忽略了问题,并没有解决问题,具体问题 ...

  4. 2017.7.10 Redis报错:DENIED Redis is running in protected mode

    参考来自: java 客户端链接不上redis解决方案 DENIED Redis is running in protected mode 完整错误信息: Caused by: redis.clien ...

  5. 使用Lua 脚本实现redis 分布式锁,报错:ERR Error running script (call to f_8ea1e266485534d17ddba5af05c1b61273c30467): @user_script:10: @user_script: 10: Lua redis() command arguments must be strings or integers .

    在使用SpringBoot开发时,使用RedisTemplate执行 redisTemplate.execute(lockScript, redisList); 发现报错: ERR Error run ...

  6. mac brew install redis 报错

    mac brew install redis 报错 /usr/local/opt/php55/bin/phpize /usr/local/opt/php55/bin/phpize: line 61: ...

  7. redis报错Windows error 0x70(a large memory)

    redis报错Windows error 0x70 redis 嫌弃你内存不够了,就给你不开第二个实例. The Windows version of Redis allocates a large ...

  8. redis 报错及解决

    报错: (error) MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persi ...

  9. filebeat output redis 报错 i/o timeout

    filebeat output  redis 报错 i/o timeout 先把报错内容贴出来. ERROR redis/client. go: Failed to RPUSH to redis li ...

  10. window下安装redis报错: creating server tcp listening socket 127.0.0.1:6379: bind No error

    window下安装redis报错: creating server tcp listening socket 127.0.0.1:6379: bind No error 解决: 如果没有配置环境,在安 ...

随机推荐

  1. OJ教程--递归

    弄清楚递归的基本思想,递归函数的运行过程,暂且不考虑是否使用递归在效率方面的差异. 题目 1: 数的组合问题.从1,2,-,n中取出m个数,将所有组合按照字典顺序列出.如n=3,m=2时,输出:12 ...

  2. 如何在 Spring Boot 优雅关闭加入一些自定义机制

    个人创作公约:本人声明创作的所有文章皆为自己原创,如果有参考任何文章的地方,会标注出来,如果有疏漏,欢迎大家批判.如果大家发现网上有抄袭本文章的,欢迎举报,并且积极向这个 github 仓库 提交 i ...

  3. Python:PIL(三)——Image

    学习自:PIL官方文档--Image (2条消息) Python图像处理PIL各模块详细介绍_章子雎的博客-CSDN博客 一.Image模块 1.open 用法 open(fp,mode='r',fo ...

  4. 在Intellij IDEA中添加JUnit单元测试

    Intellij IDEA中添加JUnit单元测试 目录 Intellij IDEA中添加JUnit单元测试 下载jar包 在Intellij IDEA项目中添加jar包 下载插件并进行设置 创建存放 ...

  5. 无法cin一个string 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换)

    头文件#include<string>不能写成#include<string.h>

  6. 浅谈cache

    2021.9.22更新: <浅谈Cache Memory> http://blog.sina.com.cn/s/blog_6472c4cc0102dusv.html 为什么贴上这个链接呢, ...

  7. JAVA Object类方法

    目录 Object类详解 一.==和equals的对比 1.1 ==是一个比较运算符 1.2 equals方法 二.hashCode方法 三.toString方法 四.finalize方法 Objec ...

  8. LeetCode-099-恢复二叉搜索树

    恢复二叉搜索树 题目描述:给你二叉搜索树的根节点 root ,该树中的两个节点被错误地交换.请在不改变其结构的情况下,恢复这棵树. 进阶:使用 O(n) 空间复杂度的解法很容易实现.你能想出一个只使用 ...

  9. linux作业--第十一周

    1. 导入hellodb.sql生成数据库 (1) 在students表中,查询年龄大于25岁,且为男性的同学的名字和年龄 (2) 以ClassID为分组依据,显示每组的平均年龄 (3) 显示第2题中 ...

  10. Laravel-手机短信验证码-阿里云

    1.composer require alibabacloud/client2.App\Service\AliyunSms.php <?php namespace App\Service; us ...