RHEL / CentOS source and arranged YUM YUM Introduction

RHEL / CentOS source and arranged YUM YUM Introduction

1 Introduction


This article is too long. You can select a chapter by catalog top right corner of the page for quick jumps.


Because of redhat yum online update, it can not be used without registration. But fortunately there is this CentOS open source projects, so that we can open source easy to install and configure the update packages.

For Linux install RHEL version you want to use source yum, yum need to first uninstall the original, and then reinstall it.

CentOS Linux version of its open source project itself, in its own ISO yum is available, do not need to re-install.

This article including local sources and third-party sources. Third-party sources include: Ali, Netease, epel, repoforge, rpmfusion.

In fact, the entire configuration process, which is equivalent to source replacement RHEL CentOS as the source of the source as well as other open source projects.

The following is a detailed process.

2 About yum

 

2.1 What is YUM

YUM = Yellow dog Updater, Modified main function is more convenient to add / delete / update the RPM package. It can automatically resolve problems rely on the package. It easy to manage a large number of system update issues

2.2 YUM Features

  • You can configure multiple resource library (Repository)
  • Simple configuration files (files under /etc/YUM.conf,/etc/YUM.repos.d)
  • Automatic dependent solve problems encountered when to add or remove rpm package
  • Easy to use
  • To maintain consistency with the RPM database

2.3 install yum

2.4 YUM configuration

YUM all configuration information is stored in a configuration file called YUM.conf, usually located in the / etc directory, which is the top priority of the YUM system, it is necessary to detail. Here is a file YUM.con got from the Internet, let us as an example, is described.

