Use and configuration of yum in CentOS

Source: Internet
Author: User
Tags ftp protocol

Use and configuration of yum in CentOS

Recently, due to server requirements, you need to build an intranet yum source in the company's intranet.

To build an intranet yum source, perform the following steps:

1. What is yum?

2. What is a repo file?

3. Detailed repo File Content

4. yum Server Configuration

5. yum client Configuration

6. Save the software package installed by yum

7. Update the rpm package

I. What is yum?

Yum (all called Yellowdog Updater Modified) is a Shell front-end package manager used in CentOS, RedHat, and Fedora operating systems.

Yum manages rpm-based software packages. It can automatically upgrade, install, and delete rpm software packages. It can also automatically find and resolve the dependencies between rpm packages, in addition, the Administrator does not need to install each rpm package one by one or manually, making it easier for the administrator to maintain the Linux host.

Yum can obtain necessary information from the repo repository configured in one or more repo files through http or ftp, and then download the related software packages. In this way, local users can easily upgrade and maintain the system when there is an Internet connection by establishing different repo warehouses.

You can use the createrepo or yum-arch command to create a repo repository. You can also use the repo repository created by others as the yum source. Here we will mainly discuss the repo repository created by using the createrepo command.

For help information on yum commands, run the man yum command as follows:

Man yum

Ii. What is a repo file?

In chapter 1, we know that the repo file is the configuration file of the yum source (software warehouse) in CentOS, RedHat, and Fedora operating systems. Generally, one repo file defines one or more software sources.

For example, we will download the software package to be installed or upgraded from the repo file, and the related configurations will be read and applied by yum.

Iii. Detailed repo File Content

The content of a standard centos repo file is as follows:

[Base]

Name = CentOS-$ releasever-Base

Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = OS

# Baseurl = http://developer.centos.org/centos/?releasever/ OS /?basearch/

Enabled = 1

Gpgcheck = 1

Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

The options are described as follows:

[Base]

This option is the name of the defined software source, which can be customized and is unique among all repo files on the server.Note: square brackets cannot contain spaces.

Name = CentOS-$ releasever-Base

This option is the name of the software repository. The $ releasever variable defines the release version, which is usually 5, 6, 7, and other numbers.

Using list = http://mirrorlist.centos.org /? Release = $ releasever & arch = $ basearch & repo = OS

This is the address list of the specified backup storage, which is usually enabled. We can try to replace $ releasever and $ basearch with their own version and architecture, such as 6.6 and x86_64. Open it in the browser, we can see a long list of available mirror server addresses. As follows:

Select the image server address with faster access and copy it to the baseurl option in the repo file. Then we can get a faster update speed.

# Baseurl = http://developer.centos.org/centos/?releasever/ OS /?basearch/

The first character of this line is #, which indicates that the line has been commented and will not be read. This line means to specify a baseurl (the source image server address ).

Baseurl is usually in the following four formats:

Base url = http://mirrors.aliyun.com/centos/6.6/ OS /x86_64/

Image server address using http protocol

Base url = ftp://ftp.sjtu.edu.cn/centos/6.6/ OS /x86_64/

Image server address using ftp protocol

Baseurl = rsync: // mirror. zol. co. zw/centos/

Use rsync image server address

Baseurl = file: // ilanni/yum/

Use the local image server address

The first two of them are the most used. For more information, see the reference provided on the centos official website:

Enabled = 1

This option indicates that the software source is enabled in this repo file. By default, this option can be left empty. However, if the value of enabled is 0, the software source is disabled.

Note: Multiple Software sources can be defined in a repo file.

Gpgcheck = 1

This option indicates that gpg verification is performed on the rpm package downloaded from the software source. If the value of gpgcheck is 0, gpg verification is not performed.

Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

This option defines the gpg key file used for verification.

Based on the above repo file description, I believe you will think that the centos repo file is actually very simple. With a preliminary understanding, we can start the following experiment.

We need to build a yum source on the company's intranet. The yum source must be configured with two sources: one is the centos CD image source and the other is the image source of the special rpm software, and the yum source is accessed through http.

This experiment: yum server 192.168.1.247 centos, client 192.168.1.248 centos.

Iv. yum Server Configuration

To meet the preceding requirements, we must first set up a yum server and configure a web server on the server.

On this web server, we use apache, and nginx is also supported.

4.1Configure web Servers

On the yum server, we now use yum to install apache directly. As follows:

Yum-y install httpd

Of course, you can also use the source code to install apache. For the source code installation of apache, refer to "mud: install apache by source code".

After apache is installed, start apache. As follows:

