Tuesday, April 6, 2010

Howto setup local yum repository on RedHat Fedora12 Centos5.4

This article is about Setting up a Local yum repository to be used for local network. Local Yum Repository can save internet bandwidth downloading all your packages from the local repository over FAST LAN Network.

If You want to use it in your network the best option to be used is using Httpd - Apache so the yum repository will be acessible via web.

Step 1
Check if Httpd is installed and running

[root@localhost ~]# ps ax | grep http

3617 ? Ss 0:00 /usr/sbin/httpd
3621 ? S 0:00 /usr/sbin/httpd
3622 ? S 0:00 /usr/sbin/httpd
3623 ? S 0:00 /usr/sbin/httpd
3624 ? S 0:00 /usr/sbin/httpd
3625 ? S 0:00 /usr/sbin/httpd
3626 ? S 0:00 /usr/sbin/httpd
3627 ? S 0:00 /usr/sbin/httpd
3628 ? S 0:00 /usr/sbin/httpd
3629 ? S 0:00 /usr/sbin/httpd

If it is not running then Start HTTPD

[root@localhost ~]# /etc/init.d/httpd start

OR

[root@localhost ~]# service httpd start


and if you haven't installed httpd yet then you can do it by

[root@localhost ~]# yum install httpd


Now make httpd start at every system boot automatically by putting it in system Startup.

[root@localhost ~]# chkconfig --levels 235 httpd on

Start apache
[root@localhost ~]# /etc/init.d/httpd start
OR
[root@localhost ~]# service httpd start


How to Build the Repository
We will use Apache's default Document root to store the packages, Default DocumentRoot for apache is "/var/www/html".

Create a dir in the Document Root named yum. We will create two more directories
base-pkg : This would contain all the packages of the Linux Distribution you are making repository for.
updates : This would contain all the update packages for your Linux Distribution

[root@localhost ~]# mkdir /var/www/html/yum
[root@localhost ~]# mkdir /var/www/html/yum/base-pkg
[root@localhost ~]# mkdir /var/www/html/yum/updates


BUILDING YOU REPOSITORY

To build you yum repository the easy way is copy all the contents from the Linux Distribution DVD/CD Media to the repository location in this case /var/www/html/yum, Make sure that you copy all the contents (Packages) into the base-pkg directory. If you have a Media follow the Steps Below


[root@localhost ~]# mount /dev/cdrom /mnt
[root@localhost ~]# cp -v /mnt/Packages/* /var/www/html/yum/base-pkg/
[root@localhost ~]# umount /mnt


Now we need a tool "createrepo" which would create a repository for the linux distibution. By default it is comes installed with all Distribution of linux, but if its not installed use yum to install it.
Check if createrepo is installed
[root@localhost ~]# which createrepo
/usr/bin/createrepo


If you get the above result skip the next step and start Building the repository if its not installed then install it
[root@localhost ~]# yum install createrepo


Now Run the createrepo tool

[root@localhost ~]# createrepo /var/www/html/yum/base-pkg/

[root@localhost ~]# ls -l /var/www/html/yum/base-pkg/repodata/
-rw-r--r-- 1 root root 2227275 2010-02-18 11:51 filelists.xml.gz
-rw-r--r-- 1 root root 6487453 2010-02-18 11:51 other.xml.gz
-rw-r--r-- 1 root root 747714 2010-02-18 11:51 primary.xml.gz
-rw-r--r-- 1 root root 951 2010-02-18 11:51 repomd.xml

The Second step building repository is updating your updates directory for all new packages. Go to the Main website of the Linux Distribution you are preparing repostory for and check the updates link or use the below links

CENTOS : rsync://centos.arcticnetwork.ca/centos/5.4/updates/i386/RPMS/
FEDORA : rsync rsync://mirror.aarnet.edu.au/fedora/linux/updates/12/i386/

As per you distribution rsync the data to the updates directory
FOR CENTOS RUN
[root@localhost ~]# rsync -avrt rsync://centos.arcticnetwork.ca/centos/5.4/updates/i386/RPMS/ --exclude=debug/ /var/www/html/yum/updates/
FOR CENTOS RUN
[root@localhost ~]# rsync -avrt rsync://mirror.aarnet.edu.au/fedora/linux/updates/12/i386/ --exclude=debug/ /var/www/html/yum/updates/


To get the updates regularly you can put the above command inthe crontab so that you updates directories are updated periodically

[root@localhost ~]# crontab -e 
* * 2 * * rsync -avrt rsync://centos.arcticnetwork.ca/centos/5.4/updates/i386/RPMS/ --exclude=debug/ /var/www/html/yum/updates/


You have created local yum repository, now to make clients on your network to use the local repository, create a file mylocal.repo in /etc/yum.repos.d

[root@localhost ~]# vim /etc/yum.repos.d/mylocal.repo
Add the Following Lines

[base-local]
name=Centos $releasever - $basearch
failovermethod=priority
baseurl=http://192.168.1.1/yum/base-pkg/
enabled=1
gpgcheck=0

[updates-local]
name=Centos $releasever - $basearch - Updates
failovermethod=priority
baseurl=http://192.168.1.1/yum/updates/
enabled=1
gpgcheck=0


THAT's IT, Now you can update all your packages over high Speed Lan connectivity instead of Internet.

3 comments:

  1. good one....thanks

    ReplyDelete
  2. Your blog is quite helpful,I desire to connect with u,could i sent electronic mail to you?

    ReplyDelete
  3. Heaven has eyes ah, let me live long enough to get such a fantastic view of the post!

    ReplyDelete