Linux | Cloud | DevOps | Scripting

Breaking

Thursday, 14 August 2014

YUM (Yellowdog Updater Modified)

A linux Administrator needs to install or update a software or package time to time. Specially, if we are using Red Hat Enterprise Linux, then we should use "rpm" command. For example, if we want to install vsftpd package we use this command and syntax:

# rpm  -ivh  /media/<tab>...DVD.../Packages/vsftpd<tab>

Sometimes its necessary to install some packages first before installing needed package. In other words we can say, one package may dependent on other packages. So, till the time we not install dependent packages our needed package will not install. In above example of vsftpd all dependencies were installed already, so there was no error or warning message and our needed package vsftpd intalled successfully. Now, we are taking an another example of a package named kdebase.

# rpm  -ivh  /media/<tab>...DVD.../Packages/kdebase<tab>          

this shows a list of available packages starting from kdebase package. Now we try to install first one.

# rpm  -ivh  /media/<tab>...DVD.../Packages/kdebase-4.3<tab>          

This shows number of dependencies and there is a warning "Failed Dependencies". For this reason, we have to install these dependencies first to install our needed package kdebase. So, this is the problem when we installs package from rpm. Now, in Red Hat, there is one more package manager which is known as YUM. Advantage of this package manager is that it installs package and dependencies by single command. There is no need to install those dependencies manually. 

YUM (Yellowdog Updater Modified):

Yum is the Red Hat package manager that is able to query for information about available packages, fetch packages from repositories, install and uninstall them, and update an entire system to the latest available version. Yum performs automatic dependency resolution on packages you are updating, installing, or removing, and thus is able to automatically determine, fetch, and install all available dependent packages.

Yum can be configured with new, additional repositories, or package sources, and also provides many plug-ins which enhance and extend its capabilities. Yum is able to perform many of the same tasks that RPM can; additionally, many of the command line options are similar. Yum enables easy and simple package management on a single machine or on groups of them.

SPECIAL NOTE:
Yum is not able to remove a package without also removing packages which depend on it. This type of operation can only be performed by RPM, is not advised, and can potentially leave your system in a non-functioning state or cause applications to misbehave and/or crash.

YUM FOR PC:
============
# mkdir /packages2
# cp -rvf /media/<tab>/Packages/* /packages2
# rpm -ivh /media/<tab>/Packages/createrepo<tab> //this will prompt to install two dependencies deltarpm & python-deltarpm
# createrepo -cvf /packages2
# vim /etc/yum.repos.d/yum.repo
[server]
name=server
baseurl=file:///packages2
enabled=1
gpgcheck=0
[save & quit] :wq!
# yum clean all
# yum list all

YUM FROM FTP (ftp://instructor.example.com):
====================================
# vim /etc/yum.repos.d/yum.repo
[server]
name=server
baseurl=ftp://instructor.example.com/pub/rhel6/dvd
enabled=1
gpgcheck=0
[save & quit] :wq!
# yum clean all
# yum list all

BASIC YUM COMMAND:
=====================
yum list [available|installed|extras|updates|obsoletes|all|recent] [pkgspec]

By default 'yum list' without any options will list all packages in all the repositories and all the packages installed on your system. Note: 'yum list all' and 'yum list' give the same output.
# yum list available

Checking for updates
# yum check-update

Updating a single package
# yum update package_name

Updating All Packages and T heir Dependencies
# yum update

Searcing Packages
# yum search term...

Lists all package groups.
# yum grouplist

Lists the repository ID, name, and number of packages it provides for each enabled repository.
# yum repolist

Displaying Package Information
# yum info package_name

Lists all the packages available to be installed in any enabled repository on your system.
# yum list installed

This is equivalent to rpm -qa. It lists all the packages installed on the system.
# yum list extras

This command lists any installed package which no longer appears in any of your enabled repositories. Useful for finding packages which linger between upgrades or things installed not from a repo.
# yum list obsoletes

This command lists any obsoleting relationships between any available package and any installed package.
# yum list updates

This command lists any package in an enabled repository which is an update for any installed package.
#yum list recent

This command lists any package added to any enabled repository in the last seven(7) days.
# yum list pkgspec

Exactly like yum list updates but returns an exit code of 100 if there are updates available. Handy for shell scripting.
   yum grouplist
   yum groupinfo
   yum groupinstall
   yum groupupdate
   yum groupremove

You can install a package group by passing its full group name (without the groupid part) to
# yum groupinstall group_name

You can also install by groupid:
# yum groupinstall groupid

# yum clean packages
This cleans up any cached packages in any enabled repository cache directory.

# yum clean metadata
This cleans up any xml metadata that may have been cached from any enabled repository.

# yum clean dbcache
Yum will create or download some sqlite database files as part of its normal operation. This command clean up the cached copies of those from any enabled repository cache.

# yum clean all
Clean all cached files from any enabled repository. Useful to run from time to time to make sure there is nothing using unnecessary space.

~] # vim  /etc/yum.conf

