Configuration and use of centos Yum Source

Source: Internet
Author: User
Tags ftp site

1. Introduction to yum

Yum, short for Yellow Dog Updater and modified, is a software package manager developed by Duke University to improve the installation of RPM software packages. It was initially developed by Terra soft, a developer of the Yellow Dog release and written in Python. It was also called Yup (Yellow Dog Updater ), this name is also available after being improved by the [email protected] development team of Duke University. Yum is designed to automatically upgrade, install/remove RPM packages, collect RPM package information, check dependencies, and automatically prompt users to solve the problem. The key to Yum is to have a reliable repository. As the name suggests, this is the software repository. It can be an HTTP or FTP site, or a local software pool, but it must contain the RPM header, the header contains various RPM package information, including descriptions, functions, provided files, dependencies, and so on. Only by collecting and analyzing these headers can we automate the remaining tasks.

Yum uses a repository to manage the relationship between some or even a distribution application, and upgrades, installs, deletes, and so on based on the calculated software dependency, this reduces the dependencies problem that Linux users have always suffered. At this point, yum and APT are the same. APT is originally used by Deb software management of Debian, but now it can also use RPM under RedHat.

Yum is mainly used to conveniently add, delete, and update RPM packages. It automatically solves the dependency problem of packages and facilitates management of a large number of system updates.

Yum can be used to configure multiple resource libraries (repository) and a simple configuration file (/etc/yum. conf) automatically solves the dependency problem when the RPM package is added or deleted, and maintains consistency with the RPM database.

Ii. Install yum

By default, centos has installed Yum without additional installation. For the purpose of this experiment, uninstall Yum and reinstall it.

1. view the yum installed by default.

# Rpm-Qa | grep yum

2. Uninstall yum

# Rpm-e yum-fastestmirror-1.1.16-14.el5.centos.1 yum-metadata-parser-1.1.2-3.el5.centos yum-3.2.22-33.el5.centos

3. reinstall yum

You can use wget to download and install related packages from the Internet, or mount the system installation disc. Here, you can choose to mount the system installation disc for installation.

# Mount/dev/CDROM/mnt/CDROM/

# Rpm-IVH yum-3.2.22-33.el5.centos.noarch.rpm yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm

# Yum-V

The basic installation package of Yum includes:

  • Yum/RPM installer/Updater
  • Yum-fastestmirror // Yum plugin which chooses fastest Repository from a previous list
  • Yum-metadata-parser // a fast metadata Parser for yum

Install other installation packages as needed.

Iii. Yum Configuration

The configuration file of yum is divided into two parts: Main and repository

  • The main section defines global configuration options. The entire Yum configuration file should have only one main. It is usually located in/etc/yum. conf.
  • The repository section defines the specific configurations of each source/server. There can be one or more configurations. It is usually located in the files in the/etc/yum. Repo. d directory.

The yum. conf file is generally located in the/etc directory, which generally only contains the configuration options of the main part.

# Cat/etc/yum. conf

[Main] cachedir =/var/Cache/yum
// Yum cache directory, where Yum stores the downloaded RPM package and database. The default value is/var/Cache/yumkeepcache = 0.
// Whether the software package is retained after the installation is complete. If the value 0 is not retained (the default value is 0), the value 1 is retained debuglevel = 2.
// Debug information output level, ranging from 0 to 10. The default value is 2 logfile =/var/log/yum. log.
// Yum log file location. You can query previous updates in the/var/log/yum. log file. Pkgpolicy = newest
// Package policy. There are two options: Newest and last. If you set multiple repository and the same software exists in different repository, which one should Yum install, if it is newest, yum will install the latest version. If it is last, yum will sort the server IDs in alphabetical order and select the software installation on the last server. Generally, select newest.
Distroverpkg = RedHat-release
// Specify a software package. Yum determines your release version based on this package. The default value is RedHat-release, or any installed RPM package for your own release. Tolerant = 1
// There are two options: 1 and 0, indicating whether Yum can tolerate errors related to software packages in command lines. For example, if you want to install packages 1, 2, and 3, 3 of them have been installed before. If you set it to 1, yum will not have an error message. The default value is 0. Exactarch = 1
// There are two options: 1 and 0. If this parameter is set to 1, yum only installs software packages that match the system architecture. For example, yum will not install the i686 software package in a system suitable for i386. The default value is 1. Retries = 6
// The number of retries after a network connection error occurs. If it is set to 0, the Retry is unlimited. The default value is 6.
Obsoletes = 1
// This is an update parameter. For details, refer to Yum (8). In short, it is equivalent to upgrade and allows updating of old RPM packages. Plugins = 1
// Whether to enable the plug-in. The default value is 1, and 0 indicates no. We usually use the Yum-fastestmirror plug-in. Bugtracker_url = Project_id = 16 & ref = Category = Yum # Note: Yum-RHN-plugin doesn't honor this. metadata_expire = 1hinstallonly_limit = 5 # Put your repos here or in separate files named file. repo # in/etc/yum. repos. d

In addition to the above, there are some options that can be added, such:

Exclude = SELinux * // exclude some software from the upgrade list. You can use wildcards to separate each item in the list with spaces. This installation includes beautification packages, chinese patching is particularly useful.
Gpgcheck = 1 // there are two options: 1 and 0, which respectively indicate whether or not GPG (GNU private guard) verification is performed to determine whether the RPM package source is valid and safe. This option is valid for each repository if it is set in [main. The default value is 0.

4. Configure the local Yum Source

1. Mount the system installation disc

# Mount/dev/CDROM/mnt/CDROM/

2. Configure the local Yum Source

# Cd/etc/yum. Repos. d/

# Ls

Four repo files are displayed.

The CentOS-Base.repo is the configuration file for the yum network source

The CentOS-Media.repo is the configuration file of the yum local source

Modify CentOS-Media.repo

# Cat CentOS-Media.repo

# CentOS-Media.repo## This repo is used to mount the default locations for a CDROM / DVD on#  CentOS-5.  You can use this repo and yum to install items directly off the#  DVD ISO that we release.## To use this repo, put in your DVD and use it with the other repos too:#  yum --enablerepo=c5-media [command]#  # or for ONLY the media repo, do this:##  yum --disablerepo=\* --enablerepo=c5-media [command] [c5-media]name=CentOS-$releasever - Mediabaseurl=file:///media/CentOS/        file:///mnt/cdrom/        file:///media/cdrecorder/gpgcheck=1enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

In baseurl, change the 2nd paths to/mnt/CDROM (that is, the disk mount point)

Change enabled = 0 to 1

3. Disable the default Yum network source.

Rename the yum network source configuration file to the CentOS-Base.repo.bak, otherwise it will first find the appropriate package in the network source, renamed and directly read from the local source.

4. Run the yum command

# Yum install PostgreSQL

Repo File Format

All repository server settings should follow the following format:

[serverid]name=Some name for this serverbaseurl=url://path/to/repository/
  • Serverid is used to distinguish different repository and must have a unique name;
  • Name is the description of repository and supports variables such as $ releasever $ basearch;
  • Baseurl is the most important part in server settings. You can obtain software from it only when the settings are correct. The format is:
baseurl=url://server1/path/to/repository/     url://server2/path/to/repository/     url://server3/path/to/repository/

The URL supports three protocols: http: // ftp: // file. After baseurl, it can be followed by multiple URLs. You can change it to an image site with a high speed, but there can only be one baseurl, that is, it cannot be in the following format:


The directory to which the URL points must be the upper level of the Repository header directory. It also supports variables such as $ releasever $ basearch.
You can add multiple options after the URL, such as gpgcheck, exclude, and failovermethod. For example:

[updates-released]name=Fedora Core $releasever - $basearch - Released Updatesbaseurl=$releasever/$basearch$releasever/$basearch$releasever/$basearchgpgcheck=1exclude=gaimfailovermethod=priority

The meaning of gpgcheck and exclude is the same as that of [main], but it only works for this server. failovermethode has two options: roundrobin and priority, meaning that multiple URLs are available, the order of Yum selection. roundrobin is a random selection. If the connection fails, use the next one, which loops in sequence. Priority starts from the first one according to the URL order. If not specified, the default value is roundrobin.

5. Configure domestic Yum sources

The system's default Yum source speed is often unsatisfactory. To achieve Fast Installation, modify the yum source here as the domestic source.

Shanghai Jiao Tong University Yum Source

A. Modify/etc/yum. Repos. d/CentOS-Base.repo:

