加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Redis设置密码

(2023-01-19 23:33:06)
分类: 其他

一、设置方法:
方法一:通过命令设置密码(临时生效,重启服务器后密码失效)

 使用redis-cli连接上redis,执行如下命令:

config set requirepass 123456

执行完毕,无需重启,退出客户端,重新登录就需要输入密码了
方法二:通过配置文件redis.conf设置密码(永久生效)

vi编辑器打开redis.conf

[root@localhost /]# vi /etc/redis.conf

输入/requirepass 找到requirepass关键字,后面跟的就是密码,默认是注释掉的,即不需要密码

    # The requirepass is not compatable with aclfile option and the ACL LOAD
    # command, these will cause requirepass to be ignored.
    #
    # requirepass foobared

注释打开,后面修改为自己的密码

    # The requirepass is not compatable with aclfile option and the ACL LOAD
    # command, these will cause requirepass to be ignored.
    #
     requirepass 123456

wq保存退出,重启服务器即可

二、连接方法:

1.连接时输入密码:

[root@localhost bin]# ./redis-cli -a 123456

2.先连接再输入密码:

    [root@localhost bin]# ./redis-cli
    127.0.0.1:6379> auth 123456

三、关闭方法:

[root@localhost bin]# ./redis-cli -a 123456 shutdown

 

重启后打开:

    [root@localhost etc]# cd /usr/local/bin
    [root@localhost bin]# redis-server /etc/redis.conf
    [root@localhost bin]# ps -ef|grep redis
    root       7650   7491  0 18:36 pts/1    00:00:00 /usr/local/bin/redis-cli
    root      12277      0 19:53 ?        00:00:00 redis-server 127.0.0.1:6379
    root      12295   7156  0 19:53 pts/0    00:00:00 grep --color=auto redis
    [root@localhost bin]# redis-cli
    127.0.0.1:6379> auth 123456
    OK


————————————————
版权声明:本文为CSDN博主「惜惜然」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_58746619/article/details/125865904

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有