美文网首页
redis - 第三节:保护模式配置

redis - 第三节:保护模式配置

作者: 会煮咖啡的猫咪 | 来源:发表于2016-12-07 14:55 被阅读2639次

保护模式下非本地连接不能访问

问题还原

我是一台机器做redis服务,一台机器当客户端连接

redis server : 10.211.55.8:6379

  • 启动服务
$ redis-server ./redis.conf

redis.conf是官方安装默认的文件

  • 客户端

输入

$ redis-cli -h 10.211.55.8 -p 6379
10.211.55.8> set key:01 val123456

返回

(error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

不带换行的错误提示,我们耐心看下,无非就是告诉我们当前是保护模式,有几个解决方案。

方案一:绑定服务器ip

$ vi ./redis.conf

......

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
bind 10.211.55.8

加入配置 bind 10.211.55.8

方案二:修改保护模式 protected-mode

$ vi ./redis.conf

......

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no

设置 protected-mode no

方案三:设置口令(推荐)

$ vi ./redis.conf

......

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass 123456789
  • 客户端
$ auth 123456789
OK
$ set key:01 val123456
OK
$ get key:01
"val123456"

我的博客

相关文章

  • redis入侵防范笔记!

    打开保护模式redis默认开启保护模式。要是配置里没有指定bind和密码,开启该参数后,redis只能本地访问,拒...

  • redis去掉保护模式

    出现这种错误时,需要修改redis的配置,观点保护模式: 修改以后重启redis-server

  • redis - 第三节:保护模式配置

    保护模式下非本地连接不能访问 问题还原 我是一台机器做redis服务,一台机器当客户端连接 redis serve...

  • redis设置远程连接

    redis任何版本都支持远程连接,前期版本里没有增加redis保护模式,bind ip即可,redis3后新增了保...

  • redis保护模式引起的问题 --- 2020-03-18

    引起以下图中出现的问题是redis开启了保护模式导致的,现在我们关闭保护模式就可以了,可能有人说我关闭了保护模式啊...

  • redis.conf详解之protected-mode

    用法 打开保护模式 关闭保护模式 用途 保护你的redis实例,防止被访问和利用。大白话:只有本地能操作这个实例,...

  • Redis保护模式配置引起的问题

    新项目搭建了个新的测试服务器,但是项目发布上去以后Redis一直不好用,查看日志后发现在getResource时报...

  • springboot 2.x整合redis

    引入redis依赖 设置连接redis的配置 Redis配置 配置redis连接 开始使用

  • redis配置和安装

    学习目标 了解Redis的配置 查看所有配置信息 配置 Redis的配置信息在 /etc/redis/redis....

  • redis配置文件

    redis配置文件中存储单位说明 redis常用配置说明 redis安全配置 在配置文件中设置密码 在redis-...

网友评论

      本文标题:redis - 第三节:保护模式配置

      本文链接:https://www.haomeiwen.com/subject/epgdmttx.html