<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>how to create centOS repository Archives - Linux Windows and android Tutorials</title>
	<atom:link href="https://www.osradar.com/tag/how-to-create-centos-repository/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.osradar.com</link>
	<description>tutorials and news and Seurity</description>
	<lastBuildDate>Wed, 27 Nov 2019 08:14:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8.12</generator>
	<item>
		<title>How To Create CentOS 8 Local Repository Mirrors With Rsync &#038; Nginx</title>
		<link>https://www.osradar.com/how-to-create-centos-8-local-repository-mirrors-with-rsync-nginx/</link>
					<comments>https://www.osradar.com/how-to-create-centos-8-local-repository-mirrors-with-rsync-nginx/#respond</comments>
		
		<dc:creator><![CDATA[sabi]]></dc:creator>
		<pubDate>Tue, 26 Nov 2019 16:50:07 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[how to create CentOS mirrors]]></category>
		<category><![CDATA[how to create centOS repository]]></category>
		<category><![CDATA[Rsync & nginx local repository]]></category>
		<category><![CDATA[unix]]></category>
		<guid isPermaLink="false">https://www.osradar.com/?p=15953</guid>

					<description><![CDATA[<p>Today, we are going to create CentOS 8 Local Repository Mirrors on our CentOS 8 with the help of Rsync &#38; Nginx. We can create by Local cron jobs through which we can checks for updates in the upstream repositories &#38; update them locally accordingly. By doing so, we&#8217;ll be able to configure our CentOS [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/how-to-create-centos-8-local-repository-mirrors-with-rsync-nginx/">How To Create CentOS 8 Local Repository Mirrors With Rsync &amp; Nginx</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Today, we are going to create CentOS 8 Local Repository Mirrors on our CentOS 8 with the help of Rsync &amp; Nginx. We can create by Local cron jobs through which we can checks for updates in the upstream repositories &amp; update them locally accordingly.</p>



<p>By doing so, we&#8217;ll  be able to configure our CentOS 8 servers to access the packages without connecting to the Internet. It helps us in reducing the amount of BandWidth and improves security control. Time can also be saved which is being consumed by pulling RPM packages from external sources.</p>



<p>Before going to start make sure you&#8217;ve an external storage with enough capacity to host repository packages &amp; potential growth.</p>



<h3><strong>Step 1: Install Nginx Server</strong></h3>



<pre class="wp-block-verse">sudo dnf -y install @nginx</pre>



<p>Start &amp; enable the nginx services.</p>



<pre class="wp-block-verse">sudo systemctl enable --now nginx</pre>



<p>Double check that the status is in working state.</p>



<pre class="wp-block-verse">systemctl status nginx</pre>



<p><strong>Allow Firewall control.</strong></p>



<pre class="wp-block-verse">sudo firewall-cmd --add-service=http --permanent<br>sudo firewall-cmd --reload</pre>



<h3><strong>Step 2: Create Repository Directories</strong></h3>



<p>In my server the secondary storage capacity is of 100 GB that I can easily use to store data /dev/vdc.</p>



<pre class="wp-block-verse">$ lsblk <br> NAME        MAJ:MIN RM SIZE RO TYPE MOUNTPOINT<br> vda         252:0    0  20G  0 disk <br> ├─vda1      252:1    0   1G  0 part /boot<br> └─vda2      252:2    0   9G  0 part <br>   ├─cl-root 253:0    0   8G  0 lvm  /<br>   └─cl-swap 253:1    0   1G  0 lvm  [SWAP]<br> vdc         252:32   0  100G 0 disk </pre>



<p>Now, we will create partition on this disk and mount it under /data directory.</p>



<pre class="wp-block-verse">sudo parted -s -a optimal -- /dev/vdc mklabel gpt<br>sudo parted -s -a optimal -- /dev/vdc mkpart primary 0% 100%<br>sudo parted -s -- /dev/vdc align-check optimal 1</pre>



<p>Next, create a physical volume &amp; group volume in this disk.</p>



<pre class="wp-block-verse">$ sudo pvcreate /dev/vdc1<br>Physical volume "/dev/vdc1" successfully created.<br><br> $ sudo vgcreate data /dev/vdc1<br>  Volume group "data" successfully created</pre>



<p>In the next step we&#8217;ll create a logical volume on this disk</p>



<pre class="wp-block-verse">$ sudo lvcreate -n repos -l+100%FREE data<br>
Logical volume "repos" created.</pre>



<p>Now, create a file system on the given disk.</p>



<pre class="wp-block-verse">$ sudo mkfs.xfs /dev/mapper/data-repos<br> meta-data=/dev/mapper/data-repos isize=512    agcount=4, agsize=1965824 blks<br>          =                       sectsz=512   attr=2, projid32bit=1<br>          =                       crc=1        finobt=1, sparse=1, rmapbt=0<br>          =                       reflink=1<br> data     =                       bsize=4096   blocks=7863296, imaxpct=25<br>          =                       sunit=0      swidth=0 blks<br> naming   =version 2              bsize=4096   ascii-ci=0, ftype=1<br> log      =internal log           bsize=4096   blocks=3839, version=2<br>          =                       sectsz=512   sunit=0 blks, lazy-count=1<br> realtime =none                   extsz=4096   blocks=0, rtextents=0</pre>



<p>To mount the Logical Volume, make a directory for it.</p>



<pre class="wp-block-verse">sudo mkdir /data</pre>



<p>Now, create a mount point</p>



<pre class="wp-block-verse">sudo vim /etc/fstab<br>/dev/mapper/data-repos /data xfs defaults 0 0 </pre>



<p>Proceed with mounting it.</p>



<pre class="wp-block-verse">sudo mount -a</pre>



<p>Make sure it is mounted.</p>



<pre class="wp-block-verse">$ df -hT /data<br>Filesystem             Type  Size   Used   Avail Use% Mounted on<br> /dev/mapper/data-repos xfs   100G   247M   100G   1%  /data</pre>



<p>For storing data in repositories, create a base directory.</p>



<pre class="wp-block-verse">sudo mkdir -p /data/repos/centos/8/</pre>



<p>Make sure all directories are created.</p>



<pre class="wp-block-verse">$ tree /data/<br> /data/<br> └── repos<br>     └── centos<br>         └── 8<br> 3 directories, 0 files </pre>



<h3><strong>Step 3: Create Repositories Sync script</strong></h3>



<p>We need a script for syncing contents from the remote repositories to the our local system</p>



<pre class="wp-block-verse">sudo vim /etc/centos8_reposync.sh</pre>



<p>Copy and paste the given data into that file.</p>



<pre class="wp-block-verse">!/bin/bash<br> repos_base_dir="/data/repos/centos/8/"<br> Start sync if base repo directory exist<br> if [[ -d "$repos_base_dir" ]] ; then<br>   # Start Sync<br>   rsync  -avSHP --delete rsync://mirror.liquidtelecom.com/centos/8/  "$repos_base_dir"<br> Download CentOS 8 repository key<br> wget -P $repos_base_dir wget https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official</pre>



<p>Run the following command to make the script executable.</p>



<pre class="wp-block-verse">sudo chmod +x /etc/centos8_reposync.sh</pre>



<p>Now install Tmux &amp; initiate first execution.</p>



<pre class="wp-block-verse">sudo yum -y install tmux<br>tmux<br> sudo /etc/centos8_reposync.sh</pre>



<p>You&#8217;ll see the script start running.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="695" height="319" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/tmux-script-start.jpg" alt="" class="wp-image-15986" srcset="https://www.osradar.com/wp-content/uploads/2019/11/tmux-script-start.jpg 695w, https://www.osradar.com/wp-content/uploads/2019/11/tmux-script-start-300x138.jpg 300w" sizes="(max-width: 695px) 100vw, 695px" /></figure></div>



<p>Various directories will be created.</p>



<pre class="wp-block-verse">$ ls -1 /data/repos/centos/8/<br> AppStream<br> BaseOS<br> centosplus<br> COMPOSE_ID<br> cr<br> extras<br> fasttrack<br> isos<br> PowerTools</pre>



<p>When the script finish up then create a cron job for weekly sync.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="699" height="177" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/finish-script-tmux.jpg" alt="" class="wp-image-15987" srcset="https://www.osradar.com/wp-content/uploads/2019/11/finish-script-tmux.jpg 699w, https://www.osradar.com/wp-content/uploads/2019/11/finish-script-tmux-300x76.jpg 300w, https://www.osradar.com/wp-content/uploads/2019/11/finish-script-tmux-696x177.jpg 696w" sizes="(max-width: 699px) 100vw, 699px" /></figure></div>



<p> You can set your desired time I&#8217;m going to set it every Sunday at 6 pm.</p>



<pre class="wp-block-verse">$ sudo crontab -e<br> 00 18 * * 7  /etc/centos8_reposync.sh </pre>



<h3><strong>Step 4: Configuring Nginx</strong></h3>



<p>First of all create a nginx config file to serve the repository contents.</p>



<pre class="wp-block-verse">$ sudo vim /etc/nginx/conf.d/centos.conf<br> server {<br>     listen 80;<br>     server_name <a href="https://www.osradar.com">repos.example.com</a>;<br>         root /data/repos/;<br> <code>   location / {             autoindex on;     }</code><br> }</pre>



<p>Note:<strong> <a href="https://www.osradar.com">repos.example.com</a></strong> is the your domain name, so set it accordingly to access the repositories.</p>



<p>Make sure you&#8217;ve configure SELinux  labels.</p>



<pre class="wp-block-verse">sudo semanage fcontext -a -t httpd_sys_content_t "/data/repos(/.*)?"<br>sudo restorecon -Rv /data/repos</pre>



<p>Restart nginx services</p>



<pre class="wp-block-verse">sudo nginx -t<br>sudo systemctl restart nginx</pre>



<p>Check that nginx is working by the URL <a href="https://www.osradar.com">repos.osradar.com</a><br> Note: You can use your own domain to access this.</p>



<h3><strong>Step 5: Configuring CentOS 8 Client machines</strong></h3>



<p>To use the local repositories, we have to configure our CentOS machines as our mirror is ready.</p>



<p>Take a backup of current repositories before proceeding.</p>



<pre class="wp-block-verse">cd /etc/yum.repos.d/<br>sudo mkdir old-repos<br>sudo mv *.repo old-repos</pre>



<p>Make a new repository file.</p>



<pre class="wp-block-verse">sudo vim local.repo</pre>



<p>Copy &amp; paste the given data into above file.</p>



<pre class="wp-block-verse">[BaseOS]<br> name=CentOS-$releasever - Base<br> baseurl=http://repos.osradar.com/centos/$releasever/BaseOS/$basearch/os/<br> gpgcheck=1<br> enabled=1<br> gpgkey=http://repos.osradar.com/centos/$releasever/RPM-GPG-KEY-CentOS-Official<br> [AppStream]<br> name=CentOS-$releasever - AppStream<br> baseurl=http://repos.osradar.com/centos/$releasever/AppStream/$basearch/os/<br> gpgcheck=1<br> enabled=1<br> gpgkey=http://repos.osradar.com/centos/$releasever/RPM-GPG-KEY-CentOS-Official<br> [centosplus]<br> name=CentOS-$releasever - Plus<br> baseurl=http://repos.cosradar.com/centos/$releasever/centosplus/$basearch/os/<br> gpgcheck=1<br> enabled=0<br> gpgkey=http://repos.osradar.com/centos/$releasever/RPM-GPG-KEY-CentOS-Official<br> [extras]<br> name=CentOS-$releasever - Extras<br> baseurl=http://repos.osradar.com/centos/$releasever/extras/$basearch/os/<br> gpgcheck=1<br> enabled=1<br> gpgkey=http://repos.osradar.com/centos/$releasever/RPM-GPG-KEY-CentOS-Official<br> [PowerTools]<br> name=CentOS-$releasever - PowerTools<br> baseurl=http://repos.osradar.com/centos/$releasever/PowerTools/$basearch/os/<br> gpgcheck=1<br> enabled=0<br> gpgkey=http://repos.osradar.com/centos/$releasever/RPM-GPG-KEY-CentOS-Official<br> [cr]<br> name=CentOS-$releasever - cr<br> baseurl=http://repos.osradar.com/centos/$releasever/cr/$basearch/os/<br> gpgcheck=1<br> enabled=0<br> gpgkey=http://repos.osradar.com/centos/$releasever/RPM-GPG-KEY-CentOS-Official<br> [fasttrack]<br> name=CentOS-$releasever - fasttrack<br> baseurl=http://repos.osradar.com/centos/$releasever/fasttrack/$basearch/os/<br> gpgcheck=1<br> enabled=0<br> gpgkey=http://repos.osradar.com/centos/$releasever/RPM-GPG-KEY-CentOS-Official</pre>



<p><strong>Note</strong>: You can use your own domain for this.</p>



<p>Now clean up current repo cache by the following command</p>



<pre class="wp-block-verse">sudo yum clean all</pre>



<p>After it update it.</p>



<pre class="wp-block-verse">$ sudo yum makecache<br>
CentOS-8 - AppStream                                                                                               1.2 MB/s | 4.3 kB     00:00    <br>
CentOS-8 - Base                                                                                                    3.9 kB/s | 3.9 kB     00:01    <br>
CentOS-8 - Extras                                                                                                  881 kB/s | 1.5 kB     00:00    <br>
Metadata cache created.</pre>



<p>Now list repositories and run system update.</p>



<pre class="wp-block-verse">sudo yum repolist</pre>



<pre class="wp-block-verse">sudo yum -y update</pre>



<h3><strong>Step 6: Enable repositories which are being disabled</strong></h3>



<p>By default, some repositories are disable. Enable them by following command.</p>



<pre class="wp-block-verse">sudo yum istall yum-utils</pre>



<p>Type given command to activate the repository.</p>



<pre class="wp-block-verse">sudo yum-config-manager --enable reponame</pre>



<p>Enable PowerTools &amp; centosplus repositories.</p>



<pre class="wp-block-verse">sudo yum-config-manager --enable PowerTools<br>sudo yum-config-manager --enable centosplus</pre>



<p>Double check these </p>



<pre class="wp-block-verse">$ sudo yum repolist <br> CentOS-8 - AppStream                                                                                               1.7 MB/s | 4.3 kB     00:00    <br> CentOS-8 - Base                                                                                                    2.0 MB/s | 3.9 kB     00:00    <br> CentOS-8 - PowerTools                                                                                               75 MB/s | 1.8 MB     00:00    <br> CentOS-8 - Plus                                                                                                     58 MB/s | 833 kB     00:00    <br> CentOS-8 - Extras                                                                                                  783 kB/s | 1.5 kB     00:00    <br> repo id                                                          repo name                                                                   status<br> AppStream                                                        CentOS-8 - AppStream                                                        5,089<br> BaseOS                                                           CentOS-8 - Base                                                             2,843<br> PowerTools                                                       CentOS-8 - PowerTools                                                       1,507<br> centosplus                                                       CentOS-8 - Plus                                                                26<br> extras                                                           CentOS-8 - Extras                                                               3</pre>



<p>To disable, substitue <strong>-enable </strong>with <strong>-disable</strong>.</p>



<p>Congratulations you&#8217;ve done. Here&#8217;s the similar tutorial if you want to sync through satellite.</p>



<p><a href="https://www.osradar.com/?p=15929">How To Sync CentOS 8 repositories on Satellite / Katello / Foreman</a></p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/how-to-create-centos-8-local-repository-mirrors-with-rsync-nginx/">How To Create CentOS 8 Local Repository Mirrors With Rsync &amp; Nginx</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.osradar.com/how-to-create-centos-8-local-repository-mirrors-with-rsync-nginx/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
