本文共 1216 字,大约阅读时间需要 4 分钟。
打开 /etc/redis.conf 修改 requirepass 配置项
# vim /etc/redis.confrequirepass test123
测试
# service redis restartStopping redis-server: [ OK ]Starting redis-server: [ OK ]# redis-cliredis 127.0.0.1:6379> set h helloworld(error) ERR operation not permitted
auth test123
redis 127.0.0.1:6379> auth test123OKredis 127.0.0.1:6379> set h helloworldOKredis 127.0.0.1:6379> get h"helloworld"redis 127.0.0.1:6379> exit
redis-cli -a 参数指定密码
# redis-cli -a test123redis 127.0.0.1:6379> set h helloworldOKredis 127.0.0.1:6379> get h"helloworld"redis 127.0.0.1:6379> exit
通过 config 动态改变密码,无需重新启动 redis 进程
# redis-cli -a test123redis 127.0.0.1:6379> config get requirepass1) "requirepass"2) "test123"redis 127.0.0.1:6379> config set requirepass passabcOKredis 127.0.0.1:6379> auth passabcOKredis 127.0.0.1:6379> set h helloworldOKredis 127.0.0.1:6379> get h"helloworld"redis 127.0.0.1:6379> exit
注意:config 不能保存到配置文件
# grep requirepass /etc/redis.conf# If the master is password protected (using the "requirepass" configuration# requirepass foobaredrequirepass test123
master/slave 模式, master 有密码, slave 怎样配置?
masterauth password
转载地址:http://jafco.baihongyu.com/