Home >Database >Redis >Introduction to redis password management

Introduction to redis password management

尚
forward
2020-03-20 09:50:092110browse

Introduction to redis password management

1. How to initialize the redis password?

A total of 2 steps:

a. There is a parameter in the configuration file: requirepass This is the parameter to configure the redis access password.

For example, requirepass test123

b. To take effect, the parameters in the configuration file need to be restarted and redis restarted.

Recommended: redis introductory tutorial

2. How to configure the password without restarting redis?

a. In the configuration file Configure the password for requirepass (the password is still valid when redis is restarted).

# requirepass foobared

For example, change it to:

requirepass  test123

b. Enter the redis redefinition parameter

to view the 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
 "requirepass"
 (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

An error is reported 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
 "requirepass"
"test123"

The password has been changed.

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

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

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

a. When logging in, enter the password

[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
 "requirepass"
 "test123"

b. Log in 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
"requirepass"
"test123"
redis 127.0.0.1:6379>

4. Master has a password, how about slave? Configuration?

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

The corresponding parameters are:

#masterauth

For example:

masterauth  mstpassword

Related recommendations:

mysql video tutorial: https:// m.sbmmt.com/course/list/51.html

The above is the detailed content of Introduction to redis password management. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete