CentOS7替换yum的问题:使用yum时出现File contains no section headers

CentOS7替换yum的问题:使用yum时出现File contains no section headers.


安装好centos后,为了更好的体验yum,我们会选择替换国内的yum,例如阿里,网易

centos替换yum的步骤

1.备份原yum
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2.进入存放repo的文件夹
cd /etc/yum.repos.d/

3.下载对应的repo文件(示例为网易centos7)
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
或者
curl http://mirrors.163.com/.help/CentOS7-Base-163.repo -o CentOS7-Base-163.repo

4.清除缓存
yum clean all
yum makecache

出现的问题

一般来说,以上四步可以正常运行,但是我在实践过程中遇到第四步清除缓存时出现错误提示:
Loaded plugins: fastestmirror

(使用curl命令会出现)
File contains no section headers.
file: file:///etc/yum.repos.d/CentOS7-Base-163.repo, line: 1
‘<?xml version="1.0" encoding="UTF-8"?>\r\n’
(使用wget命令会出现)
File contains no section headers.
file: file:///etc/yum.repos.d/CentOS7-Base-163.repo, line: 1
“\r\n”

无论是阿里系还是网易的repo下载后运动都会出现这样的错误,在对比了和CentOS-Base.repo文件后发现此时的CentOS7-Base-163.repo和CentOS-Base.repo(源yum)格式不一样

cat CentOS7-Base-163.repo

// An highlighted block
[root@localhost yum.repos.d]# cat CentOS7-Base-163.repo
<?xml version="1.0" encoding="UTF-8"?>
<WISPAccessGatewayParam xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="http://www.acmewisp.com/WISPAccessGatewayParam.xsd">
<Proxy>
<MessageType>110</MessageType>
<NextURL>http://222.201.54.55/eportal/index.jsp?wlanuserip=172.29.139.196&wlanacname=AC&ssid=GZHU&mac=C8-FF-28-95-D8-30</NextURL>
<ResponseCode>200</ResponseCode>
</Proxy>
</WISPAccessGatewayParam>

cat CentOS-Base.repo
(查看文件)

// An highlighted block
[root@localhost yum.repos.d]# cat CentOS-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-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$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-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$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-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


此时我下载了CentOS7-Base-163.repo文件用编辑器打开发现 woow

// An highlighted block
# 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-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/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/$releasever/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/$releasever/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=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

这跟导入的文件完全不一样,或许是编码格式出现了问题

解决方法

1.用编辑器打开CentOS7-Base-163.repo复制里面的代码
2.centos编辑CentOS7-Base-163.repo文件
vi CentOS7-Base-163.repo
i进入编辑
粘贴代码
esc+:wq 保存退出

相关命令

cd etc/yum.repos.d 进入etc/yum.repos.d文件夹
ls 查看该文件夹的文件
vi etc/yum.repos.d/CentOS7-Base-163.repo 修改etc/yum.repos.d中的CentOS7-Base-163.repo文件
mv CentOS-Base.repo.backup CentOS-Base.repo 把CentOS-Base.repo.backup重命名为CentOS-Base.repo

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值