{"id":12360,"date":"2019-03-26T21:30:42","date_gmt":"2019-03-26T21:30:42","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12360"},"modified":"2019-03-26T21:30:42","modified_gmt":"2019-03-26T21:30:42","slug":"how-to-setup-local-http-yum-repository-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/how-to-setup-local-http-yum-repository-on-centos-7\/","title":{"rendered":"How to Setup Local HTTP Yum Repository on CentOS 7"},"content":{"rendered":"<p>A software repository (\u201c<strong>repo<\/strong>\u201d in short) is a central file storage location to keep and maintain software packages, from which users can retrieve packages and install on their computers.<\/p>\n<p>Repositories are often stored on servers on a network for example the internet, which can be accessed by multiple users. However, you can create and configure a local repository on your computer and access it as a single user or allow access to other machines on your\u00a0<strong>LAN<\/strong>\u00a0(<strong>Local Area Network<\/strong>).<\/p>\n<p>One advantage of a setting up a local repository is that you don\u2019t need internet connection to install sofware packages.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement\/\" target=\"_blank\" rel=\"noopener\">YUM (Yellowdog Updater Modified)<\/a>\u00a0is a widely used package management tool for\u00a0<strong>RPM<\/strong>\u00a0(<strong>RedHat Package Manager<\/strong>) based Linux systems, which makes sofware installation easy on\u00a0<strong>Red Hat\/CentOS<\/strong>\u00a0Linux.<\/p>\n<p>In this article, we will explain how to setup a local\u00a0<strong>YUM<\/strong>\u00a0repository over\u00a0<strong>HTTP<\/strong>\u00a0(<strong>Nginx<\/strong>) web server on\u00a0<strong>CentOS 7 VPS<\/strong>\u00a0and also show you how to find and install software packages on client\u00a0<strong>CentOS 7<\/strong>\u00a0machines.<\/p>\n<h4>Our Testing Environment<\/h4>\n<pre><strong>Yum HTTP Repository Server<\/strong>:\tCentOS 7 [192.168.0.100]\r\n<strong>Client Machine<\/strong>:\t\tCentOS 7 [192.168.0.101]\r\n<\/pre>\n<h3>Step 1: Install Nginx Web Server<\/h3>\n<p><strong>1.<\/strong>\u00a0First start by installing Nginx HTTP server from the EPEL repository using the YUM package manager as follows.<\/p>\n<pre># yum install epel-release\r\n# yum install nginx \r\n<\/pre>\n<p><strong>2.<\/strong>\u00a0Once you have installed Nginx web server, you can start it for the first time and enable it to start automatically at system boot.<\/p>\n<pre> \r\n# systemctl start nginx\r\n# systemctl enable nginx\r\n# systemctl status nginx\r\n<\/pre>\n<p><strong>3.<\/strong>\u00a0Next, you need to open port\u00a0<strong>80<\/strong>\u00a0and\u00a0<strong>443<\/strong>\u00a0to allow web traffic to Nginx service, update the system firewall rules to permit inbound packets on\u00a0<strong>HTTP<\/strong>\u00a0and\u00a0<strong>HTTPS<\/strong>\u00a0using the commands below.<\/p>\n<pre># firewall-cmd --zone=public --permanent --add-service=http\r\n# firewall-cmd --zone=public --permanent --add-service=https\r\n# firewall-cmd --reload\r\n<\/pre>\n<p><strong>4.<\/strong>\u00a0Now you can confirm that your Nginx server is up and running, using the following URL; if you see the default Nginx web page, all is well.<\/p>\n<pre>http:\/\/SERVER_DOMAIN_NAME_OR_IP \r\n<\/pre>\n<div id=\"attachment_30333\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Nginx-Default-Page.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30333\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Nginx-Default-Page.png\" sizes=\"auto, (max-width: 780px) 100vw, 780px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Nginx-Default-Page.png 780w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Nginx-Default-Page-768x574.png 768w\" alt=\"Nginx Default Page\" width=\"780\" height=\"583\" aria-describedby=\"caption-attachment-30333\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30333\" class=\"wp-caption-text\">Nginx Default Page<\/p>\n<\/div>\n<h3>Step 2: Create Yum Local Repository<\/h3>\n<p><strong>5.<\/strong>\u00a0In this step, you need to install the required packages for creating, configuring and managing your local repository.<\/p>\n<pre># yum install createrepo  yum-utils\r\n<\/pre>\n<p><strong>6.<\/strong>\u00a0Next, create the necessary directories (yum repositories) that will store packages and any related information.<\/p>\n<pre># mkdir -p \/var\/www\/html\/repos\/{base,centosplus,extras,updates}\r\n<\/pre>\n<p><strong>7.<\/strong>\u00a0Then use the\u00a0<strong>reposync<\/strong>\u00a0tool to synchronize\u00a0<strong>CentOS YUM<\/strong>\u00a0repositories to the local directories as shown.<\/p>\n<pre># reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=\/var\/www\/html\/repos\/\r\n# reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=\/var\/www\/html\/repos\/\r\n# reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=\/var\/www\/html\/repos\/\r\n# reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=\/var\/www\/html\/repos\/\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>Loaded plugins: fastestmirror, langpacks\r\nLoading mirror speeds from cached hostfile\r\n * base: mirrors.fibergrid.in\r\n * epel: mirror.xeonbd.com\r\n * extras: mirrors.fibergrid.in\r\n * updates: mirrors.fibergrid.in\r\nbase\/7\/x86_64\/group                                                    | 891 kB  00:00:02     \r\nNo Presto metadata available for base\r\n(1\/9911): 389-ds-base-snmp-1.3.7.5-18.el7.x86_64.rpm                   | 163 kB  00:00:02     \r\n(2\/9911): 389-ds-base-devel-1.3.7.5-18.el7.x86_64.rpm                  | 267 kB  00:00:02     \r\n(3\/9911): ElectricFence-2.2.2-39.el7.i686.rpm                          |  35 kB  00:00:00     \r\n(4\/9911): ElectricFence-2.2.2-39.el7.x86_64.rpm                        |  35 kB  00:00:00     \r\n(5\/9911): 389-ds-base-libs-1.3.7.5-18.el7.x86_64.rpm                   | 695 kB  00:00:04     \r\n(6\/9911): GConf2-devel-3.2.6-8.el7.i686.rpm                            | 110 kB  00:00:00     \r\n(7\/9911): GConf2-devel-3.2.6-8.el7.x86_64.rpm                          | 110 kB  00:00:00     \r\n(8\/9911): GConf2-3.2.6-8.el7.i686.rpm                                  | 1.0 MB  00:00:06     \r\n<\/pre>\n<p>In the above commands, the option:<\/p>\n<ul>\n<li><code>-g<\/code>\u00a0\u2013 enables removing of packages that fail GPG signature checking after downloading.<\/li>\n<li><code>-l<\/code>\u00a0\u2013 enables yum plugin support.<\/li>\n<li><code>-d<\/code>\u00a0\u2013 enables deleting of local packages no longer present in repository.<\/li>\n<li><code>-m<\/code>\u00a0\u2013 enables downloading of\u00a0<strong>comps.xml<\/strong>\u00a0files.<\/li>\n<li><code>--repoid<\/code>\u00a0\u2013 specifies the repository ID.<\/li>\n<li><code>--newest-only<\/code>\u00a0\u2013 tell reposync to only pull the latest version of each package in the repos.<\/li>\n<li><code>--download-metadata<\/code>\u00a0\u2013 enables downloading all the non-default metadata.<\/li>\n<li><code>--download_path<\/code>\u00a0\u2013 specifies the path to download packages.<\/li>\n<\/ul>\n<p><strong>8.<\/strong>\u00a0Next, check the contents of your local directories to ensure that all the packages have been synchronized locally.<\/p>\n<pre># ls -l \/var\/www\/html\/repos\/base\/\r\n# ls -l \/var\/www\/html\/repos\/base\/Packages\/\r\n# ls -l \/var\/www\/html\/repos\/centosplus\/\r\n# ls -l \/var\/www\/html\/repos\/centosplus\/Packages\/\r\n# ls -l \/var\/www\/html\/repos\/extras\/\r\n# ls -l \/var\/www\/html\/repos\/extras\/Packages\/\r\n# ls -l \/var\/www\/html\/repos\/updates\/\r\n# ls -l \/var\/www\/html\/repos\/updates\/Packages\/\r\n<\/pre>\n<p><strong>9.<\/strong>\u00a0Now create a new repodata for the local repositories by running the following commands, where the flag\u00a0<code>-g<\/code>is used to update the package group information using the specified\u00a0<code>.xml<\/code>\u00a0file.<\/p>\n<pre># createrepo -g comps.xml \/var\/www\/html\/repos\/base\/  \r\n# createrepo -g comps.xml \/var\/www\/html\/repos\/centosplus\/\t\r\n# createrepo -g comps.xml \/var\/www\/html\/repos\/extras\/  \r\n# createrepo -g comps.xml \/var\/www\/html\/repos\/updates\/  \r\n<\/pre>\n<p><strong>10.<\/strong>\u00a0To enable viewing of repositories and packages in them, via a web browser, create a Nginx server block which points to the root of your repositories as shown.<\/p>\n<pre># vim \/etc\/nginx\/conf.d\/repos.conf \r\n<\/pre>\n<p>Add the following configuration ot file\u00a0<strong>repos.conf<\/strong>.<\/p>\n<pre>server {\r\n        listen   80;\r\n        server_name  repos.test.lab;\t#change  test.lab to your real domain \r\n        root   \/var\/www\/html\/repos;\r\n        location \/ {\r\n                index  index.php index.html index.htm;\r\n                autoindex on;\t#enable listing of directory index\r\n        }\r\n}\r\n<\/pre>\n<p>Save the file and close it.<\/p>\n<p><strong>11.<\/strong>\u00a0Then restart your Nginx server and view the repositories from a web browser using the following URL.<\/p>\n<pre>http:\/\/repos.test.lab\r\n<\/pre>\n<div id=\"attachment_30334\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/View-Local-Yum-Repositories.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30334\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/View-Local-Yum-Repositories.png\" sizes=\"auto, (max-width: 780px) 100vw, 780px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/View-Local-Yum-Repositories.png 780w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/View-Local-Yum-Repositories-768x313.png 768w\" alt=\"View Local Yum Repositories\" width=\"780\" height=\"318\" aria-describedby=\"caption-attachment-30334\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30334\" class=\"wp-caption-text\">View Local Yum Repositories<\/p>\n<\/div>\n<h3>Step 3: Create Cron Job to Synchronize and Create Repositories<\/h3>\n<p><strong>12.<\/strong>\u00a0Next, add a cron job that will automatically synchronize your local repos with the official CentOS repos to grab the updates and security patches.<\/p>\n<pre># vim \/etc\/cron.daily\/update-localrepos\r\n<\/pre>\n<p>Add these commands in the script.<\/p>\n<pre>#!\/bin\/bash\r\n##specify all local repositories in a single variable\r\nLOCAL_REPOS=\u201dbase centosplus extras updates\u201d\r\n##a loop to update repos one at a time \r\nfor REPO in ${LOCAL_REPOS}; do\r\nreposync -g -l -d -m --repoid=$REPO --newest-only --download-metadata --download_path=\/var\/www\/html\/repos\/\r\ncreaterepo -g comps.xml \/var\/www\/html\/repos\/$REPO\/  \r\ndone\r\n<\/pre>\n<p>Save the script and close it and set the appropriate permissions on it.<\/p>\n<pre># chmod 755 \/etc\/cron.daily\/update-localrepos\r\n<\/pre>\n<h3>Step 4: Setup Local Yum Repository on Client Machines<\/h3>\n<p><strong>13.<\/strong>\u00a0Now on your\u00a0<strong>CentOS<\/strong>\u00a0client machines, add your local repos to the YUM configuration.<\/p>\n<pre># vim \/etc\/yum.repos.d\/local-repos.repo\r\n<\/pre>\n<p>Copy and paste the configuration below in the file\u00a0<strong>local-repos.repo<\/strong>\u00a0(make changes where necessary).<\/p>\n<pre>[local-base]\r\nname=CentOS Base\r\nbaseurl=http:\/\/repos.test.lab\/base\/\r\ngpgcheck=0\r\nenabled=1\r\n\r\n[local-centosplus]\r\nname=CentOS CentOSPlus\r\nbaseurl=http:\/\/repos.test.lab\/centosplus\/\r\ngpgcheck=0\r\nenabled=1\r\n\r\n[local-extras]\r\nname=CentOS Extras\r\nbaseurl=http:\/\/repos.test.lab\/extras\/\r\ngpgcheck=0\r\nenabled=1\r\n\r\n[local-updates]\r\nname=CentOS Updates\r\nbaseurl=http:\/\/repos.test.lab\/updates\/\r\ngpgcheck=0\r\nenabled=1\r\n<\/pre>\n<div class=\"google-auto-placed ap_container\">\n<p>Save the file and start using your local YUM mirrors.<\/p>\n<p><strong>14.<\/strong>\u00a0Next, run the following command to view your local repos in the list of available YUM repos, on the client machines.<\/p>\n<pre>#  yum repolist\r\nOR\r\n# yum repolist all\r\n<\/pre>\n<div id=\"attachment_30335\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/View-Local-Yum-Repositories-on-Client.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30335\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/View-Local-Yum-Repositories-on-Client.png\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/View-Local-Yum-Repositories-on-Client.png 906w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/View-Local-Yum-Repositories-on-Client-768x256.png 768w\" alt=\"View Local Yum Repositories on Client\" width=\"906\" height=\"302\" aria-describedby=\"caption-attachment-30335\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30335\" class=\"wp-caption-text\">View Local Yum Repositories on Client<\/p>\n<\/div>\n<p>That\u2019s all! In this article, we have explained how to setup a local YUM repository on CentOS 7. We hope that you found this guide useful. If you have any questions, or any other thoughts to share, use the comment form below.<\/p>\n<p><a style=\"font-size: 1rem;\" href=\"https:\/\/www.tecmint.com\/setup-local-http-yum-repository-on-centos-7\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>A software repository (\u201crepo\u201d in short) is a central file storage location to keep and maintain software packages, from which users can retrieve packages and install on their computers. Repositories are often stored on servers on a network for example the internet, which can be accessed by multiple users. However, you can create and configure &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/how-to-setup-local-http-yum-repository-on-centos-7\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Setup Local HTTP Yum Repository on CentOS 7&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12360","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12360"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12360\/revisions"}],"predecessor-version":[{"id":12361,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12360\/revisions\/12361"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}