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 onlysafe 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 workingupstream. This is most often useful if you are using a newerdistribution release than is supported by the repository (and thepackages for the previous distribution release still work).3. Run the command with the repository temporarily disabledyum --disablerepo=base-local ...4. Disable the repository permanently, so yum won't use it by default. Yumwill then just ignore the repository until you permanently enable itagain or use --enablerepo for temporary usage:yum-config-manager --disable base-localorsubscription-manager repos --disable=base-local5. 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 muchslower). If it is a very temporary problem though, this is often a nicecompromise:yum-config-manager --save --setopt=base-local.skip_if_unavailable=truefailure: 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源。