1.查看当前密码设置,默认没有设置密码

[redis@t4-dtpoc-dameng-db-damengdb01-ma01 bin]$ ./redis-cli -h localhost -p 6379 CONFIG GET requirepass
1) "requirepass"
2) ""

2.设置密码
[redis@t4-dtpoc-dameng-db-damengdb01-ma01 bin]$ ./redis-cli -h localhost -p 6379 CONFIG SET requirepass "passw0rd"
OK
[redis@t4-dtpoc-dameng-db-damengdb01-ma01 bin]$ ./redis-cli -h localhost -p 6379 CONFIG GET requirepass
(error) NOAUTH Authentication required.

3.远程登录发现和本机登录发现设置已生效,不输入密码可以连接,但是无法获取key值。
远程:
10.153.244.17:6379> quit
-bash-4.2$ ./redis-cli -h 10.153.244.17 -p 6379
10.153.244.17:6379> get name
(error) NOAUTH Authentication required.
10.153.244.17:6379> quit
-bash-4.2$ ./redis-cli -h 10.153.244.17 -p 6379 -a 'passw0rd'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.153.244.17:6379> get name
"helloss"

本机:
[redis@t4-dtpoc-dameng-db-damengdb01-ma01 bin]$ ./redis-cli -h localhost -p 6379
localhost:6379> get name
(error) NOAUTH Authentication required.
localhost:6379> quit
[redis@t4-dtpoc-dameng-db-damengdb01-ma01 bin]$ ./redis-cli -h localhost -p 6379 -a passw0rd
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
localhost:6379> get name
"helloss"


3.重启redis,发现无法停下服务,原因是密码已生效,stop redis需要密码
[redis@t4-dtpoc-dameng-db-damengdb01-ma01 bin]$ service redis stop
Stopping ...
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...

https://blog.csdn.net/qq_30831935/article/details/94356584
安装这个网页的方法,在脚本里添加一行脚本即可
vi /etc/init.d/redis

$CLIEXEC -a "youpassword" -p $REDISPORT shutdown

发现可以stop了
[redis@t4-dtpoc-dameng-db-damengdb01-ma01 bin]$ service redis stop
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
AUTH failed: ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?
/home/redis/redis/logs/redis_6379.pid does not exist, process is not running


4.当然如果要密码常久生效,需要在配置文件里写入,否认下次redis重启后配置就会失效。
[redis@t4-dtpoc-dameng-db-damengdb01-ma01 conf]$ pwd
/home/redis/redis/conf
[redis@t4-dtpoc-dameng-db-damengdb01-ma01 conf]$ vi redis.conf

requirepass passw0rd

远程验证发现密码生效了

-bash-4.2$ ./redis-cli -h 10.153.244.17 -p 6379
10.153.244.17:6379> get name
(error) NOAUTH Authentication required.
10.153.244.17:6379> quit
-bash-4.2$ ./redis-cli -h 10.153.244.17 -p 6379 -a 'passw0rd'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.153.244.17:6379> get name
"helloss"

3.
[redis@t4-dtpoc-dameng-db-damengdb01-ma01 bin]$ ./redis-cli -h localhost -p 6379
localhost:6379>
localhost:6379> CONFIG GET requirepass
(error) NOAUTH Authentication required.
localhost:6379> quit

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