Centos7.4配置本地yum源和阿里源并配置yum优先级

一、用Centos镜像搭建本地yum源

安装完linux系统的默认yum源为centos的官方地址,在“国内的特殊环境”下使用很慢甚至无法访问,所以一般的做法都是把默认的yum源替换成aliyun的yum源或者163等国内的yum源。
但是以上的方法都是需要网络的,当没有网络的时候就无法使用了,所以还有一个常用的方法就是用Centos的iso镜像搭建本地yum源,这样安装软件的速度就会飞快,缺点是可能有些需要的包文件本地里没有。


# 1.安装Centos后默认的yum源如下

 [root@localhost ~]# ll /etc/yum.repos.d/
 total 32
 -rw-r--r--. 1 root root 1664 Dec  9  2015 CentOS-Base.repo
 -rw-r--r--. 1 root root 1309 Dec  9  2015 CentOS-CR.repo
 -rw-r--r--. 1 root root  649 Dec  9  2015 CentOS-Debuginfo.repo
 -rw-r--r--. 1 root root  290 Dec  9  2015 CentOS-fasttrack.repo
 -rw-r--r--. 1 root root  630 Dec  9  2015 CentOS-Media.repo
 -rw-r--r--. 1 root root 1331 Dec  9  2015 CentOS-Sources.repo
 -rw-r--r--. 1 root root 1952 Dec  9  2015 CentOS-Vault.repo

# 2.把默认yum源备份并建立新yum源

Centos7.4配置本地yum源和阿里源并配置yum优先级


# 3.在虚拟机上挂在Centos镜像文件
Centos7.4配置本地yum源和阿里源并配置yum优先级

[root@localhost ~]#mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only


# 4.编写repo文件并指向镜像的挂在目录

vim bendi.repo
[bash]  #库名
name=bash  #库名 (这一行其实可以不用写,用 yum reipolist会报个错但不影响使用)
baseurl=file:///mnt/  #“源所在路径”
enabled=1  #1为启动0为不启用
gpgcheck=0  #检查签名1为检测0为不检测


# 5.清除缓存

[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: local
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost ~]# yum makecache        //把yum源缓存到本地,加快软件的搜索好安装速度
[rroot@localhost ~]# yum list     

二、把默认的CentOS yum源修改成国内的aliyun yum源

这里是阿里云官方教程地址


# 1.下载aliyun yum源repo文件(对应自己的系统版本下载即可,需有外网)

#各系统版本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


# 2.清楚缓存

[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost ~]# yum makecache        //把yum源缓存到本地,加快软件的搜索好安装速度
[root@localhost ~]# yum list

三、修改yum源的优先级

ps:当既有本地yum源又有163源的时候,我们在装软件包的时候当然希望先用本地的yum源去安装,本地找不到可用的包时再使用163源去安装软件,这里就涉及到了优先级的问题,yum提供的插件yum-plugin-priorities.noarch可以解决这个问题


1.查看是否安装了yum-plugin优先级插件

[root@localhost ~]#rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.31-42.el7.noarch
yum-plugin-priorities-1.1.31-42.el7.noarch

之前我安装过所以能查到,如果未查到请按照以下方法安装

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

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


3.查看插件是否启用

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


4.修改本地yum源优先使用

[cal]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0
priority=1
//在原基础上加入priority=1 ;数字越小优先级越高
//可以继续修改其他源的priority值,经测试仅配置本地源的优先级为priority=1就会优先使用本地源了


Centos7.4配置本地yum源和阿里源并配置yum优先级


5.验证安装包的数量
执行yum repolist all 可显示所有仓库包
Centos7.4配置本地yum源和阿里源并配置yum优先级

转载于:https://blog.51cto.com/11566825/2072949

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1.查看系统本身存在的版本 rpm -qa | grep yum 2.卸载centos7上存在的yum安装包 rpm -e 包 --nodeps 3.下载yum源包(http://mirrors.163.com/centos/7/os/x86_64/Packages/) yum-metadata-parser-1.1.4-10.el7.x86_64 PackageKit-yum-1.0.7-6.el7.centos.x86_64 yum-utils-1.1.31-40.el7.noarch 下方两个一起装 yum-plugin-fastestmirror-1.1.31-40.el7.noarch yum-langpacks-0.4.2-7.el7.noarch yum-3.4.3-150.el7.centos.noarch yum-rhn-plugin-2.0.1-6.el7.noarch 4.安装yum源包 rpm -ivh yum* 5.创建配置文件(/etc/yum.repos.d/CentOS-Base.repo) vi /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=os baseurl=http://mirrors.163.com/centos/(系统版本号)7/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/7/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/7/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=$releasever - Plus - 163.com baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 每一个baseurl的centos后都改成自己系统的版本号 6.执行命令 yum clean all yum makecache yum install telnet

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值