RHEL7: Set up a local repository for a lab.

Share this link

Presentation

Downloading packages from the Internet takes time.
To be able to quickly deploy new VMs, you need a local repository.

Configuration Procedure

Install the Apache package:

# yum group install -y "Basic Web Server"

Create the directories for the CentOS distribution and the updates:

# cd /var/www/html
# mkdir -p conf repo/CentOS/7
# cd repo/CentOS/7
# mkdir -p centosplus/x86_64 extras/x86_64 os/x86_64 updates/x86_64

In the software requirements, it was specified to download the DVD version or the Everything version of the CentOS 7 distribution. It is now time to use it.

Mount the previously downloaded iso and copy it into the right place:

# mount -o loop CentOS-7.0-1406-x86_64-DVD.iso /mnt
# cd /mnt
# tar cvf - . | (cd /var/www/html/repo/CentOS/7/os/x86_64; tar xvf -)
# cd /; umount /mnt

In order to prepare the centosplus, extras and updates repositories, install the createrepo package:

# yum install createrepo

Prepare the centosplus, extras and updates repositories:

# cd /var/www/html/repo/CentOS/7/centosplus/x86_64; createrepo .
# cd ../../extras/x86_64; createrepo .
# cd ../../updates/x86_64; createrepo .

Go into the directory where the repository configuration is:

# cd /etc/yum.repos.d

Create the local.repo file and paste the following lines:

[os]
name=master - Base
baseurl=http://192.168.1.5/repo/CentOS/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=master - Updates
baseurl=http://192.168.1.5/repo/CentOS/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=master - Extras
baseurl=http://192.168.1.5/repo/CentOS/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[centosplus]
name=master - CentosPlus
baseurl=http://192.168.1.5/repo/CentOS/$releasever/centosplus/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Note1: A yum update command will update the system with what the local Apache server’s got.
Note2: Don’t try to display the $releasever and $basearch variables with the echo command. They aren’t shell variables but specific values provided by yum (see this thread for more details).

Copy the local.repo file into the /var/www/html/conf directory to make it available to the new VMs:

# cp local.repo /var/www/html/conf

Assign the SELinux attributes to the files:

# restorecon -R /var/www/html

Activate the Apache server at boot and start it:

# systemctl enable httpd && systemctl start httpd

Clean up the yum configuration:

# yum clean all

Check the yum configuration:

# yum repolist all
Loaded plugins: fastestmirror, langpacks
centosplus                                            | 2.9 kB     00:00
extras                                                | 2.9 kB     00:00
os                                                    | 3.6 kB     00:00
updates                                               | 2.9 kB     00:00
(1/2): os/7/x86_64/group_gz                             | 157 kB   00:00
(2/2): os/7/x86_64/primary_db                           | 4.9 MB   00:00
Loading mirror speeds from cached hostfile
repo id                        repo name                       status
centosplus/7/x86_64            master - CentosPlus             enabled:     0
extras/7/x86_64                master - Extras                 enabled:     0
os/7/x86_64                    master - Base                   enabled: 8,465
updates/7/x86_64               master - Updates                enabled:     0
repolist: 8,465

Finally, you need an extra step to regularly update your lab local repository.
Create a Bash script called /root/rsync.sh and paste the following lines (where mirror.ovh.net/ftp.centos.org/7/ is the url of a close CentOS repository):

#!/bin/bash
/usr/bin/rsync -av --delete --delete-excluded --exclude "local" --exclude "isos" --exclude "*.iso" --exclude "xen4" --exclude "*.i686.*" --exclude "i386" rsync://centos.mirrors.ovh.net/ftp.centos.org/7/ /var/www/html/repo/CentOS/7

Give the execution permissions:

# chmod u+x /root/rsync.sh

