码迷,mamicode.com
首页 > 其他好文 > 详细

CentOS配置本地yum源,网络源以及优先级

时间:2018-03-07 00:45:39      阅读:438      评论:0      收藏:0      [点我收藏+]

标签:yum   linux   

1.用Centos镜像搭建本地yum源

在配置网络yum之前我们先卸载旧的yum,并下载CentOS的对应软件包安装,这一步配置yum源都要操作

[root@localhost tools]# rpm -aq|grep yum
yum-metadata-parser-1.1.2-16.el6.x86_64
yum-rhn-plugin-0.9.1-58.el6.noarch
yum-3.2.29-69.el6.noarch
[root@localhost tools]# rpm -aq|grep yum|xargs rpm -e --nodeps
[root@localhost tools]# 
[root@localhost tools]# rpm -aq|grep yum|xargs rpm -e --nodeps
rpm: no packages given for erase

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm

[root@localhost ~]# cd /home/linzhongniao/tools/
[root@localhost tools]# ls
yum-3.2.29-81.el6.centos.noarch.rpm  python-iniparse-0.3.1-2.1.el6.noarch.rpm   yum-metadata-parser-1.1.2-16.el6.x86_64.rpmpython-urlgrabber-3.9.1-11.el6.noarch.rpm  yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
[root@localhost tools]# rpm -ivh *

1.1 安装完centos后默认的yum源如下

[root@localhost yum.repos.d]# ll
总用量 24
 -rw-r--r--. 1 root root 1991 5月  19 2016 CentOS-Base.repo
 -rw-r--r--. 1 root root  647 5月  19 2016 CentOS-Debuginfo.repo
 -rw-r--r--. 1 root root  289 5月  19 2016 CentOS-fasttrack.repo
 -rw-r--r--. 1 root root  630 5月  19 2016 CentOS-Media.repo
 -rw-r--r--. 1 root root 6259 5月  19 2016 CentOS-Vault.repo

1.2 备份默认yum源

[root@localhost ~]# mkdir -p /home/yum.repos.d
[root@localhost ~]# mv /etc/yum.repos.d/* /home/yum.repos.d/ 

1.3 编写repo文件 并指向镜像的挂载目录

[root@localhost ~]# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# vi /etc/yum.repos.d/local.repo

[local]
name=local
baseurl=file:///media/
enabled=1
gpgcheck=0

1.4 清楚缓存

[root@localhost ~]# yum clean all
已加载插件:fastestmirror
Cleaning repos: local
清理一切
Cleaning up list of fastest mirrors

1.5 将yum源缓存到本地,加快安装速度

[root@localhost ~]# yum makecache
已加载插件:fastestmirror
Determining fastest mirrors
local  | 4.0 kB 00:00 ... 
local/group_gz | 226 kB 00:00 ... 
local/filelists_db | 6.3 MB 00:00 ... 
local/primary_db   | 4.7 MB 00:00 ... 
local/other_db | 2.8 MB 00:00 ... 
元数据缓存已建立

1.6 列出软件包

[root@localhost ~]# yum list

2.将默认的yum源改成aliyun yum源

阿里云官方教程:http://mirrors.aliyun.com/help/centos

2.1 备份yum源

[root@localhost ~]# mv /etc/yum.repos.d/* /home/yum.repos.d/

2.2 下载aliyun yum源repo文件对应自己系统下载

各系统对应的yum源repo文件

CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo 
或者 
curl -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 
或者 
curl -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 
或者 
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 

[root@localhost ~]# cat /etc/redhat-release  查看系统版本
CentOS release 6.8 (Final)
[root@localhost ~]# wget -o /etc/yum.repos.d/centos.repo  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

[root@localhost ~]# wget -o /etc/yum.repos.d/centos.txt  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[root@localhost ~]# ll /etc/yum.repos.d/
总用量 8
 -rw-r--r--. 1 root root 2572 7月   2 2014 CentOS-Base.repo
 -rw-r--r--. 1 root root  793 3月   7 04:53 centos.txt

2.3 清除缓存

