"Turn" CentOS yum source configuration and use

 

Configuration and use of CentOS yum source

1. Introduction to yum

  yum, short for Yellow dog Updater, Modified, is a package manager developed by Duke University to improve the installability of RPM packages. It was originally developed by Terra Soft, the developer of the yellow dog distribution. It was written in python. It was also called yup (yellow dog updater) at that time. It was later improved by the Linux@Duke development team of Duke University, so it has this name. The purpose of yum is to automate upgrades, install/remove rpm packages, collect information about rpm packages, check dependencies and automatically prompt users to resolve them. The key point of yum is to have a reliable repository. As the name suggests, this is a software repository. It can be an http or ftp site, or a local software pool, but it must contain the rpm header, which includes various rpm packages. Information, including descriptions, features, provided files, dependencies, etc. It is these headers that are collected and analyzed that automate the rest of the task.

  The idea of ​​yum is to use a central repository (repository) to manage the interrelationship of a part or even a distribution application, and perform related upgrades, installations, deletions, etc. according to the calculated software dependencies, reducing the headaches of dependencies for Linux users. question. In this regard, yum is the same as apt. apt was originally used for debian's deb-type software management, but now it can also be used for rpm under RedHat.

  The main function of yum is to add/delete/update RPM packages more conveniently, automatically solve the dependency problem of packages, and manage the update problems of a large number of systems.

  yum can simultaneously configure multiple repositories (Repository), concise configuration file (/etc/yum.conf), automatically solve the dependency problems encountered when adding or deleting rpm packages, and maintain consistency with the RPM database.

Second, yum installation

CentOS has already installed yum by default, and no additional installation is required. For experimental purposes, yum is first uninstalled and then reinstalled.

1. View the yum installed by default in the system

# 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

Here, you can download related packages from the Internet through wget for installation, or you can mount the system installation CD for installation. Here, choose to mount the system installation CD 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 mirrorlist
  • yum-metadata-parser  //A fast metadata parser for yum

Other installation packages are installed according to their own needs.

Three, yum configuration

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

  • The main section defines global configuration options, and the entire yum configuration file should have only one main. Usually located in /etc/yum.conf.
  • The repository section defines the specific configuration for each source/server, there can be one or more. Often located in various files in the /etc/yum.repo.d directory.

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

# cat /etc/yum.conf

copy code
[main]
cachedir=/var/cache/yum 
  //yum cache directory, where yum stores downloaded rpm packages and databases, the default setting is /var/cache/yum keepcache=0
  //Whether to keep the package after installation, 0 is not reserved (default is 0), 1 is reserved debuglevel=2
  //Debug information output level, the range is 0-10, the default is 2 logfile=/var/log/yum.log
  //yum log file location. Users can go to the /var/log/yum.log file to query past updates. pkgpolicy=newest
  //The policy of the package. There are two options, newest and last. This function is that if you set up multiple repositories, and the same software exists in different repositories at the same time, which one should yum install, if it is newest, yum will install the latest version . If it is last, yum will alphabetically sort the server id and select the last software installation on that server. Generally choose newest.
distroverpkg=redhat-release
  //Specify a package, yum will judge your release version based on this package, the default is redhat-release, or it can be any installed rpm package for your own release. Tolerant=1
  //There are two options of 1 and 0, indicating whether yum tolerates errors related to packages on the command line. For example, if you want to install three packages 1, 2, and 3, and 3 of them have been installed before, if you Set to 1, then yum will not display error messages. Default is 0. exactarch=1
  //There are two options, 1 and 0. If set to 1, yum will only install packages that match the system architecture. For example, yum will not install i686 packages on systems suitable for i386. Defaults to 1. retries=6
  //Number of retries after a network connection error occurs, if set to 0, it will retry infinitely. The default value is 6.
