CentOS7.9创建本地yum源操作步骤&报错解决方法

本文详细描述了如何在离线环境下为CentOS7.9搭建本地yum源,包括解压ISO文件、上传文件、创建配置文件以及遇到的错误及其解决方法,包括修改repodata后缀和使用createrepo重生成索引。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.基础信息

       CentOS7.9-mini最小化安装的系统,在离线安装rpm时候需要大量依赖,需要花费大量时间去查找依赖包。受于环境限制无法接入互联网使用公开yum源,于是便有了搭建本机yum源的想法,在网上下载CentOS7.9标准版“CentOS-7-x86_64-DVD-2009.iso”包,开始了CentOS7.9本地yum源的搭建。

2.解压IOS文件并上传整个文件夹

         解压IOS,将“CentOS-7-x86_64-DVD-2009”整个目录上传到Centos7.9目录/usr/local/CentOS-7-x86_64-DVD-2009

PS:文件夹位置根据自己需求上传,此例以此位置为准。

3.创建本地yum源配置文件

备份原yum源配置文件夹:

mv /etc/yum.repos.d /etc/yum.repos.d.bak 
mkdir /etc/yum.repos.d

创建本地yum源配置文件

vi /etc/yum.repos.d/CentOS7_9-local.repo

 写入如下内容:

[base-local]
name=CentOS7_9-local
baseurl=file:///usr/local/CentOS-7-x86_64-DVD-2009
enable=1
gpgcheck=0

更新yum源配置文件

yum clean all
yum makecache

此时发现系统报错,报错内容如下:

[root@bogon local]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base-local
Cleaning up list of fastest mirrors
Other repos take up 463 M of disk space (use --verbose for details)
[root@bogon local]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
base-local                                                                                                                                                          | 3.6 kB  00:00:00     
base-local/group_gz            FAILED                                          
file:///usr/local/CentOS-7-x86_64-DVD-2009/repodata/a4e2b46586aa556c3b6f814dad5b16db5a669984d66b68e873586cd7c7253301-c7-x86_64-comps.xml.gz: [Errno 14] curl#37 - "Couldn't open file /usr/local/CentOS-7-x86_64-DVD-2009/repodata/a4e2b46586aa556c3b6f814dad5b16db5a669984d66b68e873586cd7c7253301-c7-x86_64-comps.xml.gz"
Trying other mirror.
base-local/primary_db          FAILED                                          
file:///usr/local/CentOS-7-x86_64-DVD-2009/repodata/0e82d111931e402316702696ae4178e65673dc0f9c23a2bb012d192cb2625ea1-primary.sqlite.bz2: [Errno 14] curl#37 - "Couldn't open file /usr/local/CentOS-7-x86_64-DVD-2009/repodata/0e82d111931e402316702696ae4178e65673dc0f9c23a2bb012d192cb2625ea1-primary.sqlite.bz2"
Trying other mirror.
base-local/filelists_db        FAILED                                          
file:///usr/local/CentOS-7-x86_64-DVD-2009/repodata/60aa4673bf5fa63d1a7a640ef407b8e48fe5b3337720d844a29a53fec130d6da-filelists.sqlite.bz2: [Errno 14] curl#37 - "Couldn't open file /usr/local/CentOS-7-x86_64-DVD-2009/repodata/60aa4673bf5fa63d1a7a640ef407b8e48fe5b3337720d844a29a53fec130d6da-filelists.sqlite.bz2"
Trying other mirror.
base-local/other_db            FAILED                                          
file:///usr/local/CentOS-7-x86_64-DVD-2009/repodata/9d6292fa12fd9ca472fafa8c0b348c3e1f139681aa066d41dc53b3563bcd1f53-other.sqlite.bz2: [Errno 14] curl#37 - "Couldn't open file /usr/local/CentOS-7-x86_64-DVD-2009/repodata/9d6292fa12fd9ca472fafa8c0b348c3e1f139681aa066d41dc53b3563bcd1f53-other.sqlite.bz2"
Trying other mirror.
base-local/primary_db          FAILED                                          
file:///usr/local/CentOS-7-x86_64-DVD-2009/repodata/0e82d111931e402316702696ae4178e65673dc0f9c23a2bb012d192cb2625ea1-primary.sqlite.bz2: [Errno 14] curl#37 - "Couldn't open file /usr/local/CentOS-7-x86_64-DVD-2009/repodata/0e82d111931e402316702696ae4178e65673dc0f9c23a2bb012d192cb2625ea1-primary.sqlite.bz2"
Trying other mirror.
base-local/other_db            FAILED                                          
file:///usr/local/CentOS-7-x86_64-DVD-2009/repodata/9d6292fa12fd9ca472fafa8c0b348c3e1f139681aa066d41dc53b3563bcd1f53-other.sqlite.bz2: [Errno 14] curl#37 - "Couldn't open file /usr/local/CentOS-7-x86_64-DVD-2009/repodata/9d6292fa12fd9ca472fafa8c0b348c3e1f139681aa066d41dc53b3563bcd1f53-other.sqlite.bz2"
Trying other mirror.
base-local/filelists_db        FAILED                                          
file:///usr/local/CentOS-7-x86_64-DVD-2009/repodata/60aa4673bf5fa63d1a7a640ef407b8e48fe5b3337720d844a29a53fec130d6da-filelists.sqlite.bz2: [Errno 14] curl#37 - "Couldn't open file /usr/local/CentOS-7-x86_64-DVD-2009/repodata/60aa4673bf5fa63d1a7a640ef407b8e48fe5b3337720d844a29a53fec130d6da-filelists.sqlite.bz2"
Trying other mirror.
file:///usr/local/CentOS-7-x86_64-DVD-2009/repodata/0e82d111931e402316702696ae4178e65673dc0f9c23a2bb012d192cb2625ea1-primary.sqlite.bz2: [Errno 14] curl#37 - "Couldn't open file /usr/local/CentOS-7-x86_64-DVD-2009/repodata/0e82d111931e402316702696ae4178e65673dc0f9c23a2bb012d192cb2625ea1-primary.sqlite.bz2"
Trying other mirror.


 One of the configured repositories failed (CentOS-local),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=base-local ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable base-local
        or
            subscription-manager repos --disable=base-local

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=base-local.skip_if_unavailable=true

failure: repodata/0e82d111931e402316702696ae4178e65673dc0f9c23a2bb012d192cb2625ea1-primary.sqlite.bz2 from base-local: [Errno 256] No more mirrors to try.
file:///usr/local/CentOS-7-x86_64-DVD-2009/repodata/0e82d111931e402316702696ae4178e65673dc0f9c23a2bb012d192cb2625ea1-primary.sqlite.bz2: [Errno 14] curl#37 - "Couldn't open file /usr/local/CentOS-7-x86_64-DVD-2009/repodata/0e82d111931e402316702696ae4178e65673dc0f9c23a2bb012d192cb2625ea1-primary.sqlite.bz2"

        发现找不到/usr/local/CentOS-7-x86_64-DVD-2009/repodata/下的.xml.gz、sqlite.bz2等文件。网上查了半天资料,再结合自己的判断,终于解决了问题。

4.报错解决方法

方法一:修改repodata索引文件后缀

        编辑CentOS-7-x86_64-DVD-2009\repodata\repomd.xml,发现每个<data></data>中定义的“location href=”的名称与CentOS-7-x86_64-DVD-2009\repodata中的文件名称一致,但是CentOS-7-x86_64-DVD-2009\repodata中文件少了后缀,于是根据repomd.xml,依次将CentOS-7-x86_64-DVD-2009\repodata中的文件后缀增加。

如图所示,第一个<data></data>为.xml文件,将repodata/后面到"之间的内容复制:

cca56f3cffa18f1e52302dbfcf2f0250a94c8a37acd8347ed6317cb52c8369dc-c7-x86_64-comps.xml

同时在目录中找到此文件,并修改为复制的名称,如图所示:

同理修改其他的<data></data>,修改完后再次执行

yum clean all
yum makecache

切换本地yum源成功

方法二:通过createrepo重新生成repodate索引

        repodata是rpm包目录的索引,使用createrepo工具创建。此时使用CentOS7.9虚拟机(可以访问互联网yum源)来安装使用createrepo工具。

步骤一:安装createrepo

yum install createrepo

步骤二:创建repodata索引

上传CentOS-7-x86_64-DVD-2009\Packages(rpm文件夹)到Centos虚拟机,进入Packages文件夹,执行

createrepo .

此时,在Packages生成repodata索引,如图所示:

有了repodata索引,再根据之前步骤操作即可完成本地yum源搭建。

createrepo使用参考:https://www.cnblogs.com/mxleader/p/17312013.html

PS:

1.CentOS-7-x86_64-Everything-2009.iso比CentOS-7-x86_64-DVD-2009.ios的rpm包更全,如条件允许,建议使用CentOS-7-x86_64-Everything-2009.iso中的rpm包

2.如果本地CentOS7.9服务器多,可以结合http服务,搭建本地局域网yum源。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值