在 Linux 上安装 Redis Stack

如何在 Linux 上安装 Redis Stack

Redis Open Source

了解如何从官方 APT 仓库或 RPM 源,或者使用 Snap 或 AppImage 在 Linux 上安装 Redis Stack。

从官方 Ubuntu/Debian APT 仓库安装

有关支持的 Ubuntu/Debian 平台的完整列表,请参阅此页面。将仓库添加到 APT 索引,更新它,然后安装 Redis Stack

sudo apt-get install lsb-release curl gpg
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 rhel9 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 实例,您可能希望

评价此页面
返回顶部 ↑