In enterprise environments with multiple RHEL-based systems (CentOS, Fedora, etc.), having each machine download packages individually from remote repositories creates unnecessary bandwidth consumption and slows down updates. A local YUM cache server solves this by:
- Downloading packages once from the internet
- Serving them to all machines on your LAN
- Supporting multiple distribution versions (CentOS 7/8, Fedora 30+)
1. A dedicated server with sufficient storage (recommend 50GB+ for base repos) 2. Web server (Apache/Nginx) or FTP server 3. createrepo package 4. Regular sync automation
1. Install Required Packages
sudo yum install -y yum-utils createrepo httpd
2. Configure Repository Synchronization
Create a sync script (/usr/local/bin/sync_repos.sh
):
#!/bin/bash
REPO_DIR="/var/www/html/repos"
REPOS=("base" "updates" "extras") # Add your required repos
for repo in "${REPOS[@]}"; do
reposync --gpgcheck -l --repoid=${repo} --download_path=${REPO_DIR}
createrepo -v ${REPO_DIR}/${repo} -o ${REPO_DIR}/${repo}
done
3. Set Up Cron for Automatic Updates
# Add to crontab (run daily at 2AM)
0 2 * * * /usr/local/bin/sync_repos.sh
4. Configure Web Server
Basic Apache configuration (/etc/httpd/conf.d/repos.conf
):
Alias /repos /var/www/html/repos
<Directory "/var/www/html/repos">
Options Indexes FollowSymLinks
Require all granted
</Directory>
Create a client repo file (/etc/yum.repos.d/local.repo
):
[local-base]
name=Local Base Repo
baseurl=http://yum-cache-server/repos/base
enabled=1
gpgcheck=0
[local-updates]
name=Local Updates
baseurl=http://yum-cache-server/repos/updates
enabled=1
gpgcheck=0
Version-Specific Repositories
For multiple CentOS versions (7 and 8):
reposync --gpgcheck -l --repoid=base7 --download_path=${REPO_DIR}/centos7
reposync --gpgcheck -l --repoid=base8 --download_path=${REPO_DIR}/centos8
Bandwidth Throttling
Add to sync script for controlled downloads:
reposync --gpgcheck -l --repoid=${repo} --download_path=${REPO_DIR} --limit-rate=1m
- Metadata Errors: Run
createrepo --update
on the repo directory - Permission Issues: Ensure
httpd_sys_content_t
context on repo files - Sync Failures: Check repository mirrors in
/etc/yum.repos.d/
In enterprise environments with multiple RHEL-based systems, a local YUM cache server significantly reduces bandwidth usage and speeds up package installations. Unlike Ubuntu's Apt-Cacher, RHEL distributions require a different approach using either yum-cron
or createrepo
tools.
Before setting up your cache server:
- A dedicated CentOS/RHEL 7/8/9 server with 50GB+ free space
- Root access to configure services
- Basic firewall rules for HTTP traffic (port 80/8080)
- Clients sharing the same architecture (x86_64, etc.)
First, install required packages:
yum install yum-utils createrepo httpd -y
systemctl enable --now httpd
Create the repository directory structure:
mkdir -p /var/www/html/repos/{base,updates,extras}
reposync -p /var/www/html/repos/base -r base
reposync -p /var/www/html/repos/updates -r updates
createrepo /var/www/html/repos/base
createrepo /var/www/html/repos/updates
Create a cron job to nightly sync repositories:
#!/bin/bash
reposync -p /var/www/html/repos/base -r base --download-metadata
reposync -p /var/www/html/repos/updates -r updates --download-metadata
createrepo --update /var/www/html/repos/base
createrepo --update /var/www/html/repos/updates
On client machines, create a repo file at /etc/yum.repos.d/local.repo
:
[local-base]
name=Local Base
baseurl=http://yum-cache-server/repos/base
enabled=1
gpgcheck=0
[local-updates]
name=Local Updates
baseurl=http://yum-cache-server/repos/updates
enabled=1
gpgcheck=0
For better performance:
- Use
hardlink
to save disk space:yum install hardlink -y
- Implement
nginx
instead of Apache for high traffic - Set up
failover
mirrors in client configs
If clients report missing packages:
yum clean all
yum makecache
repoclosure --repo=local-base --repo=local-updates