yum 更新不起作用(存储库问题)

yum 更新不起作用(存储库问题)
# yum update -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Update Process
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ft, http[s] or file.
Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/×86 64/6/base/mirrorli st.txt
Error: Cannot find a valid baseurl for repo: base [root@localhost Desktop]# cd/etc/yum. repos.d/ bash: cd/etc/yum.repos.d/: No such file or directory [root@localhost Desktop]# cd /etc/yum. repos. d/ [root@localhost yum. repos.d]# ll total 32
- M-Г--г=
- Пу-Г--г-.
1 root root 1991 May 19 2016 CentOS-Base.repo
1 root root 1991 May
9 14:14 Cent0S-base. repo.old
1 root root
647 May 19 2016 CentOs-Debuginfo.repo
1 root root
289 May 19
2016 Cent0S-fasttrack.repo
- M-r--г.
1 root root 630 May 19 2016 CentOS-Media.repo
- [/-Г-- Г-
. 1 root root 6259 May 19
2016 CentOS-Vault. repo
-rw-r--r--. 1 root root 259 Sep 30 2015 virtualbox. repo [root@localhost yum. repos.d]# cp Centos-Base. repo CentOs-Base.repo.old [rootalocalhost yum. repos.d]# ll total 36
- T-T---- . 1 root root 1991 May 19
2016 Cent0S-Base. repo
1 root root 1991 May
9 14:14 CentOS-base.repo.old
- To re
1 root root 1991 May
9 14:22 Centos -Base. repo.old
1 root root
647 May 19 2016 CentOS -Debuginfo.repo
- П-Г-
1 root root
289 May 19 2016 CentOS-fasttrack.repo
-rw-r--r--, 1 root root 630 May 19 2016 CentOS-Media. repo
-rw-r--r--. 1 root root 6259 May 19 2016 Cents-Vault. repo
-rw-r--r--. 1 root root 259 Sep 30 2015 virtualbox. repo [root@localhost yum. repos.d]# vi CentOs- Base. repo [root@localhost yum. repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Error: File contains no section headers.
file: file:///etc/yum.repos.d/CentOS-Base.repo, line: 4
'update status of each mirror to pick mirrors that are updated to and\n' [root@localhost yum. repos.d]#

答案1

该文件/etc/yum.repos.d/CentOS-Base.repo应如下所示(以 CentOS 7 为例,您的版本可能有所不同,但应具有类似的结构):

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-7 - Base
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-7 - Updates
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-7 - Extras
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

带方括号 ( [base][updates]、 和[extras]) 的行是节标题,并且每个设置块以节标题开始,直到下一个节标题行(或文件结尾)是部分。每个部分都定义一个可能的存储库以从中下载包。

如果存储库部分使用该mirrorlist=行,则它会告诉yum您首先从指定的 URL 下载存储库镜像 URL 列表,然后使用这些镜像之一。如果该部分使用该baseurl=行,则它直接指定包存储库的 URL。

在高安全性的防火墙环境中,这些mirrorlist=线路可能会引起麻烦,因为系统可能连接到的软件包存储库的 IP 地址无法提前确定,因为镜像列表可能会随着时间的推移而变化,并且可能包括内容交付网络例如遍布互联网的 Akamai。这使得防火墙访问列表变得冗长且难以管理。

因此,注释掉该mirrorlist=行并取消注释相应的baseurl=行是相当常见的,甚至可能指定一个自定义存储库 URL,该 URL 引用位置相当接近的可信镜像站点,甚至引用由拥有高安全环境的组织。然后防火墙管理员可以最大限度地减少防火墙访问列表的长度,这让安全审核员很高兴。

错误信息

Error: File contains no section headers.
file: file:///etc/yum.repos.d/CentOS-Base.repo, line: 4
'update status of each mirror to pick mirrors that are updated to and\n'

表明您的文件的第 4 行有一些yum不理解的内容CentOS-Base.repo。它甚至会为您显示该行的内容。

与示例相比,看起来有人可能已经#从行的开头删除了注释符号(字符)。由于该行的其余部分只是供人类阅读的自由格式文本,因此当然yum无法理解它。

也许有人尝试使用某种自动化工具修改文件,但犯了一个错误,导致该工具从非预期位置删除了注释符号?

您必须查看/etc/yum.repos.d/CentOS-Base.repo文件的内容并尝试找出发生了什么。如果文件开头的文本行丢失了注释标记,则应替换它们或删除自由格式文本行。

只有配置节(每个节都以方括号节标题行开头)才具有实际含义yum。如果这些文件丢失或损坏,您可能必须从备份中找到该文件的未损坏副本,或者通过 Google 获取适用于您的特定 CentOS 版本的该文件的示例,并使用它来修复您的文件。如果您使用的高安全性系统不允许通过互联网与基本上任何 HTTP 服务器建立传出连接,那么您应该了解您的系统应该如何获取更新(您应该使用特定的镜像?内部镜像)网站?网络代理?)并相应地调整您的重建配置。

相关内容