在 AlmaLinux/Rocky Linux 8.10 上构建并运行 Redis Open Source

Redis Open Source

按照以下步骤在运行 AlmaLinux 和 Rocky Linux 8.10 的系统上从源代码构建并运行 Redis Open Source。

注意

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

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

1. 准备系统

注意

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

microdnf install dnf sudo -y

对于 8.10 (regular),你需要按如下方式安装 sudo

dnf install sudo -y

清理软件包元数据,启用所需的仓库,并安装开发工具

sudo dnf clean all

# Add GoReleaser repo
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 update -y
sudo dnf groupinstall "Development Tools" -y
sudo dnf config-manager --set-enabled powertools
sudo dnf install -y epel-release

2. 安装所需的软件包

安装构建依赖项、Python 3.11 和支持工具

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

创建 Python 虚拟环境

python3.11 -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 服务器和 CLI 版本

./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
评价此页面
返回顶部 ↑