At least one person asked me why I did this, so I’ll start by explaining the motivation for setting up my own mirror of Yum repositories freely available on public-yum.oracle.com.
It comes down to 5 main reasons:
- Wanting my Oracle Linux 6 installation can take advantage of the “latest” repositories
- Wanting the ability to update to a consistent version by using repositories I control
- Reducing the amount of data I download over the internet
- A desire to learn how to set up a Yum repository [mirror]
- Making my updates faster as they only have to retrieve packages from the LAN
When I first looked into setting up a Yum mirror I found a number of articles covering how to do so via rsync and I then found this post where one of the comments suggests that allowing rsync access to public-yum.oracle.com would be nice. This made me realised that the rsync approach wasn’t going to work for the Oracle Linux repositories (it seems the suggestion was well received so this may change in the future). I also found a OTN article covering “How to Create a Local Yum Repository for Oracle Linux“. I eagerly started to read and quickly hit a snag for me in the prerequisites section:
Have valid customer support identifier (CSI)
I don’t have a CSI. My customers all have CSIs, because they run Oracle in production. I don’t have a CSI as I only run the OTN versions of Oracle software in my lab so that I can test out things I don’t have opportunity, access or time to test on client sites.
Anyway, with a little bit of reading around I found a way to create local mirrors of the Oracle Linux 6 Latest and Oracle UEK Latest repositories.
What follows was carried out on a VM, but there is no reason why any of this won’t work equally on a physical host. If you encounter any problem replicating what I’ve done here then please comment and I’ll gladly try to help.
1) Allocating Storage
You’re going to need a reasonable amount of storage for this. My “repos” file system currently holds 24G of data and that is just for Oracle Linux 6 Latest and Oracle UEK Latest. I created a dedicated file system for my repositories on a LVM volume, but won’t cover that here. Allocate the storage as you see fit, but you’re going to want at least the 24G quoted.
2) Create Directory For Repos
As mentioned above, I have a dedicated file system for my repositories. It’s mounted under /repos and I’ll include that in all the code listings that follow. If you chose to use a different directory structure then clearly you’ll need to make the required changes.
# mkdir -p /repos/x86_64/
3) Install yum-utils
yum-utils includes a couple of commands you’re going to need for this, reposync and createrepo.
# yum -y install yum-utils
4) Setup Repositories
Follow the instructions on public-yum.oracle.com in order to set up the Oracle repositories.
By default reposync will create a local copy of all your enabled repositories, but it is also possible to specify the name of the repo[s] you want to sync on the command line using the “r” or “repoid” flag. I use this option as I want to have my local repositories enabled on all my Oracle Linux 6 hosts, including the repository machine, but only want reposync to run for the public-yum.oracle.com repositories I want to mirror locally. This means that I do not enable any of the repositories in the public-yum-ol6.repo file downloaded from Oracle and create a new .repo file for my local repositories that I can distribute to all machines.
5) Run reposync
Running reposync is as simple as the command below:
# /usr/bin/reposync --repoid=ol6_UEK_latest --repoid=ol6_latest -p /repos/x86_64
6) Run createrepo
Once the repositories are downloaded to the local file system you need to run createrepo in order to create the repository metadata:
# createrepo /repos/x86_64/ol6_UEK_latest/getPackage/ # createrepo /repos/x86_64/ol6_latest/getPackage/
The “update” option for createrepo looked attractive in the man page, but whenever I used it the process was killed by the OOM Killer and I haven’t investigated in detail.
7) Allowing Web Access
In order to make use of the repositories they need to be exposed to the machines requiring access. HTTP is as good a way as any for my purposes, so I installed Apache (yum -y install httpd), ensured it would restart on reboot (chkconfig httpd on) and created symbolic links to my repositories:
# cd /var/www/html/repo/OracleLinux/OL6 # ln -s /repos/x86_64/ol6_UEK_latest/getPackage/ ./UEK/latest/x86_64 # ln -s /repos/x86_64/ol6_latest/getPackage/ ./latest/x86_64
8) Script for Updating Mirrors
Once I’d got it working I created a very simple shell script to allow me update whenever I appropriate:
#!/bin/bash LOG_FILE=/repos/logs/repo_cron_$(date +%Y.%m.%d).log /usr/bin/reposync --repoid=ol6_UEK_latest --repoid=ol6_latest -p /repos/x86_64 >> $LOG_FILE 2>&1 /usr/bin/createrepo /repos/x86_64/ol6_UEK_latest/getPackage/ >> $LOG_FILE 2>&1 /usr/bin/createrepo /repos/x86_64/ol6_latest/getPackage/ >> $LOG_FILE 2>&1
It’s then just a matter of pointing my Oracle Linux 6 installations at my local repository.
For reference my repo file is as follows (with hostnames removed)
[ol6_latest_local] name=Oracle Linux $releasever Latest ($basearch) baseurl=http://<hostname removed>/repo/OracleLinux/OL6/latest/$basearch/ gpgkey=http://<hostname removed>/RPM-GPG-KEY-oracle-ol6 gpgcheck=1 enabled=1 [ol6_UEK_latest_local] name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch) baseurl=http://<hostname removed>/repo/OracleLinux/OL6/UEK/latest/$basearch/ gpgkey=http://<hostname removed>/RPM-GPG-KEY-oracle-ol6 gpgcheck=1 enabled=1