{"id":6394,"date":"2016-10-18T09:30:15","date_gmt":"2016-10-18T01:30:15","guid":{"rendered":"http:\/\/rmohan.com\/?p=6394"},"modified":"2016-10-18T09:30:15","modified_gmt":"2016-10-18T01:30:15","slug":"centos-7-create-centos-7-mirror","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6394","title":{"rendered":"CentOS 7 &#8211; Create CentOS 7 Mirror"},"content":{"rendered":"<p><strong>CentOS 7 &#8211; Create CentOS 7 Mirror<\/strong><\/p>\n<p>The tutorial below will show you how to configure a CentOS 7 server with Nginx to act as a mirror for other CentOS 7 servers.<br \/>\nSteps<br \/>\nFirst we need to update and install all the necessary packages.<br \/>\nyum update<br \/>\nyum install -y createrepo rsync nginx<br \/>\nNow we need to setup our directories and permissions:<\/p>\n<p>mkdir -p \/var\/www\/html\/repos\/centos\/7.2\/os\/x86_64\/<br \/>\nmkdir -p \/var\/www\/html\/repos\/centos\/7.2\/updates\/x86_64\/<br \/>\nchmod 770 -R \/var\/www<br \/>\nchown $USER:nginx -R \/var\/www<br \/>\nNow we are going to configure Nginx to use the location we just created. Replace the contents of \/etc\/nginx\/nginx.conf with:<\/p>\n<p>user nginx;<br \/>\nworker_processes auto;<br \/>\nerror_log \/var\/log\/nginx\/error.log;<br \/>\npid \/run\/nginx.pid;<\/p>\n<p>events {<br \/>\nworker_connections 1024;<br \/>\n}<\/p>\n<p>http {<br \/>\nlog_format main &#8216;$remote_addr &#8211; $remote_user [$time_local] &#8220;$request&#8221; &#8216;<br \/>\n&#8216;$status $body_bytes_sent &#8220;$http_referer&#8221; &#8216;<br \/>\n&#8216;&#8221;$http_user_agent&#8221; &#8220;$http_x_forwarded_for&#8221;&#8216;;<\/p>\n<p>access_log \/var\/log\/nginx\/access.log main;<\/p>\n<p>sendfile on;<br \/>\ntcp_nopush on;<br \/>\ntcp_nodelay on;<br \/>\nkeepalive_timeout 65;<br \/>\ntypes_hash_max_size 2048;<\/p>\n<p>include \/etc\/nginx\/mime.types;<br \/>\ndefault_type application\/octet-stream;<\/p>\n<p>include \/etc\/nginx\/conf.d\/*.conf;<br \/>\n}<br \/>\nCreate a file at \/etc\/nginx\/conf.d\/repo.conf with the following contents<br \/>\nserver {<br \/>\nlisten 80;<br \/>\nserver_name localhost;<br \/>\nroot \/var\/www\/html\/repos;<\/p>\n<p>location \/ {<br \/>\nautoindex on;<br \/>\n}<\/p>\n<p>}<br \/>\nRun the following command<br \/>\nhttp:\/\/mirror.bytemark.co.uk\/centos\/7.2.1511\/<\/p>\n<p>createrepo \/var\/www\/html\/repos\/centos\/7.2\/os\/x86_64\/<br \/>\ncreaterepo \/var\/www\/html\/repos\/centos\/7.2\/updates\/x86_64\/<\/p>\n<p>Now we need to fetch the data for the mirror. Go to the CentOS mirrors list and pick the mirror closest to you that has an rsync address (6th column in the table). For me, I am going to use Bytemark since I am in the United Kingdom.<br \/>\nrsync:\/\/mirror.nus.edu.sg\/centos<br \/>\nTake the given url, and add the following to the end of it:<br \/>\n\/7\/os\/x86_64\/<br \/>\n\/7\/updates\/x86_64\/<\/p>\n<p>Now use those urls in the commands below<br \/>\nrsync -avz -avz &#8211;delete &#8211;exclude=&#8217;repo*&#8217; \\<br \/>\nrsync:\/\/mirror.bytemark.co.uk\/centos\/7.2.1511\/os\/x86_64\/ \\<br \/>\n\/var\/www\/html\/repos\/centos\/7\/os\/x86_64\/<\/p>\n<p>rsync -avz &#8211;delete &#8211;exclude=&#8217;repo*&#8217; \\<br \/>\nrsync:\/\/mirror.bytemark.co.uk\/centos\/7.2.1511\/updates\/x86_64\/ \\<br \/>\n\/var\/www\/html\/repos\/centos\/7.2\/updates\/x86_64\/<\/p>\n<p>Next we need to update the repo metadata by running:<\/p>\n<p>createrepo &#8211;update \/var\/www\/html\/repos\/centos\/7.2\/os\/x86_64\/<br \/>\ncreaterepo &#8211;update \/var\/www\/html\/repos\/centos\/7.2\/updates\/x86_64\/<\/p>\n<p>Configure Cron For Automatic Updating<\/p>\n<p>Create a script with the following contents:<br \/>\n#!\/bin\/bash<br \/>\nrsync -avz -avz &#8211;delete &#8211;exclude=&#8217;repo*&#8217; \\<br \/>\nrsync:\/\/mirror.bytemark.co.uk\/centos\/7.2.1511\/os\/x86_64\/ \\<br \/>\n\/var\/www\/html\/repos\/centos\/7\/os\/x86_64\/<\/p>\n<p>rsync -avz &#8211;delete &#8211;exclude=&#8217;repo*&#8217; \\<br \/>\nrsync:\/\/mirror.bytemark.co.uk\/centos\/7.2.1511\/updates\/x86_64\/ \\<br \/>\n\/var\/www\/html\/repos\/centos\/7.2\/updates\/x86_64\/<br \/>\n\/usr\/bin\/createrepo &#8211;update \\<br \/>\n\/var\/www\/html\/repos\/centos\/7\/os\/x86_64\/<\/p>\n<p>\/usr\/bin\/createrepo &#8211;update \\<br \/>\n\/var\/www\/html\/repos\/centos\/7\/updates\/x86_64\/<\/p>\n<p>Now configure the cron service to call that script from at midnight every day by executing crontab -e and adding the following line:<\/p>\n<p>@daily \/bin\/bash \/path\/to\/script.sh<br \/>\nConfigure Automatic Startup<br \/>\nRun the commands below to ensure nginx starts up on boot.<br \/>\nsystemctl enable nginx.service &amp;&amp; sudo systemctl enable firewalld.service<br \/>\nsystemctl start firewalld.service<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-service=http<br \/>\nfirewall-cmd &#8211;reload<br \/>\nsystemctl reboot<\/p>\n<p>Configure SELinux<br \/>\nIf you are running selinux and you don&#8217;t want to disable it, then run the following command to have selinux allow nginx to serve content from \/var\/www<\/p>\n<p>chcon -Rt httpd_sys_content_t \/var\/www<\/p>\n<p>Configure Client To Use Own Mirror<\/p>\n<p>There&#8217;s no point having a mirror unless you configure your other servers to use that mirror for updates. Edit the file at \/etc\/yum.repos.d\/CentOS-Base.repo and comment out any lines starting with mirrorlist or baseurl underneath [base] or [updates]. Then add your own baseurl to these sections, with your own mirrors url. For example, my mirror is located internally at http:\/\/centos-mirror.programster.org, so my base urls were:<br \/>\n[base]<br \/>\nbaseurl=http:\/\/centos-mirror.rmohan.com\/centos\/$releasever\/os\/$basearch\/<br \/>\n&#8230;<br \/>\n[updates]<br \/>\nbaseurl=http:\/\/centos-mirror.rmohan.com\/centos\/$releasever\/updates\/$basearch\/<br \/>\n&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CentOS 7 &#8211; Create CentOS 7 Mirror<\/p>\n<p>The tutorial below will show you how to configure a CentOS 7 server with Nginx to act as a mirror for other CentOS 7 servers. Steps First we need to update and install all the necessary packages. yum update yum install -y createrepo rsync nginx Now we need [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6394"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6394"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6394\/revisions"}],"predecessor-version":[{"id":6395,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6394\/revisions\/6395"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}