We have already shown you how to create a local repository on Ubuntu systems. Today we are going to learn about setting up local yum repository on CentOS 6.4 and other RPM based distributions.
As I noted in my previous tutorial about local repository, if you have to installed software, security updates and fixes often in multiple systems in your local network, then having a local repository is an efficient way. Because all required packages are downloaded over the fast LAN connection from your local server, so that it will save your Internet bandwidth and reduces your 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 installation DVD(s). You will probably have two DVD’s for CentOS:
[[email protected] ~]# mount /dev/cdrom /mnt/
Now the CentOS installation DVD is mounted under /mnt directory. Next install vsftpd package and make the packages available over FTP to your local clients.
To do that change to /mnt/Packages directory:
[[email protected] ~]# cd /mnt/Packages/
Now install vsftpd package:
[[email protected] 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:
[[email protected] Packages]# /etc/init.d/vsftpd start Starting vsftpd for vsftpd:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â [Â OKÂ ] [[email protected] Packages]# chkconfig vsftpd on
We need a package called “createrepo” to create our local repository. So let us install it too. If you did a minimal CentOS installation, then you might need to install the following dependencies first:
[[email protected] Packages]# rpm -ivh libxml2-python-2.7.6-8.el6_3.4.i686.rpm warning: [[email protected] Packages]# rpm -ivh deltarpm-3.5-0.5.20090913git.el6.i686.rpm [[email protected] Packages]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm
Now install “createrepo” package:
[[email protected] 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 CentOS DVD’s.
As I noted above, we are going to use a FTP server to serve all packages to client systems. So let us create a storage location in our FTP server pub directory.
[[email protected] ~]# mkdir /var/ftp/pub/localrepo
Now copy all the files from CentOS DVD(s) i.e for /mnt/Packages directory to the “localrepo” directory:
[[email protected] ~]# cp -ar /mnt/Packages/*.* /var/ftp/pub/localrepo/
Again, mount the CentOS installation DVD 2 and copy all the files to /var/ftp/pub/localrepo directory.
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:
[[email protected] ~]# vi /etc/yum.repos.d/localrepo.repo [localrepo] name=Unixmen Repository baseurl=file:///var/ftp/pub/localrepo gpgcheck=0 enabled=1
Note: Use three slashes in the baseurl.
Now begin building local repository:
[[email protected] ~]# createrepo -v /var/ftp/pub/localrepo/
Now the repository building process will start. The output will be as shown below:
After creating repository, disable or rename the existing repositories.
Now update the repository files:
[[email protected] ~]# yum clean all [[email protected] ~]# yum update
Client Side Configuration
Now go to your client systems. Create a new repository file as shown above under /etc/yum.repos.d/ directory and add the following contents:
[[email protected] ~]# 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.
Now disable or rename the existing repositories and update the local repository files:
[[email protected] ~]# yum clean all [[email protected] ~]# yum update
Probably you will get 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:
[[email protected] ~]# 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:
[[email protected] ~]# setsebool -P ftp_home_dir on
Now try again by updating repository:
[[email protected] ~]# yum update
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.
Let us try install any package. For instance I do httpd package installation:
[[email protected] ~]# yum install httpd
Now you might be able to install softwares from your server local repository.