The Benefits of a Local Yum Repository
In enterprise environments where CentOS Linux servers may be isolated from the internet for security reasons, patching and installing software becomes a challenge. Setting up a local YUM (Yellowdog Updater, Modified) repository allows you to host packages on a centralized internal server, significantly speeding up package deployment and conserving external bandwidth.
Step 1: Install Required Packages
Log in to the server that will host the repository. You will need a web server to serve the files and the createrepo utility to generate the repository metadata. Install them using:
sudo yum install httpd createrepo -y
Step 2: Configure the Web Server
Start the Apache web server and enable it to run at boot:
sudo systemctl start httpdsudo systemctl enable httpd
If you have a firewall active, allow HTTP traffic:
sudo firewall-cmd --permanent --add-service=httpsudo firewall-cmd --reload
Step 3: Create the Repository Directory and Copy Packages
Create a directory within the Apache document root to hold your RPM packages:
sudo mkdir -p /var/www/html/localrepo
Copy all your required .rpm files into this directory. If you are syncing from an installation DVD, mount the ISO and copy the contents of the Packages folder.
Step 4: Generate the Repository Metadata
YUM requires metadata to understand package dependencies and versions. Navigate to the repository directory and use the createrepo command to build this metadata:
cd /var/www/html/localreposudo createrepo .
This process will create a new folder named repodata containing the XML metadata files.
Step 5: Configure Client Servers to Use the Local Repo
On your client CentOS machines, navigate to the YUM repository configuration directory (/etc/yum.repos.d/) and create a new .repo file:
sudo nano /etc/yum.repos.d/local.repo
Add the following configuration, replacing the IP address with your repository server’s IP:
[localrepo]
name=Local CentOS Repository
baseurl=http://192.168.1.50/localrepo/
enabled=1
gpgcheck=0
Clean the YUM cache and verify the new repository is visible:
sudo yum clean allsudo yum repolist