[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
retries=1

[base]
name=Fedora Core $releasever - $basearch - Base
baseurl=http://download.atrpms.net/mirrors/fedoracore/$releasever/$basearch/os
http://rpmfind.net/linux/fedora/cor...er/$basearch/os
http://mirror.clarkson.edu/pub/dist...er/$basearch/os

[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/l...sever/$basearch
http://fr2.rpmfind.net/linux/fedora...sever/$basearch

[Fedora.us]
name=Fedora.us - $basearch - Extras
baseurl=http://fedora.linux.duke.edu/fedorax86_64/fedora.us/$releasever/$basearch/RPMS.stable

[Dag Wieers]
name=Dag RPM Repository for Fedora Core
baseurl=http://apt.sw.be/fedora/$releasever/en/$basearch/dag

[Livna]
Name=Livna RPM, Fedora Core $releasever - $basearch
baseurl=http://rpm.livna.org/fedora/$releasever/$basearch/RPMS.stable

[freshrpms]
name=FreshRPMs
baseurl=http://ayo.freshrpms.net/fedora/linux/$releasever/$basearch/freshrpms/
http://ftp.us2.freshrpms.net/linux/...arch/freshrpms/
  • MAIN part

    This is YUM global settings. Default generally do not change. According to the above examples and other content are summarized as follows

    . 1 the Table: yum configuration [main] Detailed options section
    parameter Explanation
    cachedir YUM cache directory, YUM RPM packages and databases in this storage download, typically / var / cache
    debuglevel Level debugging, 0-10, default is 2.
    logfile YUM log file, the default is /var/log/YUM.log.
    pkgpolicy Policy package. There are two options, newest and last, this role is if you set up multiple
    repository, while the same software at the same time there is a different repository in, YUM should be installed
    A, if it is newest, the YUM that will install the latest version. If last, the YU
    The server-id in alphabetical order, and select the software installed on the server last. One
    The election newest.
    distroverpkg Specify a package, YUM will judge you according to release this package, default
    redhat-release, it can be any rpm package installed for their own release.
    exactarch There are two options 1 and 0, does it mean you just upgrade and install the same package package cpu system, if
    1, then, as you are a rpm i386 is installed, it will not use the 1686 YUM package to upgrade.
    retries Fi retry after an error occurs, if set to 0, it will infinitely try again.
    tolerent There are two options 1 and 0, indicate whether YUM tolerate errors related to the occurrence of the command-line package,
    To install three packages 1, 2, and 3 of which had been installed, if you set to 1, YUM will not
    Error message. The default is 0.
    exclude= In addition to the exclusion of certain software upgrades list, you can use wildcards, list the items to be space separated
    Open, this is particularly useful for such as landscaping, Chinese friends to install the patch.
    gpgchkeck= There are two options 1 and 0, representing whether the gpg check whether, if not this one, the default
    It is checked. 0 means not checked, 1 for inspection.
  • server information

Configuration repository server, this is the most exciting, with a good repository, just as the door opened a hypermarket, a little something to that running leg trip, this was a free hypermarkets. All server settings should follow the following format:

  • [serverid]
    name=Some name for this server
    baseurl=url://path/to/repository/
    

    其中serverid是用于区别各个不同的repository,必须有一个独一无二的名称。 name,是对repository的描述,支持像$releasever $basearch这样的变量; baseurl是服务器设置中最重要的部分,只有设置正确,才能从上面获取软件。它的格式是:

    1. baseurl=url://server1/path/to/repository/
    2. url://server2/path/to/repository/
    3. url://server3/path/to/repository/

    其中url支持的协议有 http://ftp://file://三种。baseurl后可以跟多个url,你可以自己改为速度比较快的镜像站,但baseurl只能有一个,也就是说不能像如下格式:

    1. baseurl=url://server1/path/to/repository/
    2. baseurl=url://server2/path/to/repository/
    3. baseurl=url://server3/path/to/repository/

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

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

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

    几个变量

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

    对YUM.conf设定完成,我们就可以好好体验YUM带来的方便了。

2.5 软件源

yum可以在线安装软件,依赖的就是软件源。软件源可以为网络源也可以为本地源。

yum在操作之前会读取配置文件,查找源指向的信息,根据信息查找rpm包、解决包之间的依赖关系以及rpm包的版本兼容性问题。

软件源默认存储在/etc/yum.repos.d/路径中。这里对源配置的基本格式加以说明。以网易源为例:

[base]
name=CentOS-$releasever - Base - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
Table 2: 软件源repo文件配置格式说明
参数 说明
[base] 这个是软件源的名字,且 [ ] 里面不能为空。
name 这个只是软件源的一个描述,也可以随意些,但要有意义。
baseurl 指定路径,可以用 file,ftp,http 如果用后面的两个必须开启相应的服务,
  file 可以用来做本地软件源(如:将本地 DVD 设置为软件源),一定要保证路
enabled 有 1 和 0 两个选项,1 代表开启,0 代表关闭,开启是指激活这个软件源,
  关闭则不激活这个软件源。
gpgcheck 指下载软件包的时候是否检查数字签名,用来检查软件包的完整性。开启 gpgcheck
  后,通过 gpgkey 来指定,相应的 rpm-gpg 文件,如果不指定 gpgkey 文件,那么就必须
  手动的导入相应的 rpm-gpg 文件.

2.6 YUM使用

注:当第一次使用YUM或YUM资源库有更新时,YUM会自动下载所有所需的headers放置于/var/cache/YUM目录下,所需时间可能较长. 这里只列出常用的几个命令。几乎每个命令都有一堆的额外参数可以用。通过 "命令 –help" 可查看更多参数说明。

比如我在缓存源时,想指定缓存某个源,通过命令 yum makecache –help 可以查看缓存源的诸多参数。其中 –enablerepo 可以指定一个或者多个源.

更多用法 ,请各位客官自行摸索。

  • 安装

    命令 说明
    yum install 全部安装
    yum install package 安装指定的安装包 package。
    yum install package -y 直接安装不用询问是否安装。
    yum groupinsall group 安装程序组 group
  • 查找和显示

    命令 说明
    yum info package 显示安装包信息 package。
    yum info updates 列出更新信息。
    yum info installed 列出安装包信息。
    yum info extras 列出已安装,但不在 repo 中的包的信息。
    yum list 显示所有已经安装和可以安装的程序包。
    yum list updates 列出所有可更新的包。
    yum list installed 列出所有已经安装的包。
    yum list extras 列出所有已安装,但是没有在 repo 里的包。
    yum list package 显示指定程序包安装情况 package。
    yum groupinfo group 显示程序组 group 信息。
    yum search string 根据关键字 string 查找安装包。
    yum repolist 查看(开启的)资源库。
    yum repolist all 查看所有资源库。
    yum search 使用 YUM 查找软件包。
    yum provides 列出包中文件。
  • 删除

    命令 说明
    yum remove package 删除程序包 package
    yum groupremove group 删除程序组 group
    yum deplist package 查看程序 package 依赖情况
  • 缓存

    命令 说明
    yum makecache 将源信息缓存
    yum clean packages 清除缓存目录下的软件包
    yum clean headers 清除缓存目录下的 headers
    yum clean oldheaders 清除缓存目录下旧的 headers
    yum clean [all] 清除缓存目录下的软件包及旧的 headers

2.7 YUM常用问题解决

 

2.7.1 超时退出

如果网速慢的话可以通过增加YUM的超时时间,这样就不会总是因为超时而退出。

在 /etc/yum.conf中 #加上这么一句

timeout=120

2.7.2 YUM Existing lock

如果系统启动的时候, YUM出现Existing lock /var/run/YUM.pid: another copy is running as pid 6908. Aborting.可以用下面的办法解决:

  • 方法一

    /etc/init.d/YUM-updatesd stop
    
  • 方法二

    rm -f /var/run/YUM.pid
    

主要原因就是YUM在自动更新,只要关掉它就可以了。

3 重新安装yum

这一部分适用于RHEL版本的Linux,CentOS的Linux可忽略。

3.1 卸载yum

rpm -aq|grep yum|xargs rpm -e --nodeps

3.2 确定下载文件

在下载之前,首先我们要知道,我们在哪里下载,需要下载什么。

  • 确定下载地址

    首先要确定下载地址。我一般使用阿里源,因为速度比较快。阿里的下载地址格式是这样的:

    https://mirrors.aliyun.com/centos/$release/os/$basearch/Packages/
    

    其中$release,是操作系统版本。 $basearch 是操作系统位数(32或者64位对应的 i386 和 x86_64).

    • 查看操作系统的版本

      cat /etc/redhat-release
      

      示例:

      Red Hat Enterprise Linux Server release 7.6 (Maipo)
      

      从示例中,可以看出版本号是7.6。 在yum 源中一般不配置小版本号,只配置大版本号,也就是7.

    • 查看操作系统位数

      getconf LONG_BIT
      

      示例:

      [root@test1 data]# getconf LONG_BIT
      64
      [root@test1 data]#
      

      结果为64,表明是64位操作系统,对应的$basearch 为 x86_64,如果是32位操作系统则结果为32,对应$basearch为i386. 一般来说,服务器现在没有人再安装32位操作系统了。阿里也不再提供i386的yum源。

    经过以上的查看,我们yum相关安装包的下载页面就是: https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/

    通过这一步,基本了解了下载地址的规律。针对不同的版本可以自行调整.

  • 确定下载文件

    需要安装4个rpm包。在上一步中的页面查找以下文件

    • yum-<version>-<fixed-version>.el7.centos.noarch.rpm
    • yum-metadata-parser.<version>-<fixed-version>.el7.x86_64.rpm
    • yum-plugin-fastestmirror-<version>-<fixed-version>.el7.noarch.rpm
    • python-iniparse-<version>-<fixed-version>.el7.noarch.prm

    可以直接通过关键词 yum yum-metadata-parser yum-plugin-fastestmirro python-iniparse 直接在页面进行搜索,然后点击下载,也可以使用下面命令直接在Linux操作系统中进行下载。

    wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
    wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
    wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
    wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
    

3.3 安装

note
基本上操作都需要root用户权限,如果不能直接以root用户登录,可以su 进行切换。
rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh yum-3.4.3-161.el7.centos.noarch.rpm  yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
NOTE
最后一条命令中的两个安装包一定要一起安装,否则会出现依赖问题。

4 配置网络YUM源

一般来讲, base 源就已经足够用,有找不到的包,可以考虑配置epel源,再找不到的话,再配置rpmfusion源。

4.1 配置阿里云源

  • 备份原repo文件 备份文件,是为了防止修改repo文件时出现问题时,我们还有备份文件可以还原。

    cd /etc/yum.repos.d
    mkdir backup
    mv *.repo backup/
    
  • 配置阿里云源 CentOS yum源的配置文件,包含几个部分: base updates extras centosplus 四个部分。 我们分别需要对其进行配置,当然只配置一个base也没有问题。

    配置过程的最关键的就是确认mirrorlist的地址。先下载阿里云的repo文件:

    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    

    可以直接打开 http://mirrors.aliyun.com/repo 查找自己需要的版本的repo文件。

    下载完成后,打开文件CentOS-Base.repo,将"$release"和"$basearch"替换成实际值。 对于使用RHEL安装包安装的操作系统,release 保留大版本号,本文章示例为 7, 而对于CentOS版的操作系统,可以直接替换成全版本号比如: 7.6.1810; 将$basearch 为 x86_64, 再将enabled=0 改为 enabled=1. 至于用什么方法替换,你开心就好。

    为了方便朋友,现在将我已经将针对CentOS 7.6.1810版操作系统的repo内容整理成脚本,可以直接复制粘贴执行, 不用先下载文件再修改了。

      cat >> /etc/yum.repos.d/CentOS-Base.repo <<EOF
    [base]
    name=CentOS-7.6.1810 - Base - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/7.6.1810/os/x86_64/
            http://mirrors.aliyuncs.com/centos/7.6.1810/os/x86_64/
            http://mirrors.cloud.aliyuncs.com/centos/7.6.1810/os/x86_64/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
    
    #released updates
    [updates]
    name=CentOS-7.6.1810 - Updates - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/7.6.1810/updates/x86_64/
            http://mirrors.aliyuncs.com/centos/7.6.1810/updates/x86_64/
            http://mirrors.cloud.aliyuncs.com/centos/7.6.1810/updates/x86_64/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
    
    #additional packages that may be useful
    [extras]
    name=CentOS-7.6.1810 - Extras - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/7.6.1810/extras/x86_64/
            http://mirrors.aliyuncs.com/centos/7.6.1810/extras/x86_64/
            http://mirrors.cloud.aliyuncs.com/centos/7.6.1810/extras/x86_64/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
    
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-7.6.1810 - Plus - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/7.6.1810/centosplus/x86_64/
            http://mirrors.aliyuncs.com/centos/7.6.1810/centosplus/x86_64/
            http://mirrors.cloud.aliyuncs.com/centos/7.6.1810/centosplus/x86_64/
    gpgcheck=1
    enabled=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
    
    #contrib - packages by Centos Users
    [contrib]
    name=CentOS-7.6.1810 - Contrib - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/7.6.1810/contrib/x86_64/
            http://mirrors.aliyuncs.com/centos/7.6.1810/contrib/x86_64/
            http://mirrors.cloud.aliyuncs.com/centos/7.6.1810/contrib/x86_64/
    gpgcheck=1
    enabled=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
    
      EOF
    

4.2 配置epel源

  • 阿里云epel

    阿里云同时提供了epel源。与上一步中的操作过程完全一样。如下:

    #下载repo文件
    wget -O /etc/yum.repos.d/CentOS-epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    # 修改文件CentOS-epel.repo , 将$basearch替换成x86_64 ; enabled=0 改为enabled=1
    

    脚本也准备好,朋友们可以直接复制粘贴,不用再从网上下载文件:

      cat >> /etc/yum.repos.d/CentOS-epel.repo <<EOF
    [epel]
    name=Extra Packages for Enterprise Linux 7 - x86_64
    baseurl=http://mirrors.aliyun.com/epel/7/x86_64
    failovermethod=priority
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    
    [epel-debuginfo]
    name=Extra Packages for Enterprise Linux 7 - x86_64 - Debug
    baseurl=http://mirrors.aliyun.com/epel/7/x86_64/debug
    failovermethod=priority
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=0
    
    [epel-source]
    name=Extra Packages for Enterprise Linux 7 - x86_64 - Source
    baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
    failovermethod=priority
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=0
    EOF
    
  • fedora epel

    Fedora EPEL 下载:http://mirrors.fedoraproject.org/publiclist/EPEL/

    EPEL 下载地址:http://download.fedora.redhat.com/pub/epel/

    以上网直可能不 可用,此时,登录到下面的地址:

    https://fedoraproject.org/wiki/EPEL

    查找:“How can I use these extra packages?”

    在该条目内可以找到: The newest version of 'epel-release' for (版本)

    下载epel包。再执行安装。

    请针对不同的版本下载相应的包。

4.3 配置repoforge源

rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
yum makecache

4.4 配置rpmfusion源

RPMFusion官网:http://rpmfusion.org/

  • RHEL 6/CentOS 6

    yum -Uvh http://download1.rpmfusion.org/free/el/rpmfusion-free-release-6.noarch.rpm
    
  • RHEL 7/CentOS 7

    yum -Uvh http://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
    
  • RHEL 8 / CentOS8

    yum -Uvh http://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
    

5 配置本地yum源

对于一些环境,我们并不能联网。因此需要配置一个本地源。

配置本地源的前提是下载一个完整的ISO镜像文件,推荐下载everything版本的ISO。比如:

http://mirrors.aliyun.com/centos/7/isos/x86_64/CentOS-7-x86_64-Everything-1810.iso

这个版本比基础安装版多了一个GB 的rpm包,常用的包在这里面都能找到。

关于iso文件的挂载,参考: 开机自动挂载ISO文件.

对于虚拟机来讲, ISO文件可以配置成开机自动连接,此时 /dev/cdrom 代表了ISO文件。 挂载本地源的过程如下:

1) 创建挂载路径
mkdir /mnt/iso
2) 挂载ISO镜像
  • 虚拟机 : mount /dev/cdrom /mnt/iso
  • ISO镜像 : mount /CentOS-7-x86_64-Everything-1810.iso /mnt/iso
3) 编辑repo文件

vi /etc/yum.repos.d/CentOS-Media.repo 内容如下:

[local_iso]
name=local iso
baseurl=file:///mnt/iso
gpgcheck=1
enabled=1
gpgkey=file:///mnt/iso/RPM-GPG-KEY-CentOS-7

Author: halberd.lee

Created: 2019-08-10 Sat 02:09

Validate

Guess you like

Origin www.cnblogs.com/halberd-lee/p/11330318.html