[root@localhost ~]# yum clean all
已加载插件:fastestmirror
Cleaning repos: local
清理一切
Cleaning up list of fastest mirrors
[root@localhost ~]# yum makecache 把yum源缓存到本地,加快安装速度
已加载插件:fastestmirror
Determining fastest mirrors
local  | 4.0 kB 00:00 ... 
local/group_gz | 226 kB 00:00 ... 
local/filelists_db | 6.3 MB 00:00 ... 
local/primary_db   | 4.7 MB 00:00 ... 
local/other_db | 2.8 MB 00:00 ... 
[root@localhost ~]# yum list

3.把默认centos yum源换成163源

163官方教程:http://mirrors.163.com/.help/centos.html

3.1 Centos默认yum源如下

[root@localhost yum.repos.d]# ll
 总用量 24
 -rw-r--r--. 1 root root 1991 5月  19 2016 CentOS-Base.repo
 -rw-r--r--. 1 root root  647 5月  19 2016 CentOS-Debuginfo.repo
 -rw-r--r--. 1 root root  289 5月  19 2016 CentOS-fasttrack.repo
 -rw-r--r--. 1 root root  630 5月  19 2016 CentOS-Media.repo
 -rw-r--r--. 1 root root 6259 5月  19 2016 CentOS-Vault.repo

3.2 备份yum源文件

[root@localhost ~]# mv /etc/yum.repos.d/* /home/yum.repos.d/

3.3 下载163 yum源repo文件

各系统版本对应的repo文件

CentOS 5
wget -O /etc/yum.repos.d/CentOS5-Base-163.repo http://mirrors.163.com/.help/CentOS5-Base-163.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS6-Base-163.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

[root@localhost ~]# cat /etc/redhat-release  查看系统版本
CentOS release 6.8 (Final)
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS6-Base-163.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
 --2018-03-07 06:11:02--  http://mirrors.163.com/.help/CentOS6-Base-163.repo
正在解析主机 mirrors.163.com... 59.111.0.251
正在连接 mirrors.163.com|59.111.0.251|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2006 (2.0K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS6-Base-163.repo”
100%[============================================================================================>] 2,006   --.-K/s   in 0.001s  
2018-03-07 06:11:03 (1.97 MB/s) - 已保存 “/etc/yum.repos.d/CentOS6-Base-163.repo” [2006/2006])

[root@localhost ~]# ll /etc/yum.repos.d/
总用量 4
 -rw-r--r--. 1 root root 2006 12月  1 2016 CentOS6-Base-163.repo

3.4 清除缓存

[root@localhost ~]# yum clean all
已加载插件:fastestmirror
Cleaning repos: local
清理一切
Cleaning up list of fastest mirrors
[root@localhost ~]# yum makecache 把yum源缓存到本地,加快安装速度
已加载插件:fastestmirror
Determining fastest mirrors
local  | 4.0 kB 00:00 ... 
local/group_gz | 226 kB 00:00 ... 
local/filelists_db | 6.3 MB 00:00 ... 
local/primary_db   | 4.7 MB 00:00 ... 
local/other_db | 2.8 MB 00:00 ... 
[root@localhost ~]# yum list

4.修改yum源的优先级

当既有本地源又有网络源的时候,我们安装软件的时候当然希望按着本地yum源去安装,当找不到安装包的时候在用网络软安装,那么这里就涉及了一个优先级的问题。

4.1 查看是否安装了优先级的插件

[root@localhost ~]# rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.30-37.el6.noarch

我们看没有安装yum-plugin-priorities.noarch这个插件

4.2 安装yum-plugin-priorities.noarch插件

[root@localhost ~]# yum install yum-plugin-priorities.noarch -y

4.3 查看插件是否可用

[root@localhost ~]# cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1  1表示可用,0为禁用

4.4 修改本地yum源优先使用

[root@localhost ~]# cp /home/yum.repos.d/local.repo /etc/yum.repos.d/
[root@localhost ~]# ll /etc/yum.repos.d/
总用量 8
-rw-r--r--. 1 root root 2006 12月  1 2016 CentOS6-Base-163.repo
-rw-r--r--. 1 root root   63 3月   7 06:34 local.repo
[root@localhost ~]# cat /etc/yum.repos.d/local.repo 
[local]
name=local
baseurl=file:///media/
enabled=1
gpgcheck=0
priority=1

添加priority=1,数字越小优先级越高,也可以修改网络源的priority的值

CentOS配置本地yum源,网络源以及优先级

标签:yum   linux   

原文地址:http://blog.51cto.com/10642812/2083645

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!