We can put all our reposetories in this file. But if we want to define all of them saperately, then we can put all of them in saperate files in /etc/yum.repos.d directory with the format of  'file.repo'.

[main]
To set global settings of all defined reposetories we can define multiple paths of multiple reposetories.

cached
location of yum database and cache

keepcache
ensures that in cache it will share data of header files of a package on a installation or not

debugvalue=2
size of debug output of yum (1-10; increased number of values shows detailed data of debug)

logfile
information of login

extractarch
by using value 1, it will match the architecture of package on installation by yum. (E.g. if we want to update a pack with arch i386 with the arch update i686; then yum will not update that package)
obsolates

on installation of pre-installed package, by using value 1, it will install new package after replacing old obsolate package.

gpgcheck
(GNU Private Guard) used for packages key verification.

plugins
There are lots of plugins which extends/increase the capicity of yum by using value 0 or 1. We can enable and disable saperately in files.

To list number of plugins:
~] # ll /etc/yum/pluginconf.d/

1. blacklist.conf
2. refresh-packagekit.conf
3. rhnplugion.conf
4. whiteout.conf

For example, if we donot wat to use refresh-packagekit.conf then we can modify it.
~] # vim /etc/yum/pluginconf.d/refresh-packagekit.conf
[main]
enabled=1
if we donot want to use this plugin then we have to set enabled=0

installonly_limit
specifies how many different versions of a package can install. E.g. if we set its value "3" then yum can install three different virsions of a package.

=> createrepo:
it creates a database of all packages we copied from disk. It stores all information in three different lines like package names, type of package and which package is dependent on which package. It will also create a new directory repodata among packages.

=> reposetory:
~] # vim /etc/yum.conf
1. [rhel6_repo]                    //specifies ID of reposetory with no space, to use different names we may use underscore between them.
2. name=RHEL6 local reposetory
3. baseurl=file:///packages2           //path where our repodata folder exists
4. gpgcheck=1                                    //value1 verifies the package key (for this, we can make entry of package key here in gpgkey and also we can import that on the time of package installation), whereas value 0 installs packages wothout verify package key
5. gpgkey=file:///rhel6repo/TPM-GPG-KEY-redhat-release             //found in disk

=> Now, if we want to create saperate reposetories, we have to delete previous entries of /etc/yum.conf

First, copy all packages from disk to a dir (e.g. /packages2)
~] # vim /etc/yum.repos.d/rhel6local.repo
[rhel6_repo]
name=RHEL6 local repo
baseurl=file:///packages2
enabled=1
gpgcheck=1

~] # rpm -q vsftpd
~] # yum search vsftpd
ERROR: sometimes a packagekit... file creates so, we have to delete it (~] # rm /etc/yum.repos.d/packagekit...)
~] # yum install vsftpd
ERROR: public key for vsftpd... is not installed

