Redis设置密码
一、设置方法:
方法一:通过命令设置密码(临时生效,重启服务器后密码失效)
使用redis-cli连接上redis,执行如下命令:
1 | config set requirepass 123456 |
执行完毕,无需重启,退出客户端,重新登录就需要输入密码了
方法二:通过配置文件redis.conf设置密码(永久生效)
vi编辑器打开redis.conf
1 | [root @localhost /]# vi /etc/redis.conf |
输入/requirepass 找到requirepass关键字,后面跟的就是密码,默认是注释掉的,即不需要密码
1 2 3 4 | # The requirepass is not compatable with aclfile option and the ACL LOAD # command, these will cause requirepass to be ignored. # # requirepass foobared |
注释打开,后面修改为自己的密码
1 2 3 4 | # The requirepass is not compatable with aclfile option and the ACL LOAD # command, these will cause requirepass to be ignored. # requirepass 123456 |
wq保存退出,重启服务器即可
二、连接方法:
1.连接时输入密码:
1 | [root @localhost bin]# ./redis-cli -a 123456 |
2.先连接再输入密码:
1 2 | [root @localhost bin]# ./redis-cli 127.0 . 0.1 : 6379 > auth 123456 |
三、关闭方法:
1 | [root @localhost bin]# ./redis-cli -a 123456 shutdown |
重启后打开:
1 2 3 4 5 6 7 8 | [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 1 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 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通