CentOS7在使用yum的时候报错File contains no section headers.如何解决
- 网上搜了一大堆方法,有的靠谱有的不行,有的有时候能用,一会儿又不能用了,我这里总结了一下,两个方法,都比较简单粗暴,可以尝试一下。
- 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.
网上搜了一大堆方法,有的靠谱有的不行,有的有时候能用,一会儿又不能用了,我这里总结了一下,两个方法,都比较简单粗暴,可以尝试一下。
第一个方案
删除yum.repos.d目录下所有文件rm -f /etc/yum.repos.d/*
然后重新下载阿里的资源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
注意,上面的参数是大写的英文字母O
然后清除缓存 yum clean all
第二个方案
如果上面的办法不行,那么可以试试这个方法,稍微麻烦点,但是大概率管用。
直接修改CenOS-Base.repo文件内容
修改/etc/yum.repos.d/CenOS-Base.repo文件内容如下:
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-
r
e
l
e
a
s
e
v
e
r
−
B
a
s
e
m
i
r
r
o
r
l
i
s
t
=
h
t
t
p
:
/
/
m
i
r
r
o
r
l
i
s
t
.
c
e
n
t
o
s
.
o
r
g
/
?
r
e
l
e
a
s
e
=
releasever - Base mirrorlist=http://mirrorlist.centos.org/?release=
releasever−Basemirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=os&infra=infra
#baseurl=http://mirror.centos.org/centos/
r
e
l
e
a
s
e
v
e
r
/
o
s
/
releasever/os/
releasever/os/basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
U
p
d
a
t
e
s
m
i
r
r
o
r
l
i
s
t
=
h
t
t
p
:
/
/
m
i
r
r
o
r
l
i
s
t
.
c
e
n
t
o
s
.
o
r
g
/
?
r
e
l
e
a
s
e
=
releasever - Updates mirrorlist=http://mirrorlist.centos.org/?release=
releasever−Updatesmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=updates&in…infra
#baseurl=http://mirror.centos.org/centos/
r
e
l
e
a
s
e
v
e
r
/
u
p
d
a
t
e
s
/
releasever/updates/
releasever/updates/basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
E
x
t
r
a
s
m
i
r
r
o
r
l
i
s
t
=
h
t
t
p
:
/
/
m
i
r
r
o
r
l
i
s
t
.
c
e
n
t
o
s
.
o
r
g
/
?
r
e
l
e
a
s
e
=
releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release=
releasever−Extrasmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=extras&inf…infra
#baseurl=http://mirror.centos.org/centos/
r
e
l
e
a
s
e
v
e
r
/
e
x
t
r
a
s
/
releasever/extras/
releasever/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-
r
e
l
e
a
s
e
v
e
r
−
P
l
u
s
m
i
r
r
o
r
l
i
s
t
=
h
t
t
p
:
/
/
m
i
r
r
o
r
l
i
s
t
.
c
e
n
t
o
s
.
o
r
g
/
?
r
e
l
e
a
s
e
=
releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release=
releasever−Plusmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=centosplus…infra
#baseurl=http://mirror.centos.org/centos/
r
e
l
e
a
s
e
v
e
r
/
c
e
n
t
o
s
p
l
u
s
/
releasever/centosplus/
releasever/centosplus/basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
如果不能修改,更改文件的权限
代码如下
chmod 777 CenOS-Base.repo
注意进入到文件所处的地方再修改。
保存退出之后,在执行指令
yum clean all