CentOS yum源设置priority优先查找本地源安装
CentOS的yum在安装时默认是将/etc/yum.repos.d/目录下.repo后缀文件都查找,然后用找到的第一个源。
如果安装有网络的源和光盘cdrom的源,在列表中CentOS-Base.repo被先找到,这里是网络源。那么光盘就不会在被安装。
可以设置文件优先级来让yum先搜索优先级高的,我们设置CentOS-Media.repo文件高,CentOS-Base.repo次之。
安装yum-priorities 来管理优先级
1 | [root@Cent0S7 ]yum -y install yum-priorities |
文件优先级设置,priority=N # N值为1-99,数字越大,优先级越低.(如果repo文件项里不写priority那默认是99,最低。)
注意:priority=1这个要放到repo文件的项里,和enabled一样;而不是一个repo文件里放一个priority=1,另一个文件放priority=2就是priority=1文件优先级高了.
以 163.repo和aliyun.repo文件做例子,在[base_aliyun]项下和[base_163]分别放了priority代表,当使用到base里的链接时,优先使用[base_aliyun]项下地址。
其他项也是一样,当然如果有些链接报错感觉没用,直接在项下加入 enabled=0 关闭此项即可。
1 | [root@Cent0S7 ~] # vi /etc/yum.repos.d/aliyun.repo |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [base_aliyun] name=CentOS-$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http: //mirrors .aliyun.com /centos/ $releasever /os/ $basearch/ http: //mirrors .aliyuncs.com /centos/ $releasever /os/ $basearch/ http: //mirrors .cloud.aliyuncs.com /centos/ $releasever /os/ $basearch/ gpgcheck=1 gpgkey=http: //mirrors .aliyun.com /centos/RPM-GPG-KEY-CentOS-7 <strong>priority=1< /strong > [updates_aliyun] name=CentOS-$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http: //mirrors .aliyun.com /centos/ $releasever /updates/ $basearch/ http: //mirrors .aliyuncs.com /centos/ $releasever /updates/ $basearch/ http: //mirrors .cloud.aliyuncs.com /centos/ $releasever /updates/ $basearch/ gpgcheck=1 gpgkey=http: //mirrors .aliyun.com /centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful |
1 | [root@Cent0S7 ~] # vi /etc/yum.repos.d/163.repo |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [base_163] 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 <strong>priority=2< /strong > [updates_163] 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 |
启用CentOS-Media 这个光盘源
1 | [root@Cent0S7 ~] # sed -i 's/enabled=0/enabled=1/g' /etc/yum.repos.d/CentOS-Media.repo |
安装httpd来测试:
网络和光盘Iso都设置好,没有设置优先级:
可以看到 Repository里是base也就是网络的源。
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 | [root@Cent0S7 yum.repos.d] # yum install httpd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * c7-media: * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check <br>---- 中间略 ---- Dependencies Resolved ===================================================================================================================== Package Arch Version Repository Size ===================================================================================================================== Installing: httpd x86_64 2.4.6-97.el7.centos updates 2.7 M Installing for dependencies: apr x86_64 1.4.8-7.el7 base 104 k apr-util x86_64 1.5.2-6.el7 base 92 k httpd-tools x86_64 2.4.6-97.el7.centos updates 93 k mailcap noarch 2.1.41-2.el7 base 31 k Transaction Summary ===================================================================================================================== Install 1 Package (+4 Dependent packages) Total download size: 3.0 M Installed size: 10 M Is this ok [y /d/N ]: |
设置优先级后:
可以看到先搜索c7-media 也就是光盘里 c7-media是repo文件里设置的name可以随意改。
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 | [root@Cent0S7 yum.repos.d] # yum install httpd Loaded plugins: fastestmirror, priorities Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * c7-media: * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 10867 packages excluded due to repository priority protections Resolving Dependencies --> Running transaction check <br>---- 中间略 ---- Dependencies Resolved ===================================================================================================================== Package Arch Version Repository Size ===================================================================================================================== Installing: httpd x86_64 2.4.6-93.el7.centos c7-media 2.7 M Installing for dependencies: apr x86_64 1.4.8-5.el7 c7-media 103 k apr-util x86_64 1.5.2-6.el7 c7-media 92 k httpd-tools x86_64 2.4.6-93.el7.centos c7-media 92 k mailcap noarch 2.1.41-2.el7 c7-media 31 k Transaction Summary ===================================================================================================================== Install 1 Package (+4 Dependent packages) Total download size: 3.0 M Installed size: 10 M Is this ok [y /d/N ]: |
查看列表
1 | [root@Cent0S7 ] # yum repolist |
统计安装包个数
1 2 | [root@Cent0S7 ] # yum list | wc -l 10498 |
脚本安装:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [root@Cent0S7 ] # cat <<EOF | sudo tee yum-localrepo.sh #! /bin/bash mkdir -p /media/cdrom/ mount /dev/cdrom /media/cdrom/ echo "/dev/cdrom /mnt/cdrom iso9660 defaults 0 0" >> /etc/fstab sed -i 's/enabled=0/enabled=1/g' /etc/yum.repos.d/CentOS-Media.repo echo "priority=1" >> /etc/yum.repos.d/CentOS-Media.repo echo "priority=2" >> /etc/yum.repos.d/CentOS-Base.repo yum -y install yum-priorities yum makecache EOF |
执行脚本:
1 | [root@CentOs7] # sh yum-localrepo.sh |
参考:
http://cnblogs.com/mountain2011/p/10224350.html
1 | aliyun |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!