Create a Local Yum Repository for Oracle Linux 7
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
- Resync the Repository
- Setup the HTTP Server
- Point Servers to the Local Repository
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 7, the "ol7_latest" and "ol7_UEKR4" 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=ol7_latest -p /u01/repo/OracleLinux # /usr/bin/reposync --newest-only --repoid=ol7_UEKR4 -p /u01/repo/OracleLinux # /usr/bin/reposync --newest-only --repoid=ol7_UEKR5 -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 /u01/repo/OracleLinux/ol7_latest/getPackage/ # /usr/bin/createrepo /u01/repo/OracleLinux/ol7_UEKR4/getPackage/ # /usr/bin/createrepo /u01/repo/OracleLinux/ol7_UEKR5/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 "/u01/repo/scripts/repo_sync.sh" with the following contents.
#!/bin/bash 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=ol7_latest -p /u01/repo/OracleLinux >> $LOG_FILE 2>&1 /usr/bin/reposync --newest-only --repoid=ol7_UEKR4 -p /u01/repo/OracleLinux >> $LOG_FILE 2>&1 /usr/bin/reposync --newest-only --repoid=ol7_UEKR5 -p /u01/repo/OracleLinux >> $LOG_FILE 2>&1 /usr/bin/createrepo /u01/repo/OracleLinux/ol7_latest/getPackage/ >> $LOG_FILE 2>&1 /usr/bin/createrepo /u01/repo/OracleLinux/ol7_UEKR4/getPackage/ >> $LOG_FILE 2>&1 /usr/bin/createrepo /u01/repo/OracleLinux/ol7_UEKR5/getPackage/ >> $LOG_FILE 2>&1
Make the file executable.
# chmod u+x /u01/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 * * * /u01/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 # systemctl start httpd # systemctl enable httpd
If you are using the Linux firewall you will need to punch a hole for port 80.
# firewall-cmd --permanent --zone=public --add-port=80/tcp # firewall-cmd --reload
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 "/u01/repo/OracleLinux(/.*)?" # # Run each time the repo contents change. # restorecon -F -R -v /u01/repo/OracleLinux
Present the repositories using the HTTP server.
# mkdir -p /var/www/html/repo/OracleLinux/ol7_latest # ln -s /u01/repo/OracleLinux/ol7_latest/getPackage/ /var/www/html/repo/OracleLinux/ol7_latest/x86_64 # mkdir -p /var/www/html/repo/OracleLinux/ol7_UEKR4 # ln -s /u01/repo/OracleLinux/ol7_UEKR4/getPackage/ /var/www/html/repo/OracleLinux/ol7_UEKR4/x86_64 # mkdir -p /var/www/html/repo/OracleLinux/ol7_UEKR5 # ln -s /u01/repo/OracleLinux/ol7_UEKR5/getPackage/ /var/www/html/repo/OracleLinux/ol7_UEKR5/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.
[local_ol7_latest] name=Oracle Linux $releasever Latest ($basearch) baseurl=http://ol7-yum.localdomain/repo/OracleLinux/ol7_latest/$basearch/ gpgkey=http://ol7-yum.localdomain/RPM-GPG-KEY-oracle-ol7 gpgcheck=1 enabled=1 [local_ol7_UEKR4] name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch) baseurl=http://ol7-yum.localdomain/repo/OracleLinux/ol7_UEKR4/$basearch/ gpgkey=http://ol7-yum.localdomain/RPM-GPG-KEY-oracle-ol7 gpgcheck=1 enabled=1 [local_ol7_UEKR5] name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch) baseurl=http://ol7-yum.localdomain/repo/OracleLinux/ol7_UEKR5/$basearch/ gpgkey=http://ol7-yum.localdomain/RPM-GPG-KEY-oracle-ol7 gpgcheck=1 enabled=1
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...