CentOS 7 local repository (mirror)

If so, here I bring you how to mirror CentOS 7. What are the benefits of this? Among them, you save Internet bandwidth, you keep a local copy of your repositories with which the downloads and installations are much faster, and the main one of all is very useful as an update server if you have 10 servers or 1000 workstations with CentOS I think this is your best option because you can offer a fast update service and with the speed of your LAN network.

Now, you can make your mirror in about 10 ways but I'm going to tell you the one that in my opinion is the fastest and most comfortable, well you can make your mirror in any distribution that supports Rsync. Yesiiiiii! anyone, you can read only the rsync part, make a local centOS repository on ubuntu, debian, fedora, redhat, slackware, they all support rsync

Rsync is a free application for Unix and Microsoft Windows-type systems that offers efficient transmission of incremental data, which also operates with compressed and encrypted data. Using a delta encoding technique, it allows you to synchronize files and directories between two machines on a network or between two locations on the same machine, minimizing the volume of data transferred.

We proceed to install rsync
# yum install rsync

Once installed you just have to look in the list of CentOS mirrors some mirror near your locality that works with rsync (it is the sixth column) RsyncLocation

Create a folder where you can place the repository, I only made a mirror of CentOS 7, complete with isos and all the available folders, which took up 38 GB, so take into consideration if you are going to make a partial mirror of other versions of centOS or a full mirror. How much space will it occupy? It is something you should evaluate.

# mkdir -p /home/repo/CentOS/7

The repository has all these folders:

  • atomic
  • centosplus
  • cloud
  • cr
  • extras
  • fast track
  • isos
  • os
  • sclo
  • storage
  • updates
  • virtue

rsync works as follows:

# rsync --delete-excluded --exclude "local" --exclude "isos" --exclude "*.iso"

  • With the tag delete – excluded and –exclude you can ignore folders or files, example iso folder, or .iso files, very easy right?

# rsync -aqzH --delete msync.centos.org::CentOS /path/to/local/mirror/root

  • With option –Delete, will delete files that no longer exist in the source.
  • -a archive and store
  • -q quiet mode, suppresses non-error messages
  • -z compress data during transfer
  • -H keep the hard links, if you wanted I would also recommend the option -l to hold symlinks

How did I do it? simple like this:

# rsync -avzqlH --delete --delay-updates rsync://ftp.osuosl.org/centos/7/ /home/repo/CentOS/7

Don't rush, I'll explain why I did it like that.

  • –Delay-updates Place all the updated files at the end of the entire download, do you understand me? That is, he does not update each time he downloads a new file, but on the contrary, if there were 100 new files, after finishing the 100 new files, rsync them place in place
  • rsync: //ftp.osuosl.org/centos/7/ because I only want to do CentOS 7
  • / var / www / html / repo / CentOS / 7 where I am going to put all my files that I copy from the source.

It is not necessary, but I recommend the package createrepo, simply what it does is give it the http characteristic and create an index for your repository

# yum install createrepo

Then just run the command pointing to your repository

# createrepo /home/repo/CentOS/7

Now once finished, you must share it in some way, I always use an http server, continuing with CentOS 7, you can install a basic web server as follows (use httpd, it is not apache)

# yum group install -y "Basic Web Server

Create a symbolic link from the actual repository site to the "www" folder

# ln -s /home/repo /var/www/html/repo

We create the sites-available and sites-enabled folders
# mkdir /etc/httpd/sites-available
# mkdir /etc/httpd/sites-enabled

We edit the httpd.conf file to add all our active sites-enabled sites

# vi /etc/httpd/conf/httpd.conf

Add this line to the end of the file
IncludeOptional sites-enabled / *. Conf

We create and edit our website

# vi /etc/httpd/sites-available/repocentos.conf


ServerName repocentos.com
#ServerAlias ​​example.com
DocumentRoot / var / www / html / repo / CentOS /
ErrorLog /var/log/httpd/error.log
CustomLog /var/log/httpd/requests.log combined

