Original link http://blog.csdn.net/zyz511919766/article/details/42268219
Redis Configuration Password
1. Configuring with configuration Files
The Yum-style installation of Redis profiles is typically in/etc/redis.conf, which opens the configuration file to find
[Plain]View Plaincopy
- #requirepass foobared
Remove the comment before the line, and change the password to the desired password, save the file
[Plain]View Plaincopy
- Requirepass Myredis
Restart Redis
[Plain]View Plaincopy
- sudo service Redis restart
- #或者
- sudo service Redis stop
- sudo redis-server/etc/redis.conf
This is the time to try to log in to Redis and find that it is possible to mount, but the specific command is prompt operation is not allowed
[Plain]View Plaincopy
- 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]>
Try to log in with a password and execute a specific command to see that it can be executed successfully
[Plain]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- 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. Configure through the command line
[Plain]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- 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"
Password invalidation without restarting Redis,redis reboot
Using the old password configured in the configuration file in the first step to sign in to Redis, you will find that the original password is not available and the operation is rejected
[Plain]View Plaincopy
- 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
Log in to Redis with the modified password to perform the appropriate action
[Plain]View Plaincopy
- 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
Try to restart Redis, log in to Redis with the newly configured password, discover that the new password is invalid, and Redis re-uses the password in the configuration file
[Plain]View Plaincopy
- 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"
In addition to setting a password with the-a parameter at login, you can log in without specifying a password and authenticate before performing the operation.
[Plain]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- 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 configured the password, slave how to configure
If master is configured with a password, slave must also configure the appropriate password parameters otherwise it will not be able to replicate normally.
Locate the following line in the config file in slave, remove the comment, and change the password
[Plain]View Plaincopy
- #masterauth Mstpassword
"Go" Redis Configuration authentication Password