安装

Windows

Github下载地址:https://github.com/MicrosoftArchive/redis/releases

下载对应的.msi版本安装即可

Linux

  1. centos7使用yum安装Redis时,可能会有安装源的问题出现

    安装epel源,CentOS默认的安装源在官方的centos.org上,而redis在第三方的yum源里,因此无法安装。这就是我们常常在yum源里找不到各种软件的原因,还需要自己去wget,然后configure,make,make install,这个过程太痛苦了,并且卸载软件的时候还容易出错

  2. 非官方的yum推荐用fedora的epel仓库
    yum添加epel源的命令为:yum install epel-release然后回车

1
2
3
4
5
6
yum install epel-release

yum install redis

systemctl start redis
systemctl enable redis

Docker

1
2
3
4
5
# 不设置密码(没法通过 "docker update ..." 追加密码)
docker run -d --name redis -p 6379:6379 redis

# 设置密码
docker run -d --name redis -p 6379:6379 redis --requirepass "123456"

设置(重置)密码

输入Redis命令:会提示(error) NOAUTH Authentication required. 这是属于正常现象。

我们输入:auth 123456

再次输入Redis命令即可正常使用

Windows

  1. 找到Redis安装目录,打开redis.windows.confredis.windows-service.conf并找到# requirepass foobared这一行,在这一行下面增加一行requirepass 你的密码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ################################## 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 123456
  2. 保存,重启Redis服务

Linux

  1. 编辑文件/etc/redis.conf

    1
    2
    3
    4
    vi /etc/redis.conf

    # requirepass foobared下一行加上以下内容:
    requirepass 123456

    效果如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ################################## 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 123456
  2. 保存,重启Redis服务

    1
    systemctl restart redis

Docker

1
docker run -d --name redis -p 6379:6379 redis --requirepass "123456"