时间:2021-07-01 10:21:17 帮助过:11人阅读
redis配置密码 1.通过配置文件进行配置 yum方式安装的redis配置文件通常在/etc/redis.conf中,打开配置文件找到 #requirepass foobared 去掉行前的注释,并修改密码为所需的密码,保存文件 requirepass myRedis 重启redis sudo service redis restart#或者sudo
redis配置密码#requirepass foobared去掉行前的注释,并修改密码为所需的密码,保存文件
requirepass myRedis重启redis
sudo service redis restart #或者 sudo service redis stop sudo redis-server /etc/redis.conf这个时候尝试登录redis,发现可以登上,但是执行具体命令是提示操作不允许
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.【本文来自鸿网互联 (http://www.68idc.cn)】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,可以执行相应操作
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尝试重启一下redis,用新配置的密码登录redis执行操作,发现新的密码失效,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"
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如何配置
#masterauth mstpassword