How to Configure YUM to Use a Specific Mirror for Faster Package Updates in CentOS


2 views

When working with CentOS (particularly older versions like 6.2), you might notice significant delays during package operations. This occurs because YUM's default mirror selection mechanism isn't always optimal. The system reads from timedhosts.txt which tracks response times, but outdated entries (like those with 99999999999 values) can cripple performance.

For CentOS 6.x systems, you have several approaches to force YUM to use specific mirrors:

Method 1: Editing repo files directly

Modify the base repository file:

sudo vi /etc/yum.repos.d/CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.usc.edu/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

Method 2: Using fastestmirror plugin configuration

Configure the plugin to prefer specific mirrors:

sudo vi /etc/yum/pluginconf.d/fastestmirror.conf

[main]
enabled=1
verbose=0
socket_timeout=3
hostfilepath=/var/cache/yum/timedhosts.txt
maxhostfileage=10
maxthreads=15
# Prefer USC mirror
include_only=.usc.edu

For enterprise environments, consider maintaining a curated mirror list:

sudo vi /etc/yum/vars/mirrorlist

http://mirrors.usc.edu/centos/$releasever/os/$basearch/
http://mirror.sfo12.us.leaseweb.net/centos/$releasever/os/$basearch/
http://mirror.rackspace.com/centos/$releasever/os/$basearch/

After making changes, clear YUM cache and test:

sudo yum clean all
time yum makecache

The time command helps measure improvement. A proper mirror selection should reduce this operation from minutes to seconds.

Create a cron job to periodically verify mirror responsiveness:

#!/bin/bash
MIRRORS=(
    "mirrors.usc.edu"
    "mirror.sfo12.us.leaseweb.net"
    "mirror.rackspace.com"
)

for mirror in "${MIRRORS[@]}"; do
    echo "Testing $mirror..."
    curl -o /dev/null -s -w "%{time_total}\n" http://$mirror/centos/6/os/x86_64/repodata/repomd.xml
done | sort -n > /var/cache/yum/timedhosts.txt

When working with CentOS 6.2 systems, many administrators notice significant delays during package operations. The default YUM mirror selection process can be painfully slow due to:

  • Automatic mirror ranking based on response times
  • Outdated or unresponsive mirrors in the default list
  • The time required to evaluate all available mirrors (often showing 99999999999 timeout values)

To make YUM consistently use USC's mirror (or any other preferred mirror), you'll need to modify these configuration files:

# /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.usc.edu/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

# Disable mirrorlist to prevent auto-selection
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
enabled=1

For systems where you still want mirror flexibility but better performance:

# /etc/yum/pluginconf.d/fastestmirror.conf
[main]
enabled=1
verbose=0
socket_timeout=3
hostfilepath=/var/cache/yum/timedhosts.txt
maxhostfileage=10

After making changes, clear YUM's cache and test the new configuration:

yum clean all
time yum makecache

The time command helps measure the improvement in response time. You should see significantly faster mirror access when using a geographically close mirror like USC's.

For environments with multiple CentOS servers, consider setting up a local mirror:

# Install required packages
yum install yum-utils createrepo

# Sync with USC mirror
reposync -r base -r updates -r extras -p /path/to/local/mirror

# Create repository metadata
for repo in base updates extras; do
  createrepo /path/to/local/mirror/$repo
done