在 AlmaLinux/Rocky Linux 9.5 上构建并运行 Redis 开源版

Redis 开源版

按照以下步骤,在运行 AlmaLinux 和 Rocky Linux 9.5 的系统上从源代码构建并运行 Redis 开源版。

注意

用于生成这些构建说明的 Docker 镜像

  • AlmaLinux
    • almalinux:9.5
    • almalinux:9.5-minimal
  • Rocky Linux
    • rockylinux/rockylinux:9.5
    • rockylinux/rockylinux:9.5-minimal

1. 准备系统

注意

对于 9.5-minimal,你需要按如下方式安装 sudodnf

microdnf install dnf sudo -y

对于 9.5 (标准版),你需要按如下方式安装 sudo

dnf install sudo -y

启用 GoReleaser 仓库并安装所需的软件包

sudo tee /etc/yum.repos.d/goreleaser.repo > /dev/null <<EOF
[goreleaser]
name=GoReleaser
baseurl=https://repo.goreleaser.com/yum/
enabled=1
gpgcheck=0
EOF

sudo dnf clean all
sudo dnf makecache
sudo dnf update -y

2. 安装所需的软件包

安装构建依赖、GCC 工具链、Python 和实用程序

sudo dnf install -y --nobest --skip-broken \
    pkg-config \
    xz \
    wget \
    which \
    gcc-toolset-13-gcc \
    gcc-toolset-13-gcc-c++ \
    git \
    make \
    openssl \
    openssl-devel \
    python3 \
    python3-pip \
    python3-devel \
    unzip \
    rsync \
    clang \
    curl \
    libtool \
    automake \
    autoconf \
    jq \
    systemd-devel

创建 Python 虚拟环境

python3 -m venv /opt/venv

启用 GCC 工具链

sudo cp /opt/rh/gcc-toolset-13/enable /etc/profile.d/gcc-toolset-13.sh
echo "source /etc/profile.d/gcc-toolset-13.sh" | sudo tee -a /etc/bashrc

3. 安装 CMake

手动安装 CMake 版本 3.25.1

CMAKE_VERSION=3.25.1
ARCH=$(uname -m)

if [ "$ARCH" = "x86_64" ]; then
  CMAKE_FILE=cmake-${CMAKE_VERSION}-linux-x86_64.sh
else
  CMAKE_FILE=cmake-${CMAKE_VERSION}-linux-aarch64.sh
fi

wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_FILE}
chmod +x ${CMAKE_FILE}
./${CMAKE_FILE} --skip-license --prefix=/usr/local --exclude-subdir
rm ${CMAKE_FILE}

cmake --version

4. 下载并提取 Redis 源代码

Redis 源代码可从 Redis GitHub 站点获取。选择你要构建的版本,然后从 Assets 下拉菜单中选择 .tar.gz 文件。你可以通过对照 redis-hashes GitHub 仓库中的摘要来验证这些下载的完整性。

将 tar(1) 文件复制到 /usr/src

或者,你可以使用 wget 命令直接下载文件,如下所示。

cd /usr/src
wget -O redis-<version>.tar.gz https://github.com/redis/redis/archive/refs/tags/<version>.tar.gz

<version> 替换为 Redis 发布版本号(三位数字),例如 8.0.0

提取源代码

cd /usr/src
tar xvf redis-<version>.tar.gz
rm redis-<version>.tar.gz

5. 构建 Redis

启用 GCC 工具链并编译支持 TLS 和模块的 Redis

source /etc/profile.d/gcc-toolset-13.sh
cd /usr/src/redis-<version>

export BUILD_TLS=yes
export BUILD_WITH_MODULES=yes
export INSTALL_RUST_TOOLCHAIN=yes
export DISABLE_WERRORS=yes

make -j "$(nproc)" all

6. (可选) 验证安装

检查 Redis 是否成功安装

./src/redis-server --version
./src/redis-cli --version

7. 启动 Redis

要启动 Redis,使用以下命令

./src/redis-server redis-full.conf

要验证可用模块是否已安装,运行 [INFO]/docs/latest/commands/info/ 命令并查找类似以下的行

./src/redis-cli INFO
...
# Modules
module:name=ReJSON,ver=20803,api=1,filters=0,usedby=[search],using=[],options=[handle-io-errors]
module:name=search,ver=21005,api=1,filters=0,usedby=[],using=[ReJSON],options=[handle-io-errors]
module:name=bf,ver=20802,api=1,filters=0,usedby=[],using=[],options=[]
module:name=timeseries,ver=11202,api=1,filters=0,usedby=[],using=[],options=[handle-io-errors]
module:name=RedisCompat,ver=1,api=1,filters=0,usedby=[],using=[],options=[]
module:name=vectorset,ver=1,api=1,filters=0,usedby=[],using=[],options=[]
...

8. (可选) 将 Redis 安装到默认位置

cd /usr/src/redis-<version>
sudo make install
评价此页面
回到顶部 ↑