其实安装网络源很简单,但是今天遇到了个奇特的问题,折腾了几个小时。
先说下安装网络源的步骤:
修改CentOS默认yum源为mirrors.163.com
1、首先备份系统自带yum源配置文件/etc/yum.repos.d/CentOS-Base.repo
1
|
[root@localhost ~]
# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
|
2、进入yum源配置文件所在的文件夹
1
|
[root@localhost ~]
# cd /etc/yum.repos.d/
|
3、下载163的yum源配置文件到上面那个文件夹内
CentOS7
1
|
[root@localhost yum.repos.d]
# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
|
CentOS6
1
|
[root@localhost yum.repos.d]
# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
|
CentOS5
1
|
[root@localhost yum.repos.d]
# wget http://mirrors.163.com/.help/CentOS5-Base-163.repo
|
4、运行yum makecache生成缓存
1
|
[root@localhost yum.repos.d]
# yum makecache
|
5、这时候再更新系统就会看到以下mirrors.163.com信息
1
2
3
4
5
6
|
[root@localhost yum.repos.d]
# yum -y update
已加载插件:fastestmirror, refresh-packagekit, security
设置更新进程Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
|
修改CentOS默认yum源为mirrors.aliyun.com
1、首先备份系统自带yum源配置文件/etc/yum.repos.d/CentOS-Base.repo
1
|
[root@localhost ~]
# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
|
2、下载ailiyun的yum源配置文件到/etc/yum.repos.d/
CentOS7
1
|
[root@localhost ~]
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
|
CentOS6
1
|
[root@localhost ~]
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
|
CentOS5
1
|
[root@localhost ~]
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
|
3、运行yum makecache生成缓存
1
|
[root@localhost ~]
# yum makecache
|
4、这时候再更新系统就会看到以下mirrors.aliyun.com信息
1
2
3
4
5
6
|
[root@localhost ~]
# yum -y update
已加载插件:fastestmirror, refresh-packagekit, security
设置更新进程Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
|
是不是很Easy!
-----------------------------------------------------------------------------------------------------------
其实我也是按照这个步骤操作的,但是报了错:
[root@manager yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, security
Error: File contains no section headers.
file: file:///etc/yum.repos.d/6CentOS-Base.repo, line: 1
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r\n'
这是啥情况,问题在于你下载的不对,这里建议使用浏览器下载,然后上传至服务器。
[root@manager yum.repos.d]# file CentOS6-Base-163.repo
CentOS6-Base-163.repo: ASCII English text
当你使用wget下载的时候,请确认下file出来是否为ASCII English text,必须是这个格式。
当然了,你可用另外一种方式装
Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
error: /var/tmp/rpm-tmp.COfzVl: not an rpm package (or package manifest):
还是相同的解决办法,在浏览器输入http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm,然后上传至服务器。
[root@manager yum.repos.d]# yum install fail2ban
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
epel | 4.2 kB 00:00
http://download.fedoraproject.org/pub/epel/6/x86_64/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for epel: Damaged repomd.xml file
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: epel. Please verify its path and try again
上述报错的一切一切的原因,今天终于找到了,在网络的出口有限制,导致异常,出问题时可以使用手机4G做热点试一试。