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
?
Remove the comment before the line, and change the password to the desired password, save the file
?
Restart Redis
?
1234 |
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
?
1234567 |
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
?
123456789 |
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
?
12345 |
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" |
No need to restart Redis
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
?
123 |
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
?
1234 |
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
?
12345678910 |
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.
?
12345678 |
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
?
1 |
#masterauth mstpassword |
Transferred from: http://www.2cto.com/database/201412/365757.html
Redis Configuration Authentication Password (RPM)