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:
[root@server ~]# 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:
[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. So let us install it too. If you did a minimal CentOS installation, then you might 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 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.
[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/
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:
[root@server ~]# 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:
[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, disable or rename the existing repositories.
Now update the repository files:
[root@server ~]# yum clean all [root@server ~]# 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:
[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.
Now disable or rename the existing repositories and update the local repository files:
[root@client ~]# yum clean all [root@client ~]# 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:
[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:
[root@client ~]# 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:
[root@client ~]# yum install httpd
Now you might be able to install softwares from your server local repository.