Now, import gpgkey;
~] # rpm --import /rhel6repo/RPM-GPG-KEY-redhat-release

~] # yum install vsftpd

~] # yum list all
~] # yum list installed
~] # yum list installed | grep vsftpd

=> GROUPYUM
If all rpm are divided among some groups like kde-desktop, then we can install kde-desktop to install all packages in this group. If

we want to install all packages of a group.

~] # yum grouplist
ERROR: no groupdata available for configured reposetory.
To resolve this we have to use again createrepo command.

~] # createrepo -g /rhel6repo/repodata               OR
~] # createrepo -g /media/DVD/repodata
............................................................................
............................................................................
............................................................................
......................................................-comps-rhel6-server.xml
............................................................................
............................................................................
............................................................................

~] # createrepo -g /media/DVD/repodata/..............-comps-rhel6-server.xml  /rhel6repo/packages2
[time taking]
~] # yum clean all
~] # yum makecache

~] # yum grouplist
~] # yum grouplist | less

~] # yum groupinstall kde-desktop -y          //it will install all packages of kde-desktop group and their dependencies together.

~] # yum groupremove kde-desktop -y          //it will uninstall all packages of kde-desktop group.

=> INSTALL PACKAGE FROM REMOTE MACHINE:
If we have one FTP server or web server(HTTP) on our LAN then there is no need to make yum server on each of them.

Configuration of HTTP server:
~] # yum install httpd -y
~] # vim /etc/httpd/conf/httpd.conf
[in last]
alias /myrepo /rhel6repo
<Directory /rhel6repo>
order allow,deny
allow from all
Options Indexes Follow SymLinks          //for listing of diretory
</Directory>

~] # service httpd restart
~] # chkconfig httpd on

~] # firefox http://192.168.0.1          //it will show default page of RedHat Enterprise Linux Test Page
~] # firefox http://192.168.0.1          //it will list /rhel6repo directory
...........................................................
...........................................................
...........................................................

Configuration of FTP server:
~] # yum install vsftpd -y
Default Document Root:  /var/ftp/pub          (accessable for anonymous user)

~] # ll /var/ftp/pub
~] # ll /rhel6repo          //we have all the contents of /rhel6repo in /var/ftp/pub, for this we can mount it on pub

~] # mount --bind  /rhel6repo /var/ftp/pub
~] # ll /var/ftp/pub
~] # chmod -R 755 /var/ftp/pub

~] # service vsftpd restart
~] # chkconfig vsftpd on

~] # firefox ftp://192.168.0.1          //it will list 'pub' directory

=> As we use FTP and HTTP on other pc then some problems may occur due to SELINUX and FIREWALL

SELINUX:
~] # sestatus          //check current mode and configuration file mode
~] # eth0  >  /selinux/enforce

FIREWALL:
~] # system-config-firewall          //here, tick on FTP or HTTP as your secure services and click on apply

=> Now, make configuration on machine2 with IP 192.168.0.2
First, check on firefox: http://192.168.0.1/myrepo          OR
~] # ftp://192.168.0.1          //it will list 'pub' directory

1) HTTP Configuration:
~] # vim /etc/yum.conf
[rhel6_repo]
name=Rhel6 repo on machine2
baseurl=http://192.168.0.1/myrepo/packages
eenabled=1
gpgcheck=1
gpgkey-http://192.168.0.1/myrepo/RPM-GPG-KEY-redhat-release

~] # yum clean all
~] # yum list all

2) FTP Configuration:
~] # vim /etc/yum.conf
[rhel6_repo]
name=Rhel6 repo on machine2
baseurl=ftp://192.168.0.1/pub/packages
eenabled=1
gpgcheck=1
gpgkey=ftp://192.168.0.1/pub/RPM-GPG-KEY-redhat-release

~] # yum clean all
~] # yum list all

=====================================================================


Thanks for reading this article...

No comments:

Post a Comment

Pages