在CentOS 7下使用阿里云yum源搭建本地YUM仓库(1):同步yum源保存到本地【测试成功】

艺帆风顺 发布于 2025-04-02 18 次阅读


一、需求背景    在某个内网环境中,只有一台服务器可以连接外部网络,在此情况下,需要在该台服务器搭建yum源,以便其他内网服务器能够使用yum安装软件以解决依赖关系。二、具体实现1、查看系统版本信息2、下载阿里云yum源、epel源到本地3、检查源是否处于正常状态:yum repolist

    [root@cheliangweb yum.repos.d]# yum repolist已加载插件:fastestmirror, langpacks, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com源标识                                              源名称                                                                            状态base/7/x86_64                                       CentOS-7 - Base - mirrors.aliyun.com                                              10,072epel/x86_64                                         Extra Packages for Enterprise Linux 7 - x86_64                                    13,791extras/7/x86_64                                     CentOS-7 - Extras - mirrors.aliyun.com                                               526updates/7/x86_64                                    CentOS-7 - Updates - mirrors.aliyun.com                                            6,173repolist: 30,562

    4、安装yum依赖环境# yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils

    yum-utils:reposync同步工具

    createrepo:编辑yum库工具

    plugin-priorities:控制yum源更新优先级工具,这个工具可以用来控制进行yum源检索的先后顺序,建议可以用在client端。

    5、创建本地目录并同步mkdir /temp/repocd /temp/reporeposync -np /temp/repo/base   #执行后耐心等待,时间与服务器网络有关备注:如果只想同步某一个yum源到本地,可执行以下命令。sudo reposync -g -l -d --repoid=docker-ce-stable --download_path=/temp/repo/docker问题处理:同步后发现rpm包一个没有保存上,提示丢失key

      Removing docker-scan-plugin-0.7.0-3.el7.x86_64.rpm, due to missing GPG key.Removing docker-scan-plugin-0.8.0-3.el7.x86_64.rpm, due to missing GPG key.Removing docker-scan-plugin-0.9.0-3.el7.x86_64.rpm, due to missing GPG key.
      解决方案:导入 Docker 的 GPG 密钥,然后重新执行同步rpm --import https://download.docker.com/linux/centos/gpg6、创建repo索引信息    createrepo -po /temp/repo/base/ /temp/repo/base/

          createrepo -po /temp/repo/extras/ /temp/repo/extras/

          createrepo -po /temp/repo/updates/ /temp/repo/updates/

          createrepo -po /temp/repo/epel/ /temp/repo/epel/

      createrepo -po /temp/repo/docker-ce-stable/ /temp/repo/docker-ce-stable/

      6、更新repo源数据    createrepo --update /temp/repo/base

          createrepo --update /temp/repo/extras

          createrepo --update /temp/repo/updates

          createrepo --update /temp/repo/epel

          createrepo --update  /temp/repo/docker-ce-stable/

      三、测试验证之后重新安装即可。参考链接:https://www.cnblogs.com/reachos/p/11303843.html