Skip to main content

Crearting YUM Repositroy

Setup Local Yum Repository on CentOS/RHEL 6.4



 Today we are going to learn about setting up local yum repository on CentOS 6.4 and other RPM based distributions.

Why Local repository is important?

As a System administrator, you have to install software, security updates and fixes often in all systems. Obviously, it will consume more Internet bandwidth. 

So instead of downloading and installing applications every time in all systems from Internet repositories of Linux distribution, it is good idea to save all applications in a local server in your LAN and distribute them to the other Linux systems when required.

Having a local repository is really fast and efficient way, because all required applications will be transferred over the fast LAN connection from your local server. So that it will save the Internet bandwidth and ultimately it reduces the annual cost of Internet.

In this tutorial I use two systems as described below:
Yum Server OS         : CentOS 6.4(Minimal Install)
Yum Server IP Address : 192.168.1.200
Client OS             : CentOS 6.3(Minimal Install)
Client IP Address     : 192.168.1.201

Prerequisites
First mount your CentOS 6.4/RHEL 6.4 installation DVD(s) or ISO image on to the system on which you need to create repository.
[root@server ~]# mount -t iso9660/dev/cdrom /mnt/


Mounting the CD/DVD on to the system:

If your device is only CD reader use below command
mount -t iso9660 /dev/cdrom /mnt/

If your device is a CD read-write use below command
mount -t iso9660 /dev/cdrw /mnt

If your device is a DVD reader use below command
mount -t iso9660 /dev/dvdrom /mnt

If your device is a DVD writer use below command
mount -t iso9660 /dev/dvd-rw /mnt


Mounting the ISO image file on to the system:

If you don't have any dvd don't panic, we can continue still if we have the ISO image of OS. Simply copy the ISO file on system and mount it at /mnt or any other directory on system.
mount -o loop Study/OS/RHEL_6_2_19089-CXP9034733_1_PA4.iso /tmp/mnt

Now the OS installation DVD/ISO is mounted under /mnt directory. Next install vsftpd package.

To do that change to /mnt/Packages directory:
[root@server ~]# cd /mnt/Packages/
Now install vsftpd package:
[root@server Packages]# rpm -ivh vsftpd-2.2.2-11.el6_3.1.i686.rpm 
warning: vsftpd-2.2.2-11.el6_3.1.i686.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
      1:vsftpd              ########################################### [100%]

Start FTP service and let the service to be started automatically on every reboot:
[root@server Packages]# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]
[root@server Packages]# chkconfig vsftpd on
We need a package called “createrepo”  to create our local repository. Before installing createrepo package, you need to install the following dependencies first:
[root@server Packages]# rpm -ivh libxml2-python-2.7.6-8.el6_3.4.i686.rpm warning: 
[root@server Packages]# rpm -ivh deltarpm-3.5-0.5.20090913git.el6.i686.rpm 
[root@server Packages]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm
Now install “createrepo” package:
[root@server Packages]# rpm -ivh createrepo-0.9.9-17.el6.noarch.rpm

Build Local Repository
It’s time to build our local repository. Create a storage directory to store all packages from the mounted DVD/ISO.
As I explained earlier, we are going to use FTP server to serve all packages to client systems. So let us create a storage location in our FTP server pub directory.
[root@server ~]# mkdir /var/ftp/pub/localrepo

Now copy all the files from CentOS DVD(s) i.e for /mnt/Packages directory to the“localrepo” directory:
[root@server ~]# cp -ar /mnt/Packages/*.* /var/ftp/pub/localrepo/

If you are using DVD then again, mount the OS installation DVD 2 and copy all the files to/var/ftp/pub/localrepo directory. In case of ISO image all packages are copied at once.
Once you copied all the files, create a repository file called “localrepo.repo” under/etc/yum.repos.d/ directory and add the following lines into the file. You can name this file as your liking:
[root@server ~]# vi /etc/yum.repos.d/localrepo.repo
[localrepo]
name=Local Server Repository
baseurl=file:///var/ftp/pub/localrepo
gpgcheck=0
enabled=1

Note: Use three slashes in the baseurl.
Now begin building local repository using create repo command:
[root@server ~]# chmod 777 /etc/yum.repos.d/localrepo.repo
[root@server ~]# createrepo -v /var/ftp/pub/localrepo/

Now the repository building process will start. The output will be as shown below:



