8i | 9i | 10g | 11g | 12c | 13c | 18c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » Linux » Here

Create a Local Yum Repository for Oracle Linux 6

This article describes the process of setting up local Yum repositories for Oracle Linux using yum.oracle.com as the source repository. If you have a ULN subscription, you should use the method described here.

Repository Creation

Install the following packages, which include the utilities necessary to set up the repository.

# yum install yum-utils createrepo

Create the following directories to hold the main OS and UEK respoitories.

# mkdir -p /u01/repo/OracleLinux
# mkdir -p /u01/repo/logs
# mkdir -p /u01/repo/scripts

If you've done a default installation of Oracle Linux 6, the "ol6_latest" and "ol6_UEK_latest" repositories should already be enabled in the "/etc/yum.repos.d/public-yum-ol6.repo" file, but it's worth checking before you continue.

The reposync command is used to synchronize a remote yum repository to a local directory, using yum to retrieve the packages.

# /usr/bin/reposync --newest-only --repoid=ol6_latest -p /u01/repo/OracleLinux
# /usr/bin/reposync --newest-only --repoid=ol6_UEK_latest -p /u01/repo/OracleLinux
# /usr/bin/reposync --newest-only --repoid=ol6_UEKR4 -p /u01/repo/OracleLinux

It takes a long time to sync the repositories the first time, so be patient. I waited overnight for the 27G of downloads to complete. Subsequent refreshes only bring across the changed packages, so they are much quicker. The "newest-only" option reduces the total size of the download.

Once complete, you can create the repositories from the local directories using the createrepo command.

# /usr/bin/createrepo /repo/OracleLinux/ol6_latest/getPackage/
# /usr/bin/createrepo /repo/OracleLinux/ol6_UEK_latest/getPackage/
# /usr/bin/createrepo /repo/OracleLinux/ol6_UEKR4/getPackage/

Resync the Repository

A resync of the Yum repositories involves repeating the reposync and createrepo commands, so you should script them and run them from CRON. Create a script called "/repo/scripts/repo_sync.sh" with the following contents.


LOG_FILE=/u01/repo/logs/repo_sync_$(date +%Y.%m.%d).log

# Remove old logs
find /u01/repo/logs/repo_sync* -mtime +5 -delete; >> $LOG_FILE 2>&1

# Sync repositories
/usr/bin/reposync --newest-only --repoid=ol6_latest -p /u01/repo/OracleLinux >> $LOG_FILE 2>&1
/usr/bin/reposync --newest-only --repoid=ol6_UEK_latest -p /u01/repo/OracleLinux >> $LOG_FILE 2>&1
/usr/bin/reposync --newest-only --repoid=ol6_UEKR4 -p /u01/repo/OracleLinux >> $LOG_FILE 2>&1

/usr/bin/createrepo /u01/repo/OracleLinux/ol6_latest/getPackage/ >> $LOG_FILE 2>&1
/usr/bin/createrepo /u01/repo/OracleLinux/ol6_UEK_latest/getPackage/ >> $LOG_FILE 2>&1
/usr/bin/createrepo /u01/repo/OracleLinux/ol6_UEKR4/getPackage/ >> $LOG_FILE 2>&1

Make the file executable.

# chmod u+x /repo/scripts/repo_sync.sh

Set up a CRON job to run the script on a daily basis. The following entry runs the script each day at 01:00.

0 1 * * * /repo/scripts/repo_sync.sh > /dev/null 2>&1

Setup the HTTP Server

Install the Apache HTTP servers, start it and make sure it restarts automatically on reboot.

# yum install httpd
# service httpd start
# chkconfig httpd on

If you are using the Linux firewall you will need to punch a hole for port 80.

# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
# service iptables save

Either set SELinux to permissive, or configure the fcontext for the repository files as shown below.

# # One-off configuration.
# yum install policycoreutils-python -y
# semanage fcontext -a -t httpd_sys_content_t "/repo/OracleLinux(/.*)?"

# # Run each time the repo contents change.
# restorecon -F -R -v /repo/OracleLinux

Present the repositories using the HTTP server.

# mkdir -p /var/www/html/repo/OracleLinux/ol6_latest
# ln -s /repo/OracleLinux/ol6_latest/getPackage/ /var/www/html/repo/OracleLinux/ol6_latest/x86_64

# mkdir -p /var/www/html/repo/OracleLinux/ol6_UEK_latest
# ln -s /repo/OracleLinux/ol6_UEK_latest/getPackage/ /var/www/html/repo/OracleLinux/ol6_UEK_latest/x86_64

# mkdir -p /var/www/html/repo/OracleLinux/ol6_UEKR4
# ln -s /repo/OracleLinux/ol6_UEKR4/getPackage/ /var/www/html/repo/OracleLinux/ol6_UEKR4/x86_64

Copy the GPG key to the HTTP server.

cp /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle /var/www/html/RPM-GPG-KEY-oracle-ol6

Point Servers to the Local Repository

To allow a server to use the local Yum repositories, create a file called "/etc/yum.repos.d/local-ol6.repo" with the following contents, where "ol6-yum.localdomain" is the name of the server with the Yum repositories.

name=Oracle Linux $releasever Latest ($basearch)

name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch)

name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch)

You may also want to consider installing the following package, to make sure you pick the fastest mirror, which should be your local one.

# yum install yum-plugin-fastestmirror

For more information see:

Hope this helps. Regards Tim...

Back to the Top.