1. Configure by configuration file
Yum Redis configuration files are typically installed in/etc/redis.conf, open the configuration file to find
Remove the comment before the line and change the password to the required password to save the file
Restart Redis
sudo service redis restart
#或者
sudo service redis stop
This time try to login Redis, found can be boarded, but the implementation of the specific command is prompted to operate not allowed
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
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. Configure from the command line
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"
No reboot Redis
Using the old password that is configured in the first step in the configuration file Redis, you will find that the original password is no longer available and the operation is denied
Redis-cli-h 127.0.0.1-p 6379-a myredis
redis 127.0.0.1:6379> config get requirepass
Log in Redis with the modified password to perform the appropriate action
Redis-cli-h 127.0.0.1-p 6379-a my_redis
redis 127.0.0.1:6379> config get requirepass
1) "Requirepass"
Try restarting the Redis, using the newly configured password login Redis to perform the operation, discover the new password is invalid, Redis reuse the password in the configuration file
sudo service redis restart
stopping redis-server: [OK]
starting redis-server: [OK]
redis-cli-h 1 27.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 "
In addition to making a password through the-a parameter at logon, you can also log on without specifying a password and authenticate before performing the operation.
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"
3.master configured with password, slave how to configure
If master is configured with a password, slave will also configure the corresponding password parameters, otherwise it will not be normal replication.
Find the following line in the slave configuration file, remove the comment, and modify the password