Configure the authentication password for redis and the authentication password for redis
Redis Password Configuration
1. Configure through the configuration file
The redis configuration file installed in yum mode is usually in/etc/redis. conf. Open the configuration file and find
#requirepass foobared
Remove the comments in front of the line, change the password to the required password, and save the file.
requirepass myRedis
Restart redis
Sudo service redis restart # or sudo service redis stopsudo redis-server/etc/redis. conf
At this time, I tried to log on to redis and found that it could be mounted, but the specific command was prompted that the operation was not allowed.
redis-cli -h 127.0.0.1 -p 6379redis 127.0.0.1:6379>redis 127.0.0.1:6379> keys *(error) ERR operation not permittedredis 127.0.0.1:6379> select 1(error) ERR operation not permittedredis 127.0.0.1:6379[1]>
Log On with the password and run the specific command. The command is successfully executed.
redis-cli -h 127.0.0.1 -p 6379 -a myRedisredis 127.0.0.1:6379> keys *1) "myset"2) "mysortset"redis 127.0.0.1:6379> select 1OKredis 127.0.0.1:6379[1]> config get requirepass1) "requirepass"2) "myRedis"
2. Configure through command line
redis 127.0.0.1:6379[1]> config set requirepass my_redisOKredis 127.0.0.1:6379[1]> config get requirepass1) "requirepass"2) "my_redis"
No need to restart redis
Use the old password configured in the configuration file in step 1 to log on to redis. The original password is unavailable and the operation is rejected.
redis-cli -h 127.0.0.1 -p 6379 -a myRedisredis 127.0.0.1:6379> config get requirepass(error) ERR operation not permitted
Use the modified password to log on to redis and perform the corresponding operations.
redis-cli -h 127.0.0.1 -p 6379 -a my_redisredis 127.0.0.1:6379> config get requirepass1) "requirepass"2) "my_redis
Restart redis and log on to redis with the new password. The new password is invalid and redis uses the password in the configuration file again.
sudo service redis restartStopping redis-server: [ OK ]Starting redis-server: [ OK ]redis-cli -h 127.0.0.1 -p 6379 -a my_redisredis 127.0.0.1:6379> config get requirepass(error) ERR operation not permittedredis-cli -h 127.0.0.1 -p 6379 -a myRedisredis 127.0.0.1:6379> config get requirepass1) "requirepass"2) "myRedis"
In addition to setting a password through the-a parameter during logon, you can also authenticate the password before performing the operation without specifying a password during logon.
redis-cli -h 127.0.0.1 -p 6379redis 127.0.0.1:6379> config get requirepass(error) ERR operation not permittedredis 127.0.0.1:6379> auth myRedisOKredis 127.0.0.1:6379> config get requirepass1) "requirepass"2) "myRedis"
3. The master has configured the password and how to configure slave
If a password is configured for the master node, slave also needs to configure the corresponding Password parameters. Otherwise, the master node cannot be copied normally.
Find the following line in the configuration file of slave, remove the comment, and change the password.
#masterauth mstpassword