Thursday, July 30, 2015

How to create a HTTP YUM repository

YUM is a tool for automating package maintenance for a network of workstations running any operating system that use the Red Hat Package Management (RPM) system for distributing packaged tools and applications. It is derived from YUP, an automated package updater originally developed for Yellowdog Linux, hence its name: yum is "Yellowdog Updater, Modified".

YUM stands for Yellow dog UpdaterModified because it is based on YUP, the Yellow dog UpdaterYellow Dog is a version of Linux for the Power Architecture hardware. YUP, and later YUM, were written by the Linux community as a way to maintain an RPM-based system.

To setup a YUM server we should have following packages installed

deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
createrepo-0.9.8-4.el6.noarch.rpm

In CentOs-6.5 mostly these packages are installed by default.

Now first install httpd and from httpd we will point our yum repository

yum install httpd

Now open httpd.conf file i.e vi /etc/httpd/httpd.conf

In that search for DocumentRoot check the path provided in that. If you want you can change the path, basically it will serve the data from there.
Suppose i set the path to /var/www/html
i.e
DocumentRoot "/var/www/html"
Also in Directory the above should be mentioned
<Directory "/var/www/html">

Now, go under /var/www/html and create a html file to test the page are serving from our path or not.
cd /var/www/html/
vi index.html
<html><body><h1>It works!</h1></body></html>
:wq

Now restart httpd if its already running 
service httpd restart

Now open the page in browser "http://localhost" and check "It works" is coming or not.

If our index.html is working fine it means our data is properly serving from /var/www/html

Now we will create our own repository
Go under /var/lib/www
cd /var/lib/www

Create a dir with name yum

mkdir yum

In that create your own repo dir by any name that you want
For ex: 
mkdir myrepo

In that create our repo file
Ex; my.repo

vi my.repo

# Huzefa YUM Repository
# Please contact at huzefa.hamdard@gmail.com
# version- 10072013

# Default Base packages
# $YUM0 is exported through deployment script in /etc/profile  and /root/.bashrc
# export YUM0=`cat /etc/redhat-release | cut -d " " -f3`
# $basearch is the yum varibale which is equal to `uname -i`


#Additional packages required huz-repo
[huz-repo]
name=huz-repo
baseurl=http://192.168.236.132/yum/huzrepo/$YUM0
failovermethod=priority
enabled=1

gpgcheck=0
#END OF FILE


In that add the create a dir for every rpm versions
Suppose you want to add repo for centos version 6 then create dir with name 6
mkdir 6
In that create directory for 64 bit and 32 bit
mkdir x86_64 
mkdir i386

Suppose we have a rpm file for 64 bit then put it in x86_64 folder
and in the x86_64 folder fire this below command
createrepo .
This command will create repodata directory.

Full directory structure is as follows



Now our rpm server is setup, just restart httpd server once
service httpd restart

Now go to the browser and check you are able to see the rpm that we have uploaded

http://localhost/yum/myrepo/

Now on Client Side

Go to ur  CLIENT machine from where you want to access the repo.

Go to
cd /etc/yum.repos.d
Here you will see by default Centos repos, If you want for testing puporse you can rename all the repos which are present bydefault
ex: 
mv CentOS-Base.repo CentOS-Base.repo.bck

Now we will download our own repo that we have created on client machine

wget "http://localhost/yum/myrepo/my.repo"

Now clean the yum 

yum clean all

Now check by using command repolist

yum repolist

[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
my-repo                                                                                            | 2.9 kB     00:00
my-repo/primary_db                                                                                 | 5.8 kB     00:00
repo id                                                   repo name                                                  status
my-repo                                                  my-repo                                                   1

repolist: 1


It should show our repo name i.e my-repo and in repolist it should show 1 for our 1 rpm that we have uploaded on server.

You can also check by yum info 
yum info httpd 

[root@localhost yum.repos.d]# yum info httpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Available Packages
Name        : httpd
Arch        : x86_64
Version     : 2.4.10
Release     : 1.el6
Size        : 8.4 M
Repo        : my-repo
Summary     : Apache HTTPD
URL         : http://httpd.apache.org/
License     : GPL
Description : The Apache HTTP Server is a powerful, efficient, and extensible

            : web server.

As you can see package is coming from our repo -  my-repo.

Now you can install packages from your own yum repo

yum install httpd

It will pick the packages directly from our repo. Just upload the repo on our server and access it from anywhere.















No comments:

Post a Comment