After creating repository, update the repository files:
[root@server ~]# yum clean all
[root@server ~]# yum update

Client Side Configuration
Now, If you want to configure repository on any client just go to your client systems. Create a new repository file as shown above under/etc/yum.repos.d/ directory and add the following contents:
[root@client ~]# vi /etc/yum.repos.d/localrepo
[localrepo]
name=Unixmen Repository
baseurl=ftp://192.168.1.200/pub/localrepo
gpgcheck=0
enabled=1
Note: Use double slashes in the baseurl and 192.168.1.200 is yum server IP Address.
Then simply update the local repository files on client:
[root@client ~]# yum clean all
[root@client ~]# yum update

Now if everything works fine you will get below screen output:


As you seen in the above output, now your client will get the updates from our server“localrepo” repository, not from any other external repositories.

To install any package use command "yum install package-name". For instance to install httpd package we use:
[root@client ~]# yum install httpd


To un-install any package use command "yum remove package-name".
Now you might be able to install softwares from your server local repository.

Ehh... didn't work well, probably you got an error like shown below:
ftp://192.168.1.200/pub/localrepo/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
  Trying other mirror.
This is because your firewall and SELinux might be preventing your client to access the local repository server. So run the following commands in the server side. Allow the default firewall port 21 through your Firewall/Router:
[root@server ~]# vi /etc/sysconfig/iptables
[...]
-A INPUT -p udp -m state --state NEW --dport 21 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 21 -j ACCEPT
[...]
And update the SELinux booleans for FTP service:
[root@server ~]# setsebool -P ftp_home_dir on
Now try again by updating repository, everything will start working !!. 
Some Important yum configuration files and path:
/etc/yum.conf
/etc/yum/repos.d/
/etc/yum/pluginconf.d/
/var/cache/yum/

Don't mes-sup with these system files if you don't know about them.
Friends please share your comments or feedback so we can improve over learning experience. 

Comments

Popular posts from this blog

20 perl programming tips

1. List all Installed Perl Modules from Unix Command Line Get a list of all installed perl modules as shown below. $ perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC' /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/HTML/Filter.pm /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/HTML/LinkExtor.pm /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/HTML/PullParser.pm /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/HTML/Parser.pm /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/HTML/TokeParser.pm ..... In the above example, File::Find  and  File::Spec::Functions  module are used to list all installed modules. -M option  loads the module. It executes  use module  before executing the script -T option  enables taint checking, which instructs perl to keep track of data from the user and avoid doing anything insecure w...

Perl and Excel: How to Read, Write, Parse Excel Files using Perl

If you want to manipulate excel files programmatically, you can use Perl Spreadsheet module, which provides an object interface that makes it easier to create and parse Excel files. Install Spreadsheet WriteExcel Module Method 1: Standard install using make Download the zipped tar file of  Spreadsheet-ParseExcel  and  Spreadsheet-WriteExcel  from cpan. Untar and unzip the module as follows: tar -zxvf Spreadsheet-WriteExcel.tar.gz cd to the directory the tar creates. Execute the steps below to to install the Spreadsheet-WriteExcel module. perl Makefile.PL make make test make install Use the above procedure to install Spreadsheet-ParseExcel also. Method 2: CPAN.pm install If you have CPAN.pm configured you can install the module as follows: perl -MCPAN -e 'install "Spreadsheet::WriteExcel"' perl -MCPAN -e 'install "Spreadsheet::ParseExcel"' For additional installation help refer to: How To Install Perl Modules Manually and Using ...

How to Connect to MySQL from Perl

How do I connect to a MySQL database from a perl program? use perl DBI module to connect to a MySQL database as explained below. If you don’t have perl DBI and DBD::mysql module installed, install perl module using cpan as we discussed earlier. # perl -MCPAN -e shell cpan> install DBI cpan> install DBD::mysql On a very high level, you’ll have to do the following three steps to connect to a MySQL database and get data. 1. Connect to the MySQL Database In the DBI module, you’ll use the connect function as shown below. $dbc = DBI->connect($source, $username, $password) DBI->connect function takes the following three arguments: $source – This is in the format of “DBI:mysql:[database]:[hostname]”. Replace the [database] and [hostname] with values from your system. In the example shown below, it is connecting to the database called “mycompany” that is running on the localhost. $username – The username that is used to connect to the MySQL database. $pass...