Put this script into the root crontab (# crontab -e):

00 02 * * * /root/rsync.sh

Note: The first synchronization will last a while but, after, it will be quick.

After synchronization, you will get this kind of result:

# yum repolist all
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                          repo name                        status
centosplus/7/x86_64              master - CentosPlus              enabled:    70
extras/7/x86_64                  master - Extras                  enabled:    44
os/7/x86_64                      master - Base                    enabled: 8,465
updates/7/x86_64                 master - Updates                 enabled:   866
repolist: 9,445

Add a rule to the firewall (except if the local repository is the KVM host itself):

# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload
(4 votes, average: 4.00 out of 5)
Loading...
26 comments on “RHEL7: Set up a local repository for a lab.
  1. travisby says:

    Depending on the disc you used to install CentOS 7, you may need to remove the currently existing repos to achieve the same output — and avoid a warning about each repo “being defined twice.”

    Just do an rm /etc/yum.repos.d/* before you create your local.repo, and you should be set!

  2. anisK says:

    Hi,
    thanks for making such a great site! I have purchased the new RHEL 7 book by Michael Jang which you recomended which is being released today (8 April) – I can’t wait to receive it shortly.

    I have been following your lab tutorial and I have a problem with the rsync.sh command… when I type this into my terminal it gives me an error is this normal?

    [root@master yum.repos.d]# /usr/bin/rsync -av –delete –delete-excluded –exclude “local” –exclude “isos” –exclude “*.iso” –exclude “xen4” –exclude “*.i686.*” –exclude “i386” rsync://mirror.ovh.net/ftp.centos.org/7/ /var/www/html/repo/CentOS/7

    @ERROR: Unknown module ‘ftp.centos.org’
    rsync error: error starting client-server protocol (code 5) at main.c(1516) [Receiver=3.0.9]

    I haven’t let rsync.sh run on it’s own yet, but I just wanted to test it’s functionally and test my closest mirror format.

    My closest mirror is: http://mirror.its.sfu.ca/mirror/CentOS/7/

    Anyways thanks for reading my comment and I would appretiate any feedback given on my error.

    Yours Sincerely
    anisK

    • CertDepot says:

      My example doesn’t work anymore because the url has changed.
      I updated the tutorial because the line should now be:
      # /usr/bin/rsync -av –delete –delete-excluded –exclude “local” –exclude “isos” –exclude “*.iso” –exclude “xen4” –exclude “*.i686.*” –exclude “i386” rsync://centos.mirrors.ovh.net/ftp.centos.org/7/ /var/www/html/repo/CentOS/7

      • anisK says:

        ah sorry when I said it doesn’t give any error now that was because I forgot to remove the #…it stills give me an error

        [root@master yum.repos.d]# /usr/bin/rsync -av –delete –delete-excluded –exclude “local” –exclude “isos” –exclude “*.iso” –exclude “xen4” –exclude “*.i686.*” –exclude “i386” rsync://centos.mirrors.ovh.net/ftp.centos.org/7/ /var/www/html/repo/CentOS/7
        Unexpected remote arg: rsync://centos.mirrors.ovh.net/ftp.centos.org/7/
        rsync error: syntax or usage error (code 1) at main.c(1214) [sender=3.0.9]

  3. Cory Brown says:

    Should also be included in “Prepare the centosplus, extras and updates repositories:” step?

  4. thetron says:

    Hi I followed the guide

    However I found the 7.3 has the firewall enabled. So you should add the following

    firewall-cmd –add-port=80/tcp –permanent
    firewall-cmd –add-port=443/tcp –permanent
    firewall-cmd –reload

  5. number 6 says:

    Hello again CertDepot, I’d like to ask if the repository is at an ip that’s in a different network, let’s say 10.0.1.68 (we don’t know the subnet mask, nor its gateway or dns) and the system eth0 is 172.168.10.11 but we can’t ping anything from the 10.* network, how can we make it ping/connect to that repository?
    Would it need an eth-route config and sysctl parameters like ip forwarding and source routing?

  6. Mike_ says:

    I was wondering if for RHCE purposes we aren’t better off not updating our repos. From my understanding, the tests are based on RHEL 7.0. If so, upgrading versions could lead to some ambiguities with versions of files when using iSCSi and other applications. Any thoughts?

    If your objective is to know as much as possible, then updating is good. However, if your objective is passing the exam, can updating cause confusion?

    Thanks,

    Mike_

    • CertDepot says:

      This is a tricky question: if you don’t update your repos, you could have bugs not fixed; if you update your repos, you could change the standard behaviour. Personally, I won’t update the repos to keep the standard behaviour.

    • Lisenet says:

      What you can do is to download all RHEL 7.x DVDs from Red Hat website, and create repos for each DVD. Disable them all but the 7.0. Do as much testing as you can on RHEL 7.0, and then move to RHEL 7.1 (enable 7.1 repo and update your system). Repeat the process, do as much testing as you can on RHEL 7.1, and then move to RHEL 7.2.

      Simply create a snapshot of the system at the start of the process, so that you can always roll back to.

Leave a Reply

Upcoming Events (Local Time)

There are no events.

Follow me on Twitter

Archives

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |