打赏

Windows里如何正确安装Redis以服务运行(博主推荐)(图文详解)

 

 

 

    不多说,直接上干货!

 

  

  注意 : Redis官方并没有提供Redis的windows安装包,但在github上, 有相关的下载地址
 
 
 

 

 

一、Redis的下载地址
  相关的下载地址,如下:

 

 

  
         redis-64.3.0.503.zip(64位的win系统,redis 3.0版本)。

 

 

 

 

 

 

 

二、Redis的安装和配置
  找到下载的压缩包 redis-64.3.0.503.zip,解压后,重命名为Redis-3.0,置于某个文件夹下(如D:\SoftWare\Redis-3.0)。

 

 

 

 

 

  再删除redis-64.3.0.503.zip

   

 

 

 

 

 

 

 

 

 

 

 

1、运行Redis服务器端
  直接双击D:\SoftWare\Redis-3.0目录下的redis-server.exe文件(redis服务器端),就会以窗口的形式运行Redis服务器(但该窗口不可关闭,否则,Redis服务不可用)。此种运行redis服务器的方式,没有加载指定的配置文件。

 

 

 

 

[94000] 13 Mar 22:21:48.115 # Warning: no config file specified, using the default config. In order to specify a config file use D:\SoftWare\Redis-3.0\redis-server.exe /path/to/redis.conf
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.0.503 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 94000
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

[94000] 13 Mar 22:21:48.120 # Server started, Redis version 3.0.503
[94000] 13 Mar 22:21:48.120 * The server is now ready to accept connections on port 6379

 

 

 

 

 

 

 

 

 

 

 

2. 运行Redis客户端
  直接双击D:\SoftWare\Redis-3.0目录下的redis-cli.exe文件(redis客户端),如果显示127.0.0.1:6379> ,就说明客户端运行成功。

 

 
 
127.0.0.1:6379>

 

 

   然后,
 
  接着输入命令: keys *
  上述的意思是,查看所有的键
 
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379>

  默认安装Redis的密码是为空的。

 

 

   所以,我们需要在此步进行密码的设置。 即Redis如何添加key的问题。当然你也可以在这个shell里来操作,但是一般我们喜欢如下:

  因为我们的操作系统大部分还是使用的windows,所以在开发的时候,基本上是用windows下的redis。通过启动redis-server.exe来启动。

  redis默认是空密码,但是这样在项目上线后是不安全的,容易被入侵,所以要设置密码。

    1、打开redis.windows.conf文件,找到# requirepass foobared 这行,在此行下增加一行requirepass 所设置的密码 ,保存。

 

    

 

 

 · 这个密码123456随大家自定义,我这里设置如下

# requirepass foobared
requirepass 123456    //此处注意,行前不能有空格

 

 

    2、打开cmd(windows命令窗口),切换到redis-server.exe目录下。

 

 

 

 

    3、输入命令:redis-server.exe  redis.windows.conf启动redis,即可使用密码了。

Microsoft Windows [版本 10.0.16299.125]
(c) 2017 Microsoft Corporation。保留所有权利。

C:\Users\lenovo>cd /d D:

D:\>cd D:\SoftWare\Redis-3.0

D:\SoftWare\Redis-3.0>redis-server.exe  redis.windows.conf
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.0.503 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 57812
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

[57812] 13 Mar 22:50:43.330 # Server started, Redis version 3.0.503
[57812] 13 Mar 22:50:43.333 * The server is now ready to accept connections on port 6379

 

  注意,如果不是用命令窗口,而是直接点击redis-server.exe启动redis,密码不会生效,因为此文件默认加载的是内置的配置文件,必须指定我们设置好的配置文件,密码才会生效。

 

 

 

 

 
 
   4、双击redis-cli.exe,然后,输入auth 123456,会报如下的错误

    连接redis报此错误:ERR Client sent AUTH, but no password is set

 
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> auth 123456
(error) ERR Client sent AUTH, but no password is set
127.0.0.1:6379> CONFIG SET requirepass "123456"
OK
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379>
  输入命令: auth 123456
  如果提示OK,就说明密码正确。
  
 
   此时,你可以把redis-cli.exe关闭,再双击打开,输入如下,肯定正确了,以后就不需担心了。

 

 
 
 

 

3、 将Redis服务安装到本地服务
    由于上述启动Redis服务器的方式有点复杂,且redis服务窗口不可关闭。
    故这里介绍如何将Redis服务安装到Windows系统的本地服务。
 
  此时D:\SoftWare\Redis-3.0目录下的redis.windows.conf文件,来作为redis的配置文件。
    打开一个cmd 窗口(管理员身份运行),使用cd命令切换目录到自己解压后文件夹的目录中(如:我的是D:\SoftWare\Redis-3.0)
  依次输入下列命令:
C:\Users\lenovo>cd /d D:

D:\>cd D:\SoftWare\Redis-3.0

D:\SoftWare\Redis-3.0>redis-server --service-install redis.windows.conf --loglevel verbose
[6660] 13 Mar 23:04:16.850 # Granting read/write access to 'NT AUTHORITY\NetworkService' on: "D:\SoftWare\Redis-3.0" "D:\SoftWare\Redis-3.0\"
[6660] 13 Mar 23:04:16.850 # Redis successfully installed as a service.

D:\SoftWare\Redis-3.0>
  redis-server --service-install redis.conf --loglevel verbose 的意思是安装redis本地服务,指定配置文件redis.windows.conf
 
 
 
  操作完成后,就可以到win系统的本地服务管理处,查看和操作Redis服务。(计算机图标右键 -> 管理) -> 服务和应用程序 -> 服务)

     或者,打开cmd窗口输入services.msc,Redis出现在服务中,自行启动该服务。

 

 

 

 

 

 

 

 

4. 如何卸载Redis本地服务
  打开win系统命令行,依次输入下列命令:
C:\Users\lenovo>cd /d D:

D:\>cd D:\SoftWare\Redis-3.0

D:\SoftWare\Redis-3.0> redis-server --service-uninstall
    就可将Redis本地服务卸载。
 
 
 
 
 
 
 
 
 
 
欢迎大家,加入我的微信公众号:大数据躺过的坑        人工智能躺过的坑
 
 
 

同时,大家可以关注我的个人博客

   http://www.cnblogs.com/zlslch/   和     http://www.cnblogs.com/lchzls/      http://www.cnblogs.com/sunnyDream/   

   详情请见:http://www.cnblogs.com/zlslch/p/7473861.html

 

  人生苦短,我愿分享。本公众号将秉持活到老学到老学习无休止的交流分享开源精神,汇聚于互联网和个人学习工作的精华干货知识,一切来于互联网,反馈回互联网。
  目前研究领域:大数据、机器学习、深度学习、人工智能、数据挖掘、数据分析。 语言涉及:Java、Scala、Python、Shell、Linux等 。同时还涉及平常所使用的手机、电脑和互联网上的使用技巧、问题和实用软件。 只要你一直关注和呆在群里,每天必须有收获

 

      对应本平台的讨论和答疑QQ群:大数据和人工智能躺过的坑(总群)(161156071) 

 

 

 

 

 

 

 

 

 

 

 

 

 
 

 

posted @ 2018-03-13 22:11  大数据和AI躺过的坑  阅读(2976)  评论(0编辑  收藏  举报