obsoletes=1
  //This is an update parameter. Please refer to yum(8) for details. In short, it is equivalent to upgrade, allowing to update outdated RPM packages. plugins=1
  //Whether to enable plugins, the default is 1 is allowed, 0 is not allowed. We generally use the yum-fastestmirror plugin. bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum # Note: yum-RHN-plugin doesn't honor this. metadata_expire=1h installonly_limit = 5 # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d
copy code

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

  exclude=selinux* // To exclude some software from the upgrade list, wildcards can be used, and each item in the list should be separated by spaces. This is especially useful for friends who have installed beautification packages and Chinese patches.
  gpgcheck=1 // There are two options, 1 and 0, which represent whether to perform gpg (GNU Private Guard) check to determine whether the source of the rpm package is valid and safe. This option, if set in the [main] section, is valid for each repository. The default value is 0.

Fourth, configure the local yum source

1. Mount the system installation CD

# mount /dev/cdrom /mnt/cdrom/

2. Configure the local yum source

# cd /etc/yum.repos.d/

# ls

You will see four repo files

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

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

Modify CentOS-Media.repo

# cat CentOS-Media.repo

copy code
# 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-middle]
name=CentOS-$releasever - Media
baseurl = file: /// media/CentOS/
        file:///mnt/cdrom/
        file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
copy code

Modify the second path in baseurl to /mnt/cdrom (that is, the CD mount point)

Change enabled=0 to 1

3. Disable the default yum network source

Rename the yum network source configuration file to CentOS-Base.repo.bak, otherwise it will first look for a suitable package in the network source, and read it directly from the local source after renaming.

4. Execute the yum command

# yum install postgresql

About the format of the repo file

All repository server settings should follow the format:

[servers]
name=Some name for this server
baseurl = url: // path/to/repository/
  • serverid is used to distinguish different repositories and must have a unique name;
  • name is a description of the repository, supports variables like $releasever $basearch;
  • The baseurl is the most important part of the server setup, only if it is set correctly, can you get software from it. Its format is:
baseurl = url: // server1/path/to/repository/
     url://server2/path/to/repository/
     url://server3/path/to/repository/

The protocols supported by url are http://ftp://file://. Baseurl can be followed by multiple urls. You can change to a faster mirror site by yourself, but there can only be one baseurl, which means it cannot be in the following format:

baseurl = url: // server1/path/to/repository/
baseurl=url://server2/path/to/repository/
baseurl=url://server3/path/to/repository/

其中url 指向的目录必须是这个repository header 目录的上一级,它也支持$releasever $basearch 这样的变量。
url 之后可以加上多个选项,如gpgcheck、exclude、failovermethod 等,比如:

copy code
[updates-released]
name=Fedora Core $releasever - $basearch - Released Updates
baseurl=http://download.atrpms.net/mirrors/fedoracore/updates/$releasever/$basearch
     http://redhat.linux.ee/pub/fedora/linux/core/updates/$releasever/$basearch
     http://fr2.rpmfind.net/linux/fedora/core/updates/$releasever/$basearch
gpgcheck=1
exclude=gaim
failovermethod=priority
copy code

其中gpgcheck,exclude 的含义和[main] 部分相同,但只对此服务器起作用,failovermethode 有两个选项roundrobin 和priority,意思分别是有多个url可供选择时,yum 选择的次序,roundrobin 是随机选择,如果连接失败则使用下一个,依次循环,priority 则根据url 的次序从第一个开始。如果不指明,默认是roundrobin。

五、配置国内yum源

系统默认的yum 源速度往往不尽人意,为了达到快速安装的目的,在这里修改yum源为国内源。

上海交通大学yum源

a. 修改/etc/yum.repos.d/CentOS-Base.repo为:

copy code
# 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=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
copy code

关于变量

  • $releasever:代表发行版的版本,从[main]部分的distroverpkg获取,如果没有,则根据redhat-release包进行判断。
  • $arch:cpu体系,如i686,athlon等
  • $basearch:cpu的基本体系组,如i686和athlon同属i386,alpha和alphaev6同属alpha。

b. 导入GPG KEY

