redis设置密码

该文详细介绍了如何进入Redis配置文件目录,检查是否设置密码,然后设置密码为test,关闭并重启Redis服务以应用更改,以及验证密码设置是否成功的过程。通过无密码尝试连接失败和使用密码成功连接展示了密码生效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#1、进入redis配置文件目录下
cd /home/test/redis_qiye/
[test@10 redis_qiye]$ ll
total 32
drwxr-xr-x 2 test test   137 Jun 27 17:59 bin
drwxr-xr-x 2 test test    32 Jun 28 14:09 data
-rwxrwxr-x 1 test test   471 Jun 27 17:59 load.sh
drwxr-xr-x 2 test test    33 Jun 27 17:59 logs
-rw-r--r-- 1 test test 25474 Jun 27 17:59 redis90.conf
#2、查看配置文件是否设置密码:无
[test@10 redis_qiye]$ cat redis90.conf|grep requirepass
# If the master is password protected (using the "requirepass" configuration
# requirepass foobared
#3、设置redis密码 test
[test@10 redis_qiye]$ vim redis90.conf
requirepass test
#4、查看当前redis进程,关闭进行重启
[test@10 redis_qiye]$ ps -ef|grep redis
test   14007     1  0 14:20 ?        00:00:00 ./bin/redis-server redis90.conf
test   14063 10369  0 14:21 pts/0    00:00:00 grep --color=auto redis
# 关闭,方式1 kill, 方式2 进入终端shutdown
[test@10 redis_qiye]$ kill -9 14007[test@10 redis_qiye]$ ./bin/redis-cli -h 127.0.0.1 -p 6390
redis 127.0.0.1:6390> shutdown
redis 127.0.0.1:6390> exit
# 查看密码是否已设置,进行重启
[test@10 redis_qiye]$ ps -ef|grep redis
test   14143 10369  0 14:22 pts/0    00:00:00 grep --color=auto redis
[test@10 redis_qiye]$ cat redis90.conf |grep requirepass
# If the master is password protected (using the "requirepass" configuration
# requirepass foobared
requirepass test
#启动redis
[test@10 redis_qiye]$ ./bin/redis-server redis90.conf
[test@10 redis_qiye]$ ps -ef|grep redis
test   14709     1  0 14:25 ?        00:00:00 ./bin/redis-server redis90.conf
test   14715 10369  0 14:25 pts/0    00:00:00 grep --color=auto redis
#测试密码是否生效
#1.无密码进入,服务不可用
[test@10 redis_qiye]$ ./bin/redis-cli -h 127.0.0.1 -p 6390
redis 127.0.0.1:6390> keys *
(error) ERR operation not permitted
#2.输入密码进入,服务可用
[test@10 redis_qiye]$  ./bin/redis-cli -h 127.0.0.1 -p 6390 -a test
redis 127.0.0.1:6390> set test_name test
OK

参考资料:https://cloud.tencent.com/developer/article/2133116?from=15425

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值