Rocky9 配置国内源
创建文件并更新缓存
使用以下命令创建文件(你也可以直接用 vim 或 nano 手动创建):
sudo tee /etc/yum.repos.d/epel.repo << 'EOF'
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
baseurl=https://mirrors.aliyun.com/epel/$releasever/Everything/$basearch/
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-$releasever
[epel-debuginfo]
name=Extra Packages for Enterprise Linux $releasever - $basearch - Debug
baseurl=https://mirrors.aliyun.com/epel/$releasever/Everything/$basearch/debug/
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-$releasever
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux $releasever - $basearch - Source
baseurl=https://mirrors.aliyun.com/epel/$releasever/Everything/source/tree/
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-$releasever
gpgcheck=1
EOF
# 写入 epel-testing.repo
sudo tee /etc/yum.repos.d/epel-testing.repo << 'EOF'
[epel-testing]
name=Extra Packages for Enterprise Linux $releasever - Testing - $basearch
baseurl=https://mirrors.aliyun.com/epel/testing/$releasever/Everything/$basearch/
#metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgcheck=1
countme=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-$releasever
[epel-testing-debuginfo]
name=Extra Packages for Enterprise Linux $releasever - Testing - $basearch - Debug
baseurl=https://mirrors.aliyun.com/epel/testing/$releasever/Everything/$basearch/debug/
#metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-debug-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-$releasever
gpgcheck=1
[epel-testing-source]
name=Extra Packages for Enterprise Linux $releasever - Testing - $basearch - Source
baseurl=https://mirrors.aliyun.com/epel/testing/$releasever/Everything/source/tree/
#metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-source-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-$releasever
gpgcheck=1
EOF清理并生成缓存
sudo dnf clean all
sudo dnf makecache现在你的 EPEL 仓库也已配置为国内镜像,安装软件包的速度将显著提升。如果需要更换其他镜像(如清华、华为云),只需将上述 baseurl 和 gpgkey 中的 mirrors.aliyun.com 替换为其他镜像域名即可。
你可以按照以下步骤重新生成 Rocky Linux 9 的软件源配置文件。这里提供的是基于国内镜像(上海交大 SJTUG 和阿里云)的配置,速度会更快。如果你更喜欢其他镜像(如华为云、腾讯云),替换 baseurl 中的域名即可。
创建 Rocky Linux 基础仓库配置文件
新建 /etc/yum.repos.d/rocky.repo 文件,并粘贴以下内容:
# rocky.repo - Rocky Linux 9 基础仓库 (使用上海交大镜像)
# 若想换用其他镜像,只需替换 baseurl 中的 mirror.sjtu.edu.cn 即可
[baseos]
name=Rocky Linux $releasever - BaseOS
baseurl=https://mirror.sjtu.edu.cn/rocky/$releasever/BaseOS/$basearch/os/
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
[appstream]
name=Rocky Linux $releasever - AppStream
baseurl=https://mirror.sjtu.edu.cn/rocky/$releasever/AppStream/$basearch/os/
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=AppStream-$releasever
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
[crb]
name=Rocky Linux $releasever - CRB
baseurl=https://mirror.sjtu.edu.cn/rocky/$releasever/CRB/$basearch/os/
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=CRB-$releasever
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
# extras 仓库(包含一些额外工具,通常不需要)
[extras]
name=Rocky Linux $releasever - Extras
baseurl=https://mirror.sjtu.edu.cn/rocky/$releasever/extras/$basearch/os/
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=extras-$releasever
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
# plus 仓库(包含重新打包的第三方软件,通常不需要)
[plus]
name=Rocky Linux $releasever - Plus
baseurl=https://mirror.sjtu.edu.cn/rocky/$releasever/plus/$basearch/os/
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=plus-$releasever
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9说明:
- 已启用
baseos和appstream(系统运行必须)。crb(CodeReady Builder,原 PowerTools)默认关闭,需安装某些编译依赖时可手动启用。extras和plus很少用到,也默认关闭。
清理并重建缓存
sudo dnf clean all
sudo dnf makecache现在你的 Rocky Linux 9 已配置好快速稳定的国内镜像源。你可以再次尝试安装 chrony(它应该会从 baseos 源下载,速度很快):
sudo dnf install -y chrony补充说明
- Rocky Linux 9 的 chrony 位于 BaseOS 仓库,配置好基础源后即可快速安装,无需 EPEL。
- 如果你之后需要 Docker、Kubernetes 等第三方源,可以单独添加对应的
.repo文件,建议也使用国内镜像。 - 若想换用其他国内镜像(如阿里云、华为云、腾讯云),只需将上述配置中的
mirror.sjtu.edu.cn替换为相应域名即可(注意路径结构可能略有不同,建议先访问镜像站官网查看帮助)。