909422229_在windows上安装redis并设置密码,IP绑定【提供安装包】

来源:互联网 发布:高拱 知乎 编辑:程序博客网 时间:2024/06/12 10:47

先说废话。

Redis  是一个开源,先进的存储,并用于构建高性能,可扩展的 Web  应用程序的完美解决方案。

Redis  从它的许多竞争继承来的三个主要特点:

  1. Redis  数据库完全在内存中,使用磁盘仅用于持久性。
  2. 相比许多键值数据存储, Redis  拥有一套较为丰富的数据类型。
  3. Redis  可以将数据复制到任意数量的从服务器。

一、下载及安装Redis

首先下载,下载方式:

  1. 从 github  下载:https://github.com/MSOpenTech/redis/releases
  2. 从本站国内 CDN  节点下载:本文下方【附件】下载即可。

github   Windows  版本下载


下载后的文件为:Redis-x64-2.8.2400.zip,然后解压缩后如下图:

二、设置密码

    上次我们出现过一次大规模的Redis安全事件,给我们敲响了警钟,因为我们好多项目都是图方便,很少设置密码,而Redis的默认配置又是没有密码,导致基本都是没有设置密码。

    Redis设置密码有2个办法。

 1.修改配置文件。

   在刚刚解压的目录下,我们能够找到文件名为:redis.windows-service.conf

打开后用Ctrl + F查找:requirepass

  1. ################################## SECURITY ###################################
  2. # Require clients to issue AUTH before processing any other
  3. # commands. This might be useful in environments in which you do not trust
  4. # others with access to the host running redis-server.
  5. #
  6. # This should stay commented out for backward compatibility and because most
  7. # people do not need auth (e.g. they run their own servers).
  8. #
  9. # Warning: since Redis is pretty fast an outside user can try up to
  10. # 150k passwords per second against a good box. This means that you should
  11. # use a very strong password otherwise it will be very easy to break.
  12. requirepass <你的密码>
  13. # Command renaming.
  14. #
  15. # It is possible to change the name of dangerous commands in a shared
  16. # environment. For instance the CONFIG command may be renamed into something
  17. # hard to guess so that it will still be available for internal-use tools
  18. # but not available for general clients.
  19. #
  20. # Example:
  21. #
  22. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
  23. #
  24. # It is also possible to completely kill a command by renaming it into
  25. # an empty string:
  26. #
  27. # rename-command CONFIG ""
  28. #
  29. # Please note that changing the name of commands that are logged into the
  30. # AOF file or transmitted to slaves may cause problems.

比如我把密码设置为:asdfklfjfasdklfjasdklfjweruoweri。

那么就修改成这样:

  1. requirepass asdfklfjfasdklfjasdklfjweruoweri

然后重启即可。

2.配置临时密码。

也就是启动后在控制台redis-cli.exe配置,但这种极其不推荐。所以也不说了。

PS:密码尽量设置复杂一点。

3.IP绑定

Ip绑定还是在redis.windows-service.conf配置文件里。

Ctrl + F搜索127.0.0.1能找到如下所示:

  1. # By default Redis listens for connections from all the network interfaces
  2. # available on the server. It is possible to listen to just one or multiple
  3. # interfaces using the "bind" configuration directive, followed by one or
  4. # more IP addresses.
  5. #
  6. # Examples:
  7. #
  8. # bind 192.168.1.100 10.0.0.1
  9. # bind 127.0.0.1

支持这2种 IP 绑定,我们一般就绑定内网,默认是内网外网都可以访问。所以我们从安全的角度考虑,如果是本机使用就绑定 127.0.0.1 ,如果是局域网内使用请绑定本地 IP ,如:192.168.0.8等。

如果本文对你有帮助,那么请你赞助我,让我更有激情的写下去,帮助更多的人。

原创粉丝点击