redis password settings

Reprinted from: http://blog.csdn.net/lxpbs8851/article/details/8136126

 

1. How to initialize the password of redis?

2 steps in total:

a. There is a parameter in the configuration file: requirepass This is the parameter for configuring the redis access password.

For example requirepass test123

b. For the parameters in the configuration file to take effect, you need to restart and restart redis.

 

2. How to configure the password without restarting redis?

a. Configure the password of requirepass in the configuration file (the password will still be valid when redis is restarted).

# requirepass foobared is
modified to:

requirepass test123

 

b. Enter redis to redefine parameters

View current password:

[root@slaver251 redis-2.4.16]# ./src/redis-cli -p 6379
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> config get requirepass
1) "requirepass"
2) (nil)

shows that the password is empty,

Then set the password:

redis 127.0.0.1:6379> config set requirepass test123
OK

Query the password again:

redis 127.0.0.1:6379> config get requirepass
(error) ERR operation not permitted

It's wrong at this time!

Now only password authentication is required.

redis 127.0.0.1:6379> auth test123
OK

Query the password again:

redis 127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "test123"

The password has been changed.

When it is time to restart redis, the password will automatically take effect because the configuration parameters have been modified.

If the configuration parameter does not add a password, then the redis restart password will be equivalent to no setting.

 

3. How to log in to redis with a password ?

a. Enter the password when logging in

[root@slaver251 redis-2.4.16]# ./src/redis-cli -p 6379 -a test123
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "test123"

 

b. Login first and then verify:

[root@slaver251 redis-2.4.16]# ./src/redis-cli -p 6379
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> auth test123
OK
redis 127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "test123"
redis 127.0.0.1:6379>

 

4. The master has a password, how to configure the slave?

When the master has a password, when configuring the slave, the corresponding password parameters must also be configured accordingly. Otherwise, the slave cannot perform normal replication.

The corresponding parameters are:

#masterauth

for example:

masterauth mstpassword

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326472167&siteId=291194637