CentOS configures local yum source/Alibaba Cloud yum source/163yuan source, and configures the priority of yum source
table of Contents
Article Directory
- CentOS configures local yum source/Alibaba Cloud yum source/163yuan source, and configures the priority of yum source
- table of Contents
- 1. Use Centos mirroring to build local yum source
- 2. Modify the default CentOS yum source to the domestic aliyun-yum source
- 3. Modify the default CentOS yum source to the domestic 163 source
- Fourth, modify the priority of yum source
1. Use Centos mirroring to build local yum source
1. The default yum source after installing Centos is as follows
# ll /etc/yum.repos.d/
2. Back up the default yum source (optional)
# cp CentOS-Base.repo CentOS-Base-cp.repo
3. Mount the CentOS image file on the virtual machine
# (1) mount -t iso9660 /dev/sr0 /opt/centos
# (2) mount /dev/cdrom /mnt/cdrom
4.编写repo文件并指向镜像的挂载目录
# cd /etc/yum.repos.d/
# vi local.repo //自定义配置文件名
[local] //标签
name=local //设置yum源名称
baseurl=file:///opt/centos //挂载源
enabled=1 //可用性
gpgcheck=0 //校验
5. Clear the cache
# yum clean all //全部消除缓存
# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度
# yum repolist //列出****个包
2. Modify the default CentOS yum source to the domestic aliyun-yum source
1. Enter the yum directory
# cd /etc/yum.repos.d/
2. Back up the default yum source (optional)
# cp CentOS-Base.repo CentOS-Base-cp.repo
4. Download ailiyun's yum source configuration file to /etc/yum.repos.d/
cat /etc/redhat-release //查看系统的版本
CentOS7
输入:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
CentOS6
输入:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS5
输入:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
If you download ailiyun network error
[root@yu ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-12-20 23:40:05-- http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 116.211.220.240
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|116.211.220.240|:80... 失败:网络不可达。
Add domain name resolution
Please see: Tutorial 2: Linux-Basic Network Configuration
4. Clear the cache
# yum clean all 清除全部缓存
# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度
# yum -y update //更新yum库存
# yum repolist //总共列出了9954个包
3. Modify the default CentOS yum source to the domestic 163 source
1. The default yum source after installing Centos is as follows
1# ll /etc/yum.repos.d/
2. Back up the default yum source (optional)
# cp CentOS-Base.repo CentOS-Base-cp.repo
3. Download the 163 yum source repo file
#各系统版本repo文件对应的下载操作
CentOS 5
wget http://mirrors.163.com/.help/CentOS5-Base-163.repo
CentOS 6
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
CentOS 7
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
1# cat /etc/redhat-release //查看系统的版本
CentOS Linux release 7.2.1511 (Core)
1# wget -O /etc/yum.repos.d/CentOS7-Base-163.repo 这里是一个空格http://mirrors.163.com/.help/CentOS7-Base-163.repo
Saving to: ‘/etc/yum.repos.d/CentOS7-Base-163.repo’100%[=======================================================================================================>] 1,572 --.-K/s in 0s 2017-06-20 06:29:47 (293 MB/s) - ‘/etc/yum.repos.d/CentOS7-Base-163.repo’ saved [1572/1572]
4. Clear the cache
1# yum clean all 清除全部缓存
1# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度
1# yum -y update //更新yum库存
1# yum repolist //总共列出了9954个包
Fourth, modify the priority of yum source
1. Check whether the system has installed priority plug-ins
1# rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.31-34.el7.noarch
//这里看到没有安装yum-plugin-priorities.noarch这个插件
1# yum search yum-plugin-priorities
//用search查看是否有此插件可用
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
====================================================== N/S matched: yum-plugin-priorities =======================================================
yum-plugin-priorities.noarch : plugin to give priorities to packages from different repos
2. Install the yum-plugin-priorities.noarch plugin
1# yum -y install yum-plugin-priorities.noarch
3. Check if the plugin is enabled
1# cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1//1为启用;0为禁用
4. Modify the local yum source first
1# ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 2573 May 15 2015 CentOS-Base.repo
-rw-r--r--. 1 root root 67 Jun 20 06:04 local.repo//有两个repo文件
1# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
priority=1//在原基础上加入priority=1 ;数字越小优先级越高//可以继续修改其他源的priority值,经测试仅配置本地源的优先级为priority=1就会优先使用本地源了
5. Test
配置优先级前:(使用阿里云yum源)
1# yum -y install vimDependencies Resolved
=================================================================================================================================================Package Arch Version Repository Size
=================================================================================================================================================
Installing:
vim-enhanced x86_64 2:7.4.160-1.el7_3.1 updates 1.0 M
Updating for dependencies:
vim-common x86_64 2:7.4.160-1.el7_3.1 updates 5.9 M
省略···
配置优先级后:(使用本地yum源)
1# yum -y install vimDependencies Resolved
=================================================================================================================================================Package Arch Version Repository Size
=================================================================================================================================================
Installing:
vim-enhanced x86_64 2:7.4.160-1.el7 local 1.0 M
Installing for dependencies:
gpm-libs x86_64 1.20.7-5.el7 local 32 k
perl x86_64 4:5.16.3-286.el7 local 8.0 M
perl-Carp noarch 1.26-244.el7 local 19 k
perl-Encode x86_64 2.51-7.el7 local 1.5 M
perl-Exporter noarch 5.68-3.el7 local 28 k
perl-File-Path noarch 2.09-2.el7 local 26 k
perl-File-Temp noarch 0.23.01-3.el7 local 56 k
省略···
local 26 k
perl-File-Temp noarch 0.23.01-3.el7 local 56 k
省略···