We activate our site by creating a symbolic link

# ln -s /etc/httpd/sites-available/repocentos.conf  /etc/httpd/sites-enabled/repocentos.conf

We change the owner and group of files and folders for apache

# chown apache. www/ -R

We execute the following command so that the web server starts from the moment we started the machine

# systemctl enable httpd.service

We restart the web server with the following command

# systemctl restart httpd

How can we use it?

Create a file in /etc/yum.repos.d/local.repo and paste the following lines:

[os] name = master - Base baseurl = http: //ip or url/ repo / CentOS / $ releasever / os / $ basearch / gpgcheck = 1 gpgkey = file: /// etc / pki / rpm-gpg / RPM-GPG-KEY-CentOS-7 [updates] name = master - Updates baseurl = http: //ip or url/ repo / CentOS / $ releasever / updates / $ basearch / gpgcheck = 1 gpgkey = file: /// etc / pki / rpm-gpg / RPM-GPG-KEY-CentOS-7 [extras] name = master - Extras baseurl = http: //ip or url/ repo / CentOS / $ releasever / extras / $ basearch / gpgcheck = 1 gpgkey = file: /// etc / pki / rpm-gpg / RPM-GPG-KEY-CentOS-7 [centosplus] name = master - CentosPlus baseurl = http: //ip or url/ repo / CentOS / $ releasever / centosplus / $ basearch / gpgcheck = 1 gpgkey = file: /// etc / pki / rpm-gpg / RPM-GPG-KEY-CentOS-7

We refresh the repositories with:
# yum clean all

# yum repolist all

# yum update

Well that's it for this time. As always remember to closely follow my post and this website. Comment and so we all share our knowledge, until next time !!!


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   elendilnarsil said

    Is Centos suitable for use on an end-user desktop PC? Or is it a waste of resources? I have been testing it via Live-usb and I really liked it.

    1.    brodydalle said

      It is very stable, it really is a good option. Thanks for your comment

    2.    HO2Gi said

      Dear elendilnarsil use Fedora as an end user with centos you have to work a lot and it is a very stable server.

  2.   Gonzalo Martinez said

    Power can. But it is not very intended for desktops of normal users.

    Do not be surprised if the Wifi or some diver of I do not know, web camera, (since it includes drivers more than nothing of server hard), that in the repo there is no package of I do not know, codecs, office automation, or something like that, or that the packages are old (but stable as iron)

    1.    brodydalle said

      I do not agree with you, there are official repositories oriented to this end, such as epel and nux https://wiki.centos.org/TipsAndTricks/MultimediaOnCentOS7

  3.   Gonzalo Martinez said

    Going to the article, excellent !!

    When you have a large number of Linux computers, the installations become much faster and more practical.

    1.    brodydalle said

      that's right, thanks for your comment

  4.   alexmanafan said

    Hello colleague, can I cancel and resume the repo download? continue where I left?
    Thank you

  5.   Luis said

    a doubt friend, as I consume the repo by http, that is, see the repo structure from httpd
    http://172.16.1.9 I get the apache page but I want to put http://172.16.1.9/??? to see the structure by http.

    Thank you

  6.   odhnamra said

    I need to ask a question for doubts that arose ...
    rsync -avzqlH –delete –delay-updates rsync:…. Even there is fine but I don't have to put where it is going to be copied later?
    For example: rsync -avzqlH –delete –delay-updates rsync:…. / run / media / miuser / Data / repository / centos7 / 7 /

  7.   Daniel Morales placeholder image said

    Dear good afternoon

    Looking for information on the Web I got this interesting manual that you wrote, Congratulations on that. My question arises because I want to create a Mirror with several Linux distributions, Centos, OracleLinux, Debian, all of them with their latest versions that I have installed in the company. But how can I make the same mirror server store several distributions and versions? Should I create another folder with the name of the distributions and so on? These repositories are updated automatically or do I have to run a command every so often? Watch for your comments. Happy day