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

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源。

  • 27
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1.查看系统本身存在的版本 rpm -qa | grep yum 2.卸载centos7上存在的yum安装源包 rpm -e 源包 --nodeps 3.下载yum源包(http://mirrors.163.com/centos/7/os/x86_64/Packages/) yum-metadata-parser-1.1.4-10.el7.x86_64 PackageKit-yum-1.0.7-6.el7.centos.x86_64 yum-utils-1.1.31-40.el7.noarch 下方两个一起装 yum-plugin-fastestmirror-1.1.31-40.el7.noarch yum-langpacks-0.4.2-7.el7.noarch yum-3.4.3-150.el7.centos.noarch yum-rhn-plugin-2.0.1-6.el7.noarch 4.安装yum源包 rpm -ivh yum* 5.创建配置文件(/etc/yum.repos.d/CentOS-Base.repo) vi /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=os baseurl=http://mirrors.163.com/centos/(系统版本号)7/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=updates baseurl=http://mirrors.163.com/centos/7/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=extras baseurl=http://mirrors.163.com/centos/7/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=$releasever - Plus - 163.com baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 每一个baseurl的centos后都改成自己系统的版本号 6.执行命令 yum clean all yum makecache yum install telnet
### 回答1: 配置本地yum源是为了在CentOS 7.9上加快软件包的下载速度和部署效率。以下是在CentOS 7.9上配置本地yum源的步骤: 1. 准备一个CentOS 7.9的安装镜像文件(ISO镜像文件或DVD)。将镜像文件挂载到系统中的一个目录,例如/mnt目录下: ```shell mount -o loop /path/to/CentOS-7.9-xxxx.iso /mnt ``` 2. 在/etc/yum.repos.d/目录中创建一个新的repo文件,例如local.repo: ```shell vi /etc/yum.repos.d/local.repo ``` 3. 在打开的local.repo文件中,添加以下内容: ``` [local] name=Local Repository baseurl=file:///mnt enabled=1 gpgcheck=0 ``` 4. 保存并退出local.repo文件。 5. 清除现有的yum缓存: ```shell yum clean all ``` 6. 更新yum源: ```shell yum makecache ``` 现在你已经成功配置了本地yum源。你可以通过yum命令安装、更新或删除软件包,系统会自动从本地yum源进行操作,提供更快的下载速度和操作效率。 ### 回答2: 在CentOS 7.9上配置本地yum源的步骤如下: 1. 首先,需要安装一个软件包用于创建本地yum源。打开终端,以root用户身份运行以下命令: ``` yum install -y createrepo ``` 2. 创建一个目录用于存储本地yum源配置文件和软件包。例如,可以使用以下命令创建一个名为`myyum`的目录: ``` mkdir /myyum ``` 3. 将要添加到yum源的软件包复制到创建的目录中。例如,将软件包`example.rpm`复制到`/myyum`目录中: ``` cp example.rpm /myyum ``` 4. 使用`createrepo`命令创建一个本地yum源的索引。进入`/myyum`目录,然后运行以下命令: ``` createrepo . ``` 这将在`/myyum`目录中生成一个名为`repodata`的文件夹,其中包含有关可用软件包的元数据。 5. 下一步是创建一个本地yum源配置文件。在`/etc/yum.repos.d/`目录下创建一个名为`myyum.repo`的文件: ``` vi /etc/yum.repos.d/myyum.repo ``` 在文件中添加以下内容: ``` [myyum] name=My Local Yum baseurl=file:///myyum enabled=1 gpgcheck=0 ``` 保存并关闭文件。 6. 最后,运行`yum clean all`命令清除yum缓存,然后运行`yum list`命令检查本地yum源是否配置成功: ``` yum clean all yum list ``` 如果配置成功,您将在可用软件包列表中看到您复制到`/myyum`目录的软件包。 现在,您已成功配置了本地yum源,在CentOS 7.9上可以使用该源进行软件包安装和更新。 ### 回答3: 要在CentOS 7.9上配置本地的Yum源,您可以按照以下步骤进行操作: 1. 首先确保您已经连接到互联网,并且拥有root用户权限。 2. 安装必要的软件包。在终端中运行以下命令安装所需软件包: ``` sudo yum install createrepo yum-utils ``` 3. 创建一个用于存储本地Yum存储库的目录。您可以选择在任何位置创建此目录,但是在本例中,我们将创建名为"local_yum"的目录。使用以下命令创建该目录: ``` sudo mkdir /opt/local_yum ``` 4. 拷贝CentOS 7的Yum存储库文件到本地目录中。您可以从CentOS官方镜像站点下载对应版本的repo文件,并使用以下命令将其复制到本地目录: ``` sudo cp /etc/yum.repos.d/CentOS-Base.repo /opt/local_yum/ ``` 5. 进入刚刚创建的目录: ``` cd /opt/local_yum ``` 6. 打开复制的repo文件进行编辑: ``` sudo vim CentOS-Base.repo ``` 7. 将文件中所有的"baseurl"和"mirrorlist"行都注释掉,并在每个注释行下方添加以下内容: ``` baseurl=file:///opt/local_yum ``` 8. 保存文件并退出编辑器。 9. 使用以下命令生成本地Yum存储库的索引: ``` sudo createrepo /opt/local_yum ``` 10. 使用以下命令清除您的Yum缓存并重新生成缓存: ``` sudo yum clean all sudo yum makecache ``` 11. 完成以上步骤后,您的本地Yum源配置成功。您可以使用常规的Yum命令来安装、更新和管理软件包,系统将会自动从本地Yum源中获取软件包。 这样,您就成功在CentOS 7.9上配置了本地Yum源

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值