当前位置:首页 > redis > 正文内容

Redis设置密码

关中浪子1年前 (2023-02-07)redis639
【腾讯云】2核2G4M云服务器新老同享99元/年,续费同价
找梯子最重要的就是稳定,这个已经上线三年了,一直稳定没有被封过,赶紧下载备用吧!

一、设置方法:

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

 使用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      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


扫描二维码推送至手机访问。

版权声明:本文由码农翻生发布,如需转载请注明出处。

本文链接:https://lubojian.cn/post/191.html

分享给朋友:
返回列表

没有更早的文章了...

下一篇:reids 配置文件中重要参数说明

相关文章

reids 配置文件中重要参数说明

bind 127.0.0.1 -::1   注释掉此行,外网就可以访问了# 指定连接Redis的IP地址,本机的网卡IP地址或0.0.0.0protected-mode yes    设置为NO 外网...

Windows on Redis 中 设置 redis 密码

设置密码有两种方式。1. 命令行设置密码。运行cmd切换到redis根目录,先启动服务端>redis-server.exe另开一个cmd切换到redis根目录,启动客户端>redis-cli.exe -h 127.0.0.1 -...

redis主从中的Master自动选举之Sentinel哨兵机制

redis主从中的Master自动选举之Sentinel哨兵机制

一、什么是哨兵顾名思义,哨兵的作用就是监控Redis系统的运行状况,它的功能包括两个监控master和slave是否正常运行master出现故障时自动将slave数据库升级为master哨兵是一个独立的进程,使用哨兵后的架构如图所示,同时为...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。