Redis 高危命令禁用 您所在的位置:网站首页 redis的flushdb Redis 高危命令禁用

Redis 高危命令禁用

#Redis 高危命令禁用| 来源: 网络整理| 查看: 265

使用公司已有 redis 环境时才发现没有 config 命令。经了解才知道被禁用了。 1、对于一些 redis 的高危命令,建议做禁用处理 如: flushdb:清空数据库 flushall:清空所有数据 config:可以使用命令修改配置信息 keys:可以查看所有 key 的值 禁用的做法是,通过修改配置文件*/redis.conf 文件。实质是修改了命令的名字为其他名字,以防不熟悉的使用者误用或者其他人恶意使用。 命令如下:

rename-command FLUSHALL delflushall rename-command CONFIG conf

在*/redis.conf文件中增加以上内容即可,如下图: 在这里插入图片描述

2、修改 redis.conf 文件后,重启后生效

127.0.0.1:6379> flushall (error) ERR unknown command ‘flushall’ #提示命令不存在 127.0.0.1:6379> delflushall OK 127.0.0.1:6379> keys * (empty list or set) #已清空所有数据 127.0.0.1:6379> conf set slowlog-log-slower-than 1000 OK # conf 命令也正常执行 127.0.0.1:6379>

Tips: flushall 命令已经不存在,delflushall 和 conf正常生效。

3、关于重启 redis 1.在命令行执行,shutdown

127.0.0.1:6379> shutdown save not connected>

Tips: save|nosave,是 shutdown 命令的可选修饰符; A. 执行 SHUTDOWN SAVE 会强制让数据库执行保存操作,即使没有设定(configure)保存点 B. 执行 SHUTDOWN NOSAVE 会阻止数据库执行保存操作,即使已经设定有一个或多个保存点(你可以将这一用法看作是强制停止服务器的一个假想的 ABORT 命令) C. 执行成功自动断开连接。执行失败报错。

2.使用 redis 的客户端工具redis-cli

[root@localhost redis-4.0.10]# ./redis-cli shutdown

Tips: 如果设置了密码,则使用如下命令:

[root@localhost src]# ./redis-cli -a ‘redis1’ shutdown Warning: Using a password with ‘-a’ option on the command line interface may not be safe. [root@localhost src]# [root@localhost src]# [root@localhostsrc]# ps -ef|grep redis root 41210 41142 0 16:18 pts/2 00:00:00 ./redis-cli -c -h 127.0.0.1 root 45656 28981 0 17:38 pts/1 00:00:00 ./redis-cli -c -h 127.0.0.1 -a redis1 root 47810 41233 0 18:17 pts/4 00:00:00 grep --color=auto redis

3、使用系统命令,kill 进程

[root@localhost redis-4.0.10]# ps -ef|grep redis root 41210 41142 0 16:18 pts/2 00:00:00 ./redis-cli -c -h 127.0.0.1 root 45648 1 0 17:38 ? 00:00:02 ./redis-server 192.168.225.131:6379 root 45656 28981 0 17:38 pts/1 00:00:00 ./redis-cli -c -h 127.0.0.1 -a redis1 root 47683 41233 0 18:15 pts/4 00:00:00 grep --color=auto redis [root@localhost redis-4.0.10]#kill 45648

Tips: Kill -9 也是可以的,因为Redis可以妥善处理SIGTERM信号。

4.启动 redis

[root@localhost src]# ./redis-server …/redis.conf [root@localhost src]# ps -ef|grep redis root 41210 41142 0 16:18 pts/2 00:00:00 ./redis-cli -c -h 127.0.0.1 root 45656 28981 0 17:38 pts/1 00:00:00 ./redis-cli -c -h 127.0.0.1 -a redis1 root 48153 1 0 18:24 ? 00:00:00 ./redis-server 192.168.225.131:6379 root 48160 41233 0 18:24 pts/4 00:00:00 grep --color=auto redis [root@localhost src]#



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有