How to Build a Fast Local Yum Repository on CentOS and Switch to Domestic Mirrors
This guide walks through creating a local CentOS Yum repository from an ISO image, backing up the default repo files, mounting the ISO, configuring a local repo, switching to Aliyun or 163 mirrors, setting repository priorities with yum‑plugin‑priorities, and testing package installation to ensure the local source is used first.
1. View the default Yum repository files
# ll /etc/yum.repos.d/2. (Optional) Backup the existing Yum repository files
# mkdir /opt/centos-yum.bak
# mv /etc/yum.repos.d/* /opt/centos-yum.bak/3. Mount the CentOS ISO image in the virtual machine
# mount -t iso9660 /dev/sr0 /opt/centos4. Create a repo file that points to the mounted ISO
# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=05. Clean the Yum cache and rebuild it
# yum clean all
# yum makecache6. Replace the default repo with the Aliyun mirror
Download the appropriate Aliyun repo file for your CentOS version and overwrite the existing CentOS-Base.repo:
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # yum clean all
# yum makecache7. Replace the default repo with the 163 mirror
Download the 163 repo file for your CentOS version:
# wget -O /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo # yum clean all
# yum makecache8. Set repository priority so the local repo is preferred
Install the priority plugin and configure it:
# yum -y install yum-plugin-priorities.noarch # cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1Add priority=1 to the local repo (lower numbers mean higher priority):
# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
priority=19. Test package installation before and after setting priority
Before priority (using Aliyun repo):
# yum -y install vim
# ... package is pulled from the "updates" repositoryAfter priority (using local repo):
# yum -y install vim
# ... package and all dependencies are resolved from the "local" repositoryThese steps provide a fast, offline Yum source and ensure it is used preferentially over external mirrors.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
