在 Linux 上安装 Redis Stack

如何在 Linux 上安装 Redis Stack

了解如何从官方 APT 存储库或 RPM 提要安装 Redis Stack,或使用 Snap 或 AppImage 安装。

从官方 Ubuntu/Debian APT 存储库

查看 此页面,了解支持的 Ubuntu/Debian 平台的完整列表。将存储库添加到 apt 索引中,更新它并安装 Redis Stack

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis-stack-server

Redis 不会自动启动,也不会在启动时启动。为此,请运行以下命令。

sudo systemctl enable redis-stack-server
sudo systemctl start redis-stack-server

从官方 Red Hat/Rocky RPM 提要

查看 此页面,了解支持的 Red Hat/Rocky 平台的完整列表。请按照以下步骤安装 Redis Stack。

  1. 使用以下内容创建文件 /etc/yum.repos.d/redis.repo

    [Redis]
    name=Redis
    baseurl=http://packages.redis.io/rpm/rhel9 # replace rhel7 with the appropriate value for your platform
    enabled=1
    gpgcheck=1
  2. 运行以下命令

    curl -fsSL https://packages.redis.io/gpg > /tmp/redis.key
    sudo rpm --import /tmp/redis.key
    sudo yum install epel-release
    sudo yum install redis-stack-server

Redis 不会自动启动,也不会在启动时启动。为此,请运行以下命令。

sudo systemctl enable redis-stack-server
sudo systemctl start redis-stack-server

在使用 Snap 的 Ubuntu 上

首先,从 此页面下载最新的 Redis Stack snap 包。

要安装,请运行

sudo apt update
sudo apt install redis-tools
sudo snap install --dangerous --classic <snapname.snap>

Redis 不会自动启动,也不会在启动时启动。要启动前台的 redis-stack-server,请运行以下命令

sudo snap run redis-stack-server

要停止 Redis,请按 Ctrl-C

请按照以下步骤将 Redis Stack 与 systemd 集成,以便您可以在后台启动/停止

  1. 编辑/etc/systemd/system/redis-stack-server.service 文件并输入以下信息

    [Unit]
    Description=Redis Stack Server
    After=network.target
    
    [Service]
    ExecStart=/usr/bin/snap run redis-stack-server
    Restart=always
    User=root
    Group=root
    
    [Install]
    WantedBy=multi-user.target
  2. 运行以下命令。

    sudo systemctl daemon-reload
    sudo systemctl start redis-stack-server
    sudo systemctl enable redis-stack-server

如果您的 Linux 发行版当前没有安装 Snap,您可以使用 这里 描述的说明进行安装。然后,从 下载页面 下载相应的软件。

在带有 AppImage 的 Ubuntu 上

在继续之前,需要安装 Fuse。按如下方式安装。

sudo apt update
sudo apt install fuse

接下来,从 此页面 下载最新的 Redis Stack AppImage 包。

要运行镜像,请执行以下命令

sudo apt update
sudo apt install redis-tools
chmod a+x <AppImageFile> # replace AppImageFile with the name of your downloaded file
./<AppImageFile>

这将在前台启动 Redis。要停止 Redis,请输入 Ctrl-C

请按照以下步骤将 Redis Stack 与 systemd 集成,以便您可以在后台启动/停止

  1. 编辑/etc/systemd/system/redis-appimage.service 文件并输入以下信息

    [Unit]
    Description=Redis Server (AppImage)
    After=network.target
    
    [Service]
    ExecStart=/path/to/your/<AppImageFile> --daemonize no
    Restart=always
    User=redis-user   # replace with an existing user or create a new one
    Group=redis-group # replace with an existing group or create a new one
    
    [Install]
    WantedBy=multi-user.target
  2. 运行以下命令。

    sudo systemctl daemon-reload
    sudo systemctl start redis-appimage
    sudo systemctl enable redis-appimage

在后台启动和停止 Redis Stack

您可以使用 systemctl 命令将 Redis 服务器作为后台进程启动。这仅适用于使用 apt 安装的 Ubuntu/Debian 以及使用 yum 安装的 Red Hat/Rocky。

sudo systemctl start redis-stack-server

要停止服务,请使用

sudo systemctl stop redis-stack-server

连接到 Redis

Redis 运行后,您可以通过运行 redis-cli 来测试它

redis-cli

使用 ping 命令测试连接

127.0.0.1:6379> ping
PONG

您还可以使用 Redis Insight 测试 Redis 服务器是否正在运行。

下一步

拥有运行的 Redis 实例后,您可能需要

RATE THIS PAGE
Back to top ↑