Linux:yum配置使用阿里源、epel源
Centos:yum配置使用阿里云yum源、epel源
使用阿里云yum源
1.备份
cd /etc/yum.repos.d/ && mkdir backup && mv *repo backup/
2.下载阿里云yum源
Centos 5:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
Centos 6:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
Centos 7:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3.更新 repo 缓存:yum clean all && yum makecache
[root@test1280 yum.repos.d]# yum clean all && yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.7 kB 00:00
base/group_gz | 242 kB 00:00
base/filelists_db | 6.4 MB 00:17
base/primary_db | 4.7 MB 00:12
base/other_db | 2.8 MB 00:07
extras | 3.4 kB 00:00
extras/filelists_db | 24 kB 00:00
extras/prestodelta | 2.2 kB 00:00
extras/primary_db | 29 kB 00:00
extras/other_db | 14 kB 00:00
updates | 3.4 kB 00:00
updates/filelists_db | 4.7 MB 00:12
updates/prestodelta | 236 kB 00:00
updates/primary_db | 6.6 MB 00:18
updates/other_db | 303 kB 00:00
Metadata Cache Created
PS:
如果我们访问 http://mirrors.aliyun.com/repo/,可以看到一系列的 repo 配置文件:
选择自己需要的下载即可(例如阿里云epel源)。
使用epel源
epel:Extra Packages for Enterprise Linux,是一个第三方镜像源。
1.备份
cd /etc/yum.repos.d/ && mkdir backup && cp *repo backup/
2.安装epel yum源
有几种常用的方法:
2.1)yum 安装:yum install -y epel-release
[root@test1280 yum.repos.d]# yum install -y epel-release
安装完成后,将在 /etc/yum.repos.d 新增两个 repo 文件:epel.repo、epel-testing.repo。
2.2)rpm 安装:
Centos 6:
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
或
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
例如:
[root@test1280 yum.repos.d]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.rne5Zd: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
[root@test1280 yum.repos.d]# rpm -qa | grep epel
epel-release-6-8.noarch
更多请参见:http://dl.fedoraproject.org/pub/epel/,例如:
当然,通过 rpm 包安装,也可以先找个镜像源下载epel rpm包,然后手动安装:
例如,清华的镜像源:https://mirrors.tuna.tsinghua.edu.cn/epel//6/x86_64/
下载后上传至服务器,然后通过 rpm -ivh 安装 epel-rpm 包:
[root@test1280 yum.repos.d]# ls -l epel-release-6-8.noarch.rpm
-rw-r--r--. 1 root root 14540 Nov 3 04:11 epel-release-6-8.noarch.rpm
[root@test1280 yum.repos.d]# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
[root@test1280 yum.repos.d]# rpm -qa | grep epel
epel-release-6-8.noarch
安装完成后,将在 /etc/yum.repos.d 新增两个 repo 文件:epel.repo、epel-testing.repo。
2.3)文件安装:
其实前两种方法,不论是yum安装也好,或是 rpm 安装也罢,都是要在 /etc/yum.repos.d 中生成 epel.repo 文件。
我们从其他已有的主机copy、或者从网上下一个 epel 源,例如:
[root@test1280 yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.rep
甚至手动编辑 /etc/yum.repos.d/epel.repo 也可以:
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://mirrors.aliyun.com/epel/6/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
3.更新 repo 缓存:yum clean all && yum makecache
如果想了解更多 yum 配置,请继续~~
实验主机环境
[root@test1280 ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@test1280 ~]# uname -a
Linux test1280 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
yum 镜像源配置目录:
[root@test1280 ~]# tree /etc/yum.repos.d
/etc/yum.repos.d
├── CentOS-Base.repo
├── CentOS-Debuginfo.repo
├── CentOS-fasttrack.repo
├── CentOS-Media.repo
└── CentOS-Vault.repo
0 directories, 5 files
在 /etc/yum.repos.d 目录中,以 .repo 结尾的文件,都会被 yum 读取。
每个 repo 配置文件都包含多个镜像源信息,例如[base]、[updates]、[extras]等等。
可以通过 yum repolist 查看当前 有效的 镜像源:
[root@test1280 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.zju.edu.cn
* extras: mirror.lzu.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
repo id repo name status
base CentOS-6 - Base 6,713
extras CentOS-6 - Extras 46
updates CentOS-6 - Updates 708
repolist: 7,467
为什么说是 “有效的” 呢?
因为,在 repo 文件中配置的镜像源,可以通过设置 enabled=0 “禁用”,例如:
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
若镜像源无 enabled 配置时,默认启用,即“有效的”。
如果要查看所有的镜像源,可以执行 yum repolist all ,如下:
输出中的三列分别是:
- repo id:镜像源唯一标识,例如[base]、[updates]…
- repo name:镜像源描述信息,取自镜像源中name字段值
- status:启用状态,取自镜像源中enabled字段值
例如:
[base]
name=CentOS-$releasever - Base
这个镜像源中,base就是镜像源唯一标识id,name是一串描述信息。
在 /etc/yum.repos.d 中的所有 repo 配置文件中的镜像源id不可重复,是唯一的。
yum 在 install、update 等命令时,会依据 yum repo 缓存连接镜像源,而不是读取配置文件 /etc/yum.repos.d 中的 repo 配置。
可以通过以下命令清空 yum repo 缓存:
yum clean all
[root@test1280 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base extras updates
Cleaning up Everything
可以通过以下命令创建 yum repo 缓存:
yum makecache
[root@test1280 yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
* base: mirrors.cn99.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
base | 3.7 kB 00:00
base/group_gz | 242 kB 00:00
base/filelists_db | 6.4 MB 00:18
base/primary_db | 4.7 MB 00:13
base/other_db | 2.8 MB 00:07
extras | 3.4 kB 00:00
extras/filelists_db | 24 kB 00:00
extras/prestodelta | 2.2 kB 00:00
extras/primary_db | 29 kB 00:00
extras/other_db | 14 kB 00:00
updates | 3.4 kB 00:00
updates/filelists_db | 4.7 MB 00:13
updates/prestodelta | 236 kB 00:00
updates/primary_db | 6.6 MB 00:18
updates/other_db | 303 kB 00:00
Metadata Cache Created
镜像配置 mirrorlist 和 baseurl 区别
[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/
mirrorlist 从名字含义看是镜像源的集合(list),其中包含 releasever、arch、basearch等变量。
那这些变量值是多少呢?
查看 /etc/yum.conf 配置中 cachedir 字段:
[root@test1280 ~]# cat /etc/yum.conf | grep cachedir
cachedir=/var/cache/yum/$basearch/$releasever
查找本机 /var/cache/yum:
[root@test1280 ~]# tree /var/cache/yum -L 2
/var/cache/yum
└── x86_64
└── 6
2 directories, 0 files
可知,basearch=x86_64,releasever=6。
使用变量值替换 mirrorlist,访问:
http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=
将会获得一个镜像源的集合:
http://centos.ustc.edu.cn/centos/6.10/os/x86_64/
http://ap.stykers.moe/centos/6.10/os/x86_64/
http://mirrors.163.com/centos/6.10/os/x86_64/
http://mirror.jdcloud.com/centos/6.10/os/x86_64/
http://mirrors.huaweicloud.com/centos/6.10/os/x86_64/
http://mirrors.cn99.com/centos/6.10/os/x86_64/
http://mirrors.aliyun.com/centos/6.10/os/x86_64/
http://mirrors.njupt.edu.cn/centos/6.10/os/x86_64/
http://mirrors.tuna.tsinghua.edu.cn/centos/6.10/os/x86_64/
http://mirrors.nju.edu.cn/centos/6.10/os/x86_64/
man yum.conf:
- mirrorlist:
mirrorlist Specifies a URL to a file containing a list of baseurls. This can be used instead of or with the baseurl option. - baseurl:
Must be a URL to the directory where the yum repository’s ‘repodata’ directory lives.
更多请参见 man yum.conf.
所以我们可以使用 mirrorlist 中的一个镜像地址设置为我们的 baseurl。
如果 mirrorlist 中的一个镜像地址不能访问,我们可以获取一个有效的镜像源。
A base URL is the link to a certain repository, containing packages for installation.
Those same packages are mirrored into different servers to increase availability, e.g. if a server goes down or is overloaded, packages can be fectched from other mirrors.
参考
1.https://www.cnblogs.com/liuxingke/articles/9888846.html
2.https://www.itread01.com/content/1551717496.html
3.https://www.quora.com/What-is-the-difference-between-base-URL-and-mirrorlist-in-Yum
4.https://serverfault.com/questions/892354/what-is-the-difference-between-base-url-and-mirrorlist-in-yum
5.https://www.cnblogs.com/mrnx2004/p/10473404.html
6.https://lists.centos.org/pipermail/centos/2005-October/011738.html
7.https://blog.csdn.net/yasi_xi/article/details/11746255
8.https://linux.cn/article-2324-1.html
9.https://www.cnblogs.com/fps2tao/p/7580188.html
10.https://blog.51cto.com/liuqun/1984107
11.https://blog.huzhifeng.com/2016/12/16/EPEL/
12.https://mirror.tuna.tsinghua.edu.cn/help/epel/
更多推荐
所有评论(0)