Note: All three methods should be preceded by an action
1. The default yum source after Centos installation is as follows
[root@kangvcar ~]# 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. Back up or delete the default or original yum source directly (optional)
[root@kangvcar ~]# mkdir /opt/centos-yum.bak
[root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/
Local yum source configuration
Step 1: Mount the CentOS image file on the virtual machine
[root@kangvcar ~]# mount -t iso9660 /dev/sr0 /opt/centos
mount: /dev/sr0 is write-protected, mounting read-only
Step 2: Write a repo file and point to the mirror mount directory
[root@kangvcar ~]# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
Step 3: Run yum makecache to generate the cache
yum clean all
Run yum makecache to generate cache
yum makecache
Update System
yum -y update
Substitute yum Source for Ali Cloud Source under Centos
Official Aliyun Tutorial: http://mirrors.aliyun.com/help/centos
Ali Cloud Linux Installation Mirror Source Address: http://mirrors.aliyun.com/
Step 1: Download CentOS-Base.repo to/etc/yum.repos.d/
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
Step 2: Run yum makecache to generate the cache
yum clean all
Run yum makecache to generate cache
yum makecache
Update System
yum -y update
Replace yum source under Centos with domestic source 163
163 Official Tutorial: http://mirrors.163.com/.help/centos.html
Step 1: Download the 163 yum source repo file
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
Step 2: Run yum makecache to generate the cache
yum clean all
Run yum makecache to generate cache
yum makecache
Update System
yum -y update
Modify priority of yum source
ps: When installing packages with both local Yum source and 163 source, of course, we want to install the packages with the local Yum source first, and install the software with the 163 source when the available packages are not found locally. This involves priority issues, which can be solved by the plug-in yum-plugin-priorities.noarch provided by yum.
First: Check to see if the system has priority plug-ins installed
[root@kangvcar ~]# rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.31-34.el7.noarch
//You can see here that yum-plugin-priorities is not installed.noarchThis plugin
[root@kangvcar ~]# yum search yum-plugin-priorities
//Use search to see if this plug-in is available
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
Second: Install the yum-plugin-priorities.noarch plugin
[root@kangvcar ~]# yum -y install yum-plugin-priorities.noarch
Third: Check if the plug-in is enabled
[root@kangvcar ~]# cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1
//1 is enabled; 0 is disabled
Fourth: Modify local yum source to take precedence
[root@kangvcar ~]# 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
//There are two repo files
[root@kangvcar ~]# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
priority=1
//Add priority=1 to the original; the smaller the number, the higher the priority
//You can continue to modify the priority values of other sources, and after testing, configuring only local sources with priority=1 will give priority to local sources
Fifth: Testing
Before configuring priority: (use Ali yum source)
[root@kangvcar ~]# yum -y install vim Dependencies 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 ······ ······ ······
After configuring priority: (using local yum source)
[root@kangvcar ~]# yum -y install vim
Dependencies 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
······
······
······