# CentOS-Base.repo## The mirror system uses the connecting IP address of the client and the# update status of each mirror to pick mirrors that are updated to and# geographically close to the client.  You should use this for CentOS updates# unless you are manually picking other mirrors.## If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead.##[base]name=CentOS-$releasever - Base#mirrorlist=$releasever&arch=$basearch&repo=osbaseurl=$releasever/os/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5#released updates [updates]name=CentOS-$releasever - Updates#mirrorlist=$releasever&arch=$basearch&repo=updatesbaseurl=$releasever/updates/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5#additional packages that may be useful[extras]name=CentOS-$releasever - Extras#mirrorlist=$releasever&arch=$basearch&repo=extrasbaseurl=$releasever/extras/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5#additional packages that extend functionality of existing packages[centosplus]name=CentOS-$releasever - Plus#mirrorlist=$releasever&arch=$basearch&repo=centosplusbaseurl=$releasever/centosplus/$basearch/gpgcheck=1enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5#contrib - packages by Centos Users[contrib]name=CentOS-$releasever - Contrib#mirrorlist=$releasever&arch=$basearch&repo=contribbaseurl=$releasever/contrib/$basearch/gpgcheck=1enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

About Variables

  • $ Releasever: indicates the release version. It is obtained from distroverpkg in [main]. If not, it is determined based on the RedHat-release package.
  • $ Arch: CPU system, such as i686 and athlon
  • $ Basearch: Basic CPU system group. For example, i686 and athlon belong to the same i386, and Alpha and alphaev6 belong to the same Alpha.

B. Import the GPG key

Yum can use GPG to verify the package to ensure the integrity of the downloaded package. Therefore, we need to find the GPG key at each repository site, which is usually placed in a prominent position on the home page, some plain text files named like RPM-GPG-KEY-CentOS-5, download them, and use the RPM -- import RPM-GPG-KEY-CentOS-5 command to import the key.

C. Execute the yum command

Other domestic Yum sources are listed as follows:

1. Enterprise contribution:
Sohu open source mirror station:
Netease open source mirror station:

2. University Teaching:
Beijing University of Technology:
Http:// (IPv4 only)
Http:// (IPv6 only)
Beijing Jiao Tong University:
Http:// (IPv4 only)
Http:// (IPv6 only)
Http:// (IPv4 + IPv6)
Lanzhou University:
Xiamen University:
Tsinghua University:
Http:// + IPv6)
Http:// only)
Http:// only)
Tianjin University:
China University of Science and Technology:
Http:// + IPv6)
Northeastern University:
Http:// only)
Http:// only)
University of electronic science and technology:

6. Use third-party software libraries

The default Yum software repository for centos/RHEL is very limited. It is only limited to the regular packages and updates of some software packages in the released versions. Using rpmforge, many third-party RPM software packages can be added. The rpmforge library now has more than 10000 centos software packages, which is considered by the centos community as the safest and most stable third-party software library.

1. Install the Yum-priorities plug-in.

This plug-in is used to set the order in which Yum calls the software source. Because the official software sources are relatively stable and recommended. Therefore, the order of the official source is higher than that of the third source. To ensure this order, you need to install the Yum-priorities plug-in.

# Yum-y install Yum-Priorities

2. After installing the Yum-priorities plug-in, you need to set/etc/yum. repos. d/directory. repo-related files, such as CentOS-Base.repo, insert sequence instructions in these files: Priority = n (n is a positive integer from 1 to 99, the smaller the value, the higher priority)

Generally, set the priority of [base], [Addons], [updates], [extras] to 1, [centosplus], and [contrib] to 2. The third software source is: priority = N (recommended N> 10)

Take CentOS-Base.repo as an example:

[base]name=CentOS-$releasever - Base#mirrorlist=$releasever&arch=$basearch&repo=osbaseurl=$releasever/os/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5priority=1

3. download and install the rpmforge RPM package

# Wget

4. Install the PGP key of the Dag

# Rpm -- import

5. Verify rpmforge's RPM file package

# Rpm-K rpmforge-release-0.5.2-2.el5.rf. *. rpm

6. Install rpmforge's RPM package

# Rpm-I rpmforge-release-0.5.2-2.el5.rf.i386.rpm

7. Set the source level in the/etc/yum. Repos. d/rpmforge. Repo file.

[[Email protected] yum. Repos. d] # Cat rpmforge. Repo

### Name: RPMforge RPM Repository for RHEL 5 - dag### URL:[rpmforge]name = RHEL $releasever - - dagbaseurl =$basearch/rpmforgemirrorlist = = file:///etc/yum.repos.d/mirrors-rpmforgeenabled = 1protect = 0gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-daggpgcheck = 1priority=12

8. test and install

# Yum install htop


Install and use other third-party software libraries, such as epel (extra packages for Enterprise Linux) and rpmfusion, similar to rpmforge.

Configuration and use of centos Yum Source

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.