Basic usage strategy of Yum package manager under CentOS

Time:2020-11-19

1. What is Yum
yum : Yellow dog Updater, Modified
The main function is to add / delete / update RPM package more conveniently
It can solve the dependency problem of package automatically
It is easy to manage a large number of system update problems
Yum features
Multiple repositories can be configured at the same time
Simple configuration file (/ etc/ yum.conf
Automatically resolve dependency issues when adding or deleting RPM packages
Easy to use
Maintain consistency with RPM database
Yum install
We can use the rhel3 and rhel4 packages to install.
RHEL5 is installed with Yum by default and can be used directly
Yum is installed by default in CentOS and can be used directly
Yum is installed by default in Fedora and can be used directly

2. Install and update and uninstall
install

Copy code

The code is as follows:

yum install PACKAGE_NAME …

– Y: Yes for auto answer
 
If you need to install the specified version of the program:

Copy code

The code is as follows:

yum install PACKAGE-VERSION …

To re install the specified package:

Copy code

The code is as follows:

yum reinstall PACKAGE_NAME …

give an example:

Copy code

The code is as follows:

[[email protected] ~]# yum -y install creatrepo

upgrade

Copy code

The code is as follows:

yum update PACKAGE_NAME

If more than one version of the upgrade package is available and you only expect to upgrade to the specified version:

Copy code

The code is as follows:

yum update PACKAGE-VERSION

Demotion:

Copy code

The code is as follows:

yum downgrade PACKAGE_NAME

Check for available upgrades:

Copy code

The code is as follows:

yum check-update

give an example:

Copy code

The code is as follows:

[[email protected] ~]# yum update createrepo

uninstall

Copy code

The code is as follows:

yum erase|remove PACKAGE_NAME

Note: other packages that depend on the specified package will be unloaded
give an example:

Copy code

The code is as follows:

[[email protected] ~]# yum remove createrepo

3. Detailed explanation of usage of Yum common instructions
The first time you use Yum or Yum resource library to update, Yum will automatically download all required package index files and place them in / var / cache / Yum directory, which may take a long time
Update instructions of RPM package
Check for updatable RPM packages

Copy code

The code is as follows:

#yum check-update

Update all RPM packages

Copy code

The code is as follows:

#yum update

Update the specified RPM package, such as kernel and kernel source

Copy code

The code is as follows:

#yum update kernel kernel-source

Large scale version upgrade. Unlike Yum update, even old obsolete packages are upgraded

Copy code

The code is as follows:

#yum upgrade

Instructions for installing and deleting RPM packages
Install the RPM package, such as xmms-mp3

Copy code

The code is as follows:

#yum install xmms-mp3

Delete the RPM package, including those that are dependent on it
 

Copy code

The code is as follows:

#yum remove xmms-mp3

Or

Copy code

The code is as follows:

yum erase xmms-mp3

(higher version)
Yum cache (/ var / cache / Yum /) related parameters
Clear the RPM package file from the cache

Copy code

The code is as follows:

#yum clean packages

Clear RPM header file in cache

Copy code

The code is as follows:

#yum clearn headers

Clear all relevant information from the cache

Copy code

The code is as follows:

#yum clearn all

RPM packet information and list query related instructions
Lists all RPM packages in the repository that can be installed or updated

Copy code

The code is as follows:

#yum list

Lists specific RPM packages in the repository that can be installed or updated and that have already been installed

Copy code

The code is as follows:

#yum list glibc
#yum list glibc*

Lists all RPM packages in the repository that can be updated

Copy code

The code is as follows:

#yum list updates

List all RPM packages that have been installed

Copy code

The code is as follows:

#yum list installed

List installed RPM packages that are not included in the repository (download installed RPM packages from other websites)

Copy code

The code is as follows:

#yum list extras

Lists information about all RPM packages in the repository that can be installed or updated

Copy code

The code is as follows:

#yum info

Lists specific RPM packages in the repository that can be installed or updated and that have already been installed

Copy code

The code is as follows:

#yum info glibc
#yum info glibc*

Lists information about all RPM packages that can be updated in the repository

Copy code

The code is as follows:

#yum info updates

Lists information about all RPM packages that have been installed

Copy code

The code is as follows:

#yum info installed

Lists information about installed RPM packages that are not included in the repository (download information about installed RPM packages from other websites)

Copy code

The code is as follows:

#yum info extras

Search RPM packet related instructions
Search for RPM packages that match specific characters (search in RPM package name, package description, etc.)

Copy code

The code is as follows:

#yum search glibc

Search the package list file for packages that contain realplay

Copy code

The code is as follows:

#yum provides realplay

The yum command can also be used to install local RPM package files

Copy code

The code is as follows:

yum localinstall /path/to/rpm_package_file …

Install local RPM package
 
Options:
— enablerepo = enable a Yum warehouse
— disablerepo = disable a Yum warehouse
Note: priority is higher than / etc/ yum.repos . D / *. Repo configuration file;
– Y: Yes for auto answer
— nogpgcheck: does not verify the source and integrity of the package
give an example:

Copy code

The code is as follows:

[[email protected] ~]# yum -y localinstall /tmp/repos/glibc-common-2.6.32-358.el6.i386.rpm

4. Yum software warehouse building method
If you manage a large number of servers, the installation and update of RPM software packages need to access and connect to the Internet, which will lead to a slow installation of software packages and a waste of bandwidth. In order to avoid the disadvantages of the above situation, we can realize the rapid installation and update of software packages by creating our own local repository
Create the warehouse server and copy all the data in the DVD or CD distribution to the server (take CentOS 5 as an example)
Create warehouse directory

Copy code

The code is as follows:

mkdir /yum

Mount the installation media disk

Copy code

The code is as follows:

mount -o loop /download/centos5.iso /mnt

Copy the contents of the CD to the / Yum directory

Copy code

The code is as follows:

cp /mnt/* /yum

Create the index file of the software package of the repository (the createepo package needs to be installed)

Copy code

The code is as follows:

cd /yum
createrepo -g repodata/comps.xml .

(. Represents the current directory)
Configure the Apache server and point the DocumentRoot to the / Yum directory. You can list the contents of the directory (sample configuration).

Copy code

The code is as follows:

DocumentRoot “/yum”
<Directory “/yum”>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

Start Apache, the test access is normal, and the server-side settings are completed
Client settings, modify the yum configuration file (assuming server IP = 192.168.0.1)
Modify configuration file content / etc/ yum.repos .d/centos- server.repo The contents are as follows

Copy code

The code is as follows:

#cat /etc/yum.repos.d/centos-server.repo
[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
retries=20
obsoletes=1
gpgcheck=0

[centos5]
name=centos5 – Base
baseurl=http://192.168.0.1/
gpgcheck=0

Delete / etc/ yum.repos Other. Repo files in. D / directory (no other repository is used)
After the above configuration, you can use your own repository to install and update the software package. If you need to build a lot of distribution repositories, you can divide them into different directories. Refer to the following directory structure

Copy code

The code is as follows:

/yum
|– rh35-x86-32
| |– headers
| `– repodata
|– rh36-x86-32
| |– headers
| `– repodata
|– rh36-x86-64
| |– headers
| `– repodata
|– rh38-x86-32
| |– headers
| `– repodata
|– rh38-x86-64
| |– headers
| `– repodata
|– rh39-x86-32
| |– headers
| `– repodata
|– rh42-x86-32
| `– repodata
|– rh43-x86-32
| `– repodata
|– rh44-x86-32
| `– repodata
|– rh44-x86-64
| `– repodata
|– rh45-x86-64
|– rh46-x86-32
| `– repodata
|– rh46-x86-64
| `– repodata
|– rh47-x86-64
| `– repodata
|– rh48-x86-32
| `– repodata
|– rh48-x86-64
| `– repodata
|– rh50-x86-32
| `– repodata
|– rh50-x86-64
| `– repodata
|– rh52-x86-32
| `– repodata
|– rh52-x86-64
| `– repodata
|– rh53-x86-32
| `– repodata
|– rh53-x86-64
| `– repodata
|– rh54-x86-64
| `– repodata
`– update
|– rhel3-x86-32
| |– headers
| `– repodata
|– rhel3-x86-64
| |– headers
| `– repodata
|– rhel4-x86-32
| `– repodata
|– rhel4-x86-64
| `– repodata
|– rhel5-x86-32
| `– repodata
|– rhel5-x86-64
`– repodata

Then, according to the needs, set the yum configuration file of the client to use different release software warehouses!