/Etc/init. d/httpd start

Wget http: // 192.168.1.247

We can see that the apache server has started properly.

4.2Install createrepo

What is createrepo? Createrepo is a software package for creating a repository in linux. Create is the meaning of creation, and repo is the abbreviation of repository, which is the meaning of repository.

Only createrepo software can be installed to create a software repository on the yum server.

Createrepo is easy to install. Now we use yum to install it as follows:

Yum-y install createrepo

After createrepo is installed, we can create a repo repository.

4.3CD image

Copy the locally downloaded CD image to the yum server. We copied it through xftp, as shown below:

The location where the software source is created is as follows:

Mkdir-p/var/www/html/yum

Ll/var/www/html/yum/

Create a directory for attaching a CD as follows:

Mkdir/iso

CentOS-6.6-x86_64-minimal.iso/iso/mount-o loop/

Ll/iso/

Copy all the files copied to the CD to the/var/www/html/yum/directory, as shown below:

Cp-rv/iso/*/var/www/html/yum/

Now we can access this directory to see if it can be properly displayed, as shown below:

Wget http: // 192.168.1.247/yum

We can clearly see that this directory is currently accessible.

Note: here we have not created the yum database and information index file because the CD already has the yum database and information index file. We do not need to run the createrepo command again. In fact, yum databases and information index files are all in the repodata folder. As follows:

For the effect of the CD image experiment, we use the curl software in the CD image package as an example. As follows:

Ll | grep curl

4.4Special software image

We also require a special yum source to store special software. Here we use lrzsz as an example.

The location where the yum source is stored is/var/www/html/ilanni/, and the rpm package of the lrzsz software is placed under the/var/www/html/ilanni/directory, as follows:

Mkdir-p/var/www/html/ilanni

Cp/var/cache/yum/x86_64/6/base/packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm/var/www/html/ilanni/

Ll/var/www/html/ilanni/

Now we will create the yum database and information index file for this special yum source, switch to the/var/www/html/ilanni/directory, and execute the createrepo Command, as shown below:

Createrepo ./

Tree repodata/

Now we can access this directory to see if it can be properly displayed, as shown below:

Wget http: // 192.168.1.247/ilanni

We can clearly see that this directory is currently accessible.

All the above configurations are performed on the yum server. Now we can switch to the yum client for operations.

V. yum client Configuration

Yum client operations are much simpler. We only need to modify the client's repo file.

Go to the/etc/yum. repos. d/directory and back up the original repo file as follows:

Rename. repo. repo. bak *. repo

Then, create a new repo file ilanni. repo in this directory. The content is as follows:

[Centos6]

Name = centos6

Baseurl = http: // 192.168.1.247/yum/

Enabled = 1

Gpgcheck = 0

[Ilanni]

Name = ilanni

Baseurl = http: // 192.168.1.247/ilanni/

Enabled = 1

Gpgcheck = 0

Note: The file name can be changed, but the suffix must be. repo.

After the repo file is modified, We will test the file.

Install the curl software as follows:

Yum-y install curl

Install the lrzsz software as follows:

Yum-y install lrzsz

Through the above tests, we can see that the client has downloaded the required software package from the yum server.

Note: If the client yum prompts that the software cannot be found when installing the software package. We strongly recommend that you run the yum clean all and yum list commands on the client.

Yum clean all indicates that the yum source cache is cleared, and yum list indicates that all software packages are listed.

The preceding steps are used to set up the yum source on the Intranet.

6. Save the software package installed by yum

When we use yum for software installation, the software package will be automatically deleted after installation.

To save the software package installed by yum, modify the yum configuration file yum. conf and change keepcache to 1. As follows:

Vi/etc/yum. conf

Cachedir indicates the cache location of the rpm package.

VII. Update the rpm package

We often encounter these two situations after building an intranet yum source. First, update the software version, and then add new software.

In any of the above cases, we need to first Delete the yum database and information index file of the original yum server, and then re-create the yum database and information index file through the createrepo command.

Here we take the new software as an example. The software is lftp.

As follows:

Cp/var/cache/yum/x86_64/6/base/packages/lftp-4.0.9-1.el6_5.1.x86_64.rpm/var/www/html/ilanni/

Ll/var/www/html/ilanni/

Rm-fr/var/www/html/ilanni/repodata/

Createrepo/var/www/html/ilanni/

Now we can switch to the client to perform the following operations:

Yum clean all

Yum list | grep lftp

Yum-y install lftp

It is obvious that the lftp software has been installed on the client.

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: info-contact@alibabacloud.com 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.