yum[]使用总结

摘要

yum 是centos中centos中最好用的包下载工具。

yum的中国镜像

  1. 清华镜像: https://mirrors.tuna.tsinghua.edu.cn/help/centos/

  2. 网易镜像
    https://mirrors.163.com/.help/centos.html

建议 网易 和 清华镜像交换使用, 有时候清华镜像抽风,有时网易镜像抽风。
使用方法也很简单,到官网下载相应的Centos-Base.repo文件。
然后替换系统中文件即可,/etc/yum.repos.d/
最后清楚系统中原来的缓存,并生成新的缓存。

1
2
yum clean all
yum makecache
1
替换前,建议备份该文件

CentOS7-Base-163.repo 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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

配置文件 baseurl 和 mirrorllist的区别

首先从beseurl中寻找相应的软件,找不到后再尝试从mirrorlist寻找资源。
在镜像文件中,通常会指定baseurl为镜像的url并注释掉mirrorlist,加快下载速度。
可根据自己的需要决定是否注释掉mirrorlist。

问题汇总1

方法二

yum安装NodeJS在访问镜像列表时出现404,升级yum更新epel之后则出现这个错误: “Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again”

通过Google得知:原因

yum-epel升级到0.5.2版本,更换了https链接,所以原来的镜像列表就过时了,砸地。

解决方法是,运行:yum –disablerepo=epel -y update ca-certificates

记住一定要加上–disablerepo=epel,否则怎么都更新不了

使用代理

可以在/etc/yum.conf或者bashrc中配置代理,
yum.conf中的优先级更高,仅仅针对yum 命令有效
建议bashrc中添加代理,全局有效,方便管理。

修复epel仓库

删除epel

1
yum remove epel-release

安装epel

1
yum install epel-release

参考

  1. http://www.devkang.com/yum-errno-12-timeout-on