redis配置认证密码
Author:[email protected] Date:
1.通过配置文件进行配置
yum方式安装的redis配置文件通常在/etc/redis.conf中,打开配置文件找到
- #requirepass foobared
- requirepass myRedis
- sudo service redis restart
- #或者
- sudo service redis stop
- sudo redis-server /etc/redis.conf
- redis-cli -h 127.0.0.1 -p 6379
- redis 127.0.0.1:6379>
- redis 127.0.0.1:6379> keys *
- (error) ERR operation not permitted
- redis 127.0.0.1:6379> select 1
- (error) ERR operation not permitted
- redis 127.0.0.1:6379[1]>
- redis-cli -h 127.0.0.1 -p 6379 -a myRedis
- redis 127.0.0.1:6379> keys *
- 1) "myset"
- 2) "mysortset"
- redis 127.0.0.1:6379> select 1
- OK
- redis 127.0.0.1:6379[1]> config get requirepass
- 1) "requirepass"
- 2) "myRedis"
2.通过命令行进行配置
- redis 127.0.0.1:6379[1]> config set requirepass my_redis
- OK
- redis 127.0.0.1:6379[1]> config get requirepass
- 1) "requirepass"
- 2) "my_redis"
使用第一步中配置文件中配置的老密码登录redis,会发现原来的密码已不可用,操作被拒绝
- redis-cli -h 127.0.0.1 -p 6379 -a myRedis
- redis 127.0.0.1:6379> config get requirepass
- (error) ERR operation not permitted
- redis-cli -h 127.0.0.1 -p 6379 -a my_redis
- redis 127.0.0.1:6379> config get requirepass
- 1) "requirepass"
- 2) "my_redis
- sudo service redis restart
- Stopping redis-server: [ OK ]
- Starting redis-server: [ OK ]
- redis-cli -h 127.0.0.1 -p 6379 -a my_redis
- redis 127.0.0.1:6379> config get requirepass
- (error) ERR operation not permitted
- redis-cli -h 127.0.0.1 -p 6379 -a myRedis
- redis 127.0.0.1:6379> config get requirepass
- 1) "requirepass"
- 2) "myRedis"
除了在登录时通过 -a 参数制定密码外,还可以登录时不指定密码,而在执行操作前进行认证。
- redis-cli -h 127.0.0.1 -p 6379
- redis 127.0.0.1:6379> config get requirepass
- (error) ERR operation not permitted
- redis 127.0.0.1:6379> auth myRedis
- OK
- redis 127.0.0.1:6379> config get requirepass
- 1) "requirepass"
- 2) "myRedis"
3.master配置了密码,slave如何配置
slave中配置文件内找到如下行,移除注释,修改密码即可
- #masterauth mstpassword
转载本站文章《redis配置认证密码》,
请注明出处:https://www.zhoulujun.cn/html/DB/redis/287.html
上一篇:第一页
下一篇:大内存对redis未来发展的影响