yum 可以使用gpg 对包进行校验,确保下载包的完整性,所以我们先要到各个repository 站点找到gpg key,一般都会放在首页的醒目位置,一些名字诸如RPM-GPG-KEY-CentOS-5 之类的纯文本文件,把它们下载下来,然后用rpm --import RPM-GPG-KEY-CentOS-5 命令将key 导入。

c. 执行yum 命令

其他国内yum源列表如下:

1. 企业贡献:
搜狐开源镜像站:http://mirrors.sohu.com/
网易开源镜像站:http://mirrors.163.com/

2. 大学教学:
北京理工大学:
http://mirror.bit.edu.cn (IPv4 only)
http://mirror.bit6.edu.cn (IPv6 only)
北京交通大学:
http://mirror.bjtu.edu.cn (IPv4 only)
http://mirror6.bjtu.edu.cn (IPv6 only)
http://debian.bjtu.edu.cn (IPv4+IPv6)
兰州大学:http://mirror.lzu.edu.cn/
厦门大学:http://mirrors.xmu.edu.cn/
清华大学:
http://mirrors.tuna.tsinghua.edu.cn/ (IPv4+IPv6)
http://mirrors.6.tuna.tsinghua.edu.cn/ (IPv6 only)
http://mirrors.4.tuna.tsinghua.edu.cn/ (IPv4 only)
天津大学:http://mirror.tju.edu.cn/
中国科学技术大学:
http://mirrors.ustc.edu.cn/ (IPv4+IPv6)
http://mirrors4.ustc.edu.cn/
http://mirrors6.ustc.edu.cn/
东北大学:
http://mirror.neu.edu.cn/ (IPv4 only)
http://mirror.neu6.edu.cn/ (IPv6 only)
电子科技大学:http://ubuntu.uestc.edu.cn/

六、使用第三方软件库

Centos/RHEL默认的yum软件仓库非常有限,仅仅限于发行版本那几张盘里面的常规包和一些软件包的更新,利用RpmForge,可以增加非常多的第三方rpm软件包。RpmForge库现在已经拥有超过10000种的CentOS的软件包,被CentOS社区认为是最安全也是最稳定的一个第三方软件库。

1、安装yum-priorities插件

这个插件是用来设置yum在调用软件源时的顺序的。因为官方提供的软件源,都是比较稳定和被推荐使用的。因此,官方源的顺序要高于第三方源的顺序。如何保证这个顺序,就需要安装yum-priorities这插件了。

# yum -y install yum-priorities

2、安装完yum-priorities插件后需要设置/etc/yum.repos.d/ 目录下的.repo相关文件(如CentOS-Base.repo),在这些文件中插入顺序指令:priority=N (N为1到99的正整数,数值越小越优先)

一般配置[base], [addons], [updates], [extras] 的priority=1,[CentOSplus], [contrib] 的priority=2,其他第三的软件源为:priority=N (推荐N>10)

以CentOS-Base.repo 为例:

copy code
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
priority=1
copy code

3、下载与安装相应rpmforge的rpm文件包

# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm

4、安装DAG的PGP Key

# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

5、验证rpmforge的rpm文件包

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

6、安装rpmforge的rpm文件包

# rpm -i rpmforge-release-0.5.2-2.el5.rf.i386.rpm

7、设置/etc/yum.repos.d/rpmforge.repo文件中源的级别

[root@TS-DEV yum.repos.d]# cat rpmforge.repo 

copy code
### Name: RPMforge RPM Repository for RHEL 5 - dag
### URL: http://rpmforge.net/
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el5/en/$basearch/rpmforge
mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
priority=12
copy code

8. Test installation

# yum install htop

Reference  http://wiki.centos.org/AdditionalResources/Repositories/RPMForge#head-5aabf02717d5b6b12d47edbc5811404998926a1b

The installation and use of other third-party software libraries such as EPEL (Extra Packages for Enterprise Linux) and RPMFusion are similar to RPMForge, and you can find information and install them yourself.

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326441754&siteId=291194637