2.2. /etc/redis.conf
打开 /etc/redis.conf 修改 requirepass 配置项
# vim /etc/redis.conf requirepass test123
测试
# service redis restart Stopping redis-server: [ OK ] Starting redis-server: [ OK ] # redis-cli redis 127.0.0.1:6379> set h helloworld (error) ERR operation not permitted
auth test123
redis 127.0.0.1:6379> auth test123 OK redis 127.0.0.1:6379> set h helloworld OK redis 127.0.0.1:6379> get h "helloworld" redis 127.0.0.1:6379> exit
redis-cli -a 参数指定密码
# redis-cli -a test123 redis 127.0.0.1:6379> set h helloworld OK redis 127.0.0.1:6379> get h "helloworld" redis 127.0.0.1:6379> exit
通过 config 动态改变密码,无需重新启动 redis 进程
# redis-cli -a test123 redis 127.0.0.1:6379> config get requirepass 1) "requirepass" 2) "test123" redis 127.0.0.1:6379> config set requirepass passabc OK redis 127.0.0.1:6379> auth passabc OK redis 127.0.0.1:6379> set h helloworld OK redis 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 foobared requirepass test123
master/slave 模式, master 有密码, slave 怎样配置?
masterauth password