同步外网YUM源

        在企业实际应用场景中,仅仅靠光盘中的RPM软件包是不能满足需要的,用户可以把外网的YUM源中的所有软件包同步至本地,完善本地YUM源的软件包数量及完整性。

        获取外网YUM源软件常见方法包括: rsync、wget、 reposync,三种同步方法的区别为: rsync方式需要外网YUM源支持rsync协议;wget可以直接获取; reposync可以同步几乎所有的YUM源。下面以 reporsync为案例,同步外网YUM源软件至本地,步骤如下:

(1)下载CentOS 7 repo文件至/etc/yum. repos.d,并安装 reposync命令工具

 wget http://mirrors.163.com/.help/CentOS7-Base-163.repo 

 mv CentOS7-Base-163.repo /etc/yum repos. d/centos. repo

 yum clean all

 yum install yum-utils createrepo-y

 yum repolist

(2)通过reposync命令工具获取外网YUM源所有软件包,r指定 repolist id,默认不加-r表示获取外网所有YUM软件包,p参数表示指定下载软件的路径。

 reposync -r base -p /var/www/html/centos

 reposync -r updates -p /var/www/html/centos

(3)通过reposync工具下载完所有的软件包之后,需要执行 createrepo更新本地yum仓库。

 createrepo /var/www/html/centos/

#如果是多个repo id,你可以合并写成一条命令:

reposync -n --repoid=extras6 --repoid=updates6 --repoid=base6 --repoid=epel6 -p  ./CentOS6/

#以一个为例,格式:createrepo -po    源目录    索引元数据的输出位置目录

createrepo -po /data/centos/7.4/base7.4    /data/centos/7.4/base7.4

#更新元数据

createrepo --update /data/centos/7.4/base7.4

注:外部YUM源地址:(测试日期:2021/03/24)

官方备份档案:https://vault.centos.org/    (CentOS 6,已不在维护,如需要请使用里面提供的镜像站)

http://archive.kernel.org/centos-vault/    (CentOS 6 这个貌似用不了)

http://linuxsoft.cern.ch/centos-vault/        (CentOS 6这个还可以)

http://mirror.nsc.liu.se/centos-store/        (CentOS 6这个还可以)

https://mirrors-i.tuna.tsinghua.edu.cn/centos-vault/      (清华大学开源软件镜像站,推荐用这个,CentOS 6这个还可以,阿里的已经没有了)

官方当前维护版本:https://wiki.centos.org/Download   

可能存在问题:

【1】CentOS 6的YUM源不可用,可以使用上面提供 外部YUM源地址或者使用我这边改好的几个能用YUM源的地址,使用时最好将/etc/yum.repo.d/目录下的文件全部移走,不要让repolist id重复(即repo文件中“[]”内的名称不能重复),提供现成repo文件如下:

CentOS6-Base.7z (压缩包有四个文件,只需要使用其中一个即可!)

你如果有其他YUM源,请自行修改。

提示:修改YUM网络源链接时,需保证当前链接路径下有repodata目录存在!!!

例如链接:https://mirrors-i.tuna.tsinghua.edu.cn/centos-vault/6.10/os/x86_64/

【2】CentOS 8 使用reposync同步网络yum源到本地 ,在reposync同步命令稍有不同:

举例如下:

dnf reposync --repoid=the_repo

同步存储库中所有repo id为“ the_repo”的软件包。同步后的副本将保存在当前工作目录的“the_repo”子目录中。

dnf reposync -p /my/repos/path --repoid=the_repo

同步存储库中所有repo id为“ the_repo”的软件包。在定义保存路径情况下,文件将保存在“ / my / repos / path / the_repo”目录中。

dnf reposync --repoid=the_repo --download-metadata

同步repo id为“ the_repo”存储库中的所有软件包和元数据。

说明:--download-metadata :下载所有存储库元数据。下载的副本可立即用作存储库,而无需在其上运行createrepo命令使用。

使用--download-metadata选项同步的存储库可以直接在DNF中使用,例如通过使用--repofrompath选项引用:

dnf --repofrompath=syncedrepo,the_repo --repoid=syncedrepo list --available

 

那么上面使用的命令:

 reposync -r base -p /var/www/html/centos

 reposync -r updates -p /var/www/html/centos

在CentOS 8 中就需要写成

 reposync --repoid=base -p /var/www/html/centos  

 reposync --repoid=updates -p /var/www/html/centos  

【3】在CentOS 8 使用reposync命令同步时报错如下:

Modular dependency problems:

Problem 1: conflicting requests

nothing provides module(perl:5.26) needed by module perl-DBD-SQLite:1.58:8010020191114033549:073fa5fe-0.x86_64

Problem 2: conflicting requests

nothing provides module(perl:5.26) needed by module perl-DBI:1.641:8010020191113222731:16b3ab4d-0.x86_64

【解决方法】:

yum module enable perl:5.26

PS:在使用私有yum源时该命令可能不能执行成功,可先使用官方yum源,执行该命令后,再使用私有仓库。

参考文章链接如下:

1、CentOS8更换yum源后出现同步仓库缓存失败的问题:https://www.zhangshengrong.com/p/O3aA7dGnX4/

2、yum报错:needed by module perl-DBD-SQLite:1.58:https://blog.csdn.net/weixin_45241288/article/details/104527538

3、CentOS镜像使用帮助:http://mirrors.163.com/.help/centos.html

4、Centos的yum源更换为国内的阿里云软件源:https://waterbear.pw/630.html

5、dnf-reposync - Man Page:https://www.mankier.com/8/dnf-reposync

版权声明:
作者:WaterBear
链接:https://l-t.top/1116.html
来源:雷霆运维
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>