CentOS中yum install命令如何找到安装包的下载地址

Posted gsls200808

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS中yum install命令如何找到安装包的下载地址相关的知识,希望对你有一定的参考价值。

我们通常用的yum install命令是怎么找到我们想要的下载地址的,这里简单做一下分析

首先,搜索所有/etc/yum.repos.d下所有repo

 在每个repo中都有一个baseurl,这里以docker-ce.repo下载containerd.io 的rpm包为例

docker-ce的部分repo为

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

它的baseurl为

https://download.docker.com/linux/centos/$releasever/$basearch/stable

其中有两个变量$releasever和$basearch为yum里的变量

centos8获取

/usr/libexec/platform-python -c 'import dnf, json; db = dnf.dnf.Base(); print(json.dumps(db.conf.substitutions, indent=2))'

centos6/7获取

python -c 'import yum, json; yb = yum.YumBase(); print json.dumps(yb.conf.yumvar, indent=2)'

其他获取命令arch获取$basearch

我这里获取的结果


  "arch": "x86_64",
  "basearch": "x86_64",
  "releasever": "8"

所以实际的baseurl为

https://download.docker.com/linux/centos/8/x86_64/stable

首先他会去找baseurl + /repodata/repomd.xml,拼接后的路径为

https://download.docker.com/linux/centos/8/x86_64/stable/repodata/repomd.xml

文件内容如下

<?xml version="1.0" encoding="UTF-8"?>
<repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm">
  <revision>1668722787</revision>
  <data type="primary">
    <checksum type="sha256">be17658b784892066fdfbfe9ec068b16ee160f2a4c0d32f17cdb4571b6354755</checksum>
    <open-checksum type="sha256">a5c7c260751e6ca1ea7c77f6c991bb207d1e81055a6e0d7e5935084bc6981297</open-checksum>
    <location href="repodata/be17658b784892066fdfbfe9ec068b16ee160f2a4c0d32f17cdb4571b6354755-primary.xml.gz"/>
    <timestamp>1668722787</timestamp>
    <size>14654</size>
    <open-size>266294</open-size>
  </data>
  <data type="filelists">
    <checksum type="sha256">cf1a791d6c576477dda984611b48b44f1857a6914f291f1f66f2956a8c7f9ef3</checksum>
    <open-checksum type="sha256">c44aba02e3e5e6d1a2ee3ab957200908f04a18f52dc7a86b74a4fa9efa3ea4ac</open-checksum>
    <location href="repodata/cf1a791d6c576477dda984611b48b44f1857a6914f291f1f66f2956a8c7f9ef3-filelists.xml.gz"/>
    <timestamp>1668722787</timestamp>
    <size>16970</size>
    <open-size>370747</open-size>
  </data>
  <data type="other">
    <checksum type="sha256">abceebf147a05e99f2c07a0f31f61b5eaa15468c62bbe036c8627ed15db66885</checksum>
    <open-checksum type="sha256">12b2f5856fcee45052acfb910504a5da4d4c8dac588c069d2f990dda93a41382</open-checksum>
    <location href="repodata/abceebf147a05e99f2c07a0f31f61b5eaa15468c62bbe036c8627ed15db66885-other.xml.gz"/>
    <timestamp>1668722787</timestamp>
    <size>7245</size>
    <open-size>60645</open-size>
  </data>
  <data type="primary_db">
    <checksum type="sha256">fd30a988d4fac2906713cd09631c352fae8ba760649a3a23563afb20469c0f94</checksum>
    <open-checksum type="sha256">6c8f98ca6820379b70483f7bed54f9f47c32f8b420c88ea588e113746383afd0</open-checksum>
    <location href="repodata/fd30a988d4fac2906713cd09631c352fae8ba760649a3a23563afb20469c0f94-primary.sqlite.bz2"/>
    <timestamp>1668722787</timestamp>
    <size>49764</size>
    <open-size>360448</open-size>
    <database_version>10</database_version>
  </data>
  <data type="filelists_db">
    <checksum type="sha256">20e7bc1d075a56626855bf991b490ceede97aff17a4679a63f018e78905aa00a</checksum>
    <open-checksum type="sha256">91b51edaba3236b72a39b2d896b06aa54518fc1c9d1f1ee68712cca06c5aa286</open-checksum>
    <location href="repodata/20e7bc1d075a56626855bf991b490ceede97aff17a4679a63f018e78905aa00a-filelists.sqlite.bz2"/>
    <timestamp>1668722787</timestamp>
    <size>31574</size>
    <open-size>258048</open-size>
    <database_version>10</database_version>
  </data>
  <data type="other_db">
    <checksum type="sha256">073a126a1c676d7f28f6627b0ce62334599032e86819db0b1db5caa2c0200a29</checksum>
    <open-checksum type="sha256">ee2bd9ab4c2f461aa0ba80c5768f6691f519b35d0aebf72a12ccd593f064e7d7</open-checksum>
    <location href="repodata/073a126a1c676d7f28f6627b0ce62334599032e86819db0b1db5caa2c0200a29-other.sqlite.bz2"/>
    <timestamp>1668722787</timestamp>
    <size>12236</size>
    <open-size>77824</open-size>
    <database_version>10</database_version>
  </data>
  <data type="updateinfo">
    <checksum type="sha256">65c4f66e2808d328890505c3c2f13bb35a96f457d1c21a6346191c4dc07e6080</checksum>
    <open-checksum type="sha256">ded9c95e1b88197c906603b5d9693c579cb0afeade3bc7f8ec6cae06b962477d</open-checksum>
    <location href="repodata/65c4f66e2808d328890505c3c2f13bb35a96f457d1c21a6346191c4dc07e6080-updateinfo.xml.gz"/>
    <timestamp>1668722787</timestamp>
    <size>55</size>
    <open-size>42</open-size>
  </data>
</repomd>

 repomd.xml包含primary/filelist/other/group时间戳、检验等等之类。

primary.xml里包含所有rpm文件列表、依赖关系、软件包安装列表。最重要的是这个,我们拼接primary.xml.gz这个路径

路径为

https://download.docker.com/linux/centos/8/x86_64/stable/repodata/be17658b784892066fdfbfe9ec068b16ee160f2a4c0d32f17cdb4571b6354755-primary.xml.gz

下载后解压打开,可以看到第一个包是containerd.io-1.3.7-3.1.el8.x86_64.rpm

 location标签的内容为Packages/containerd.io-1.3.7-3.1.el8.x86_64.rpm

那么拼接上的下载地址为

https://download.docker.com/linux/centos/8/x86_64/stable/Packages/containerd.io-1.3.7-3.1.el8.x86_64.rpm

我们使用wget命令就可以下载下来

wget https://download.docker.com/linux/centos/8/x86_64/stable/Packages/containerd.io-1.3.7-3.1.el8.x86_64.rpm

下载结果如图

 实际上yum命令执行的过程中,会先在每个repo的primary列表文件先搜索有没有这个名称的包,匹配到再进行下载。primary文件中还定义了一些依赖关系,需要先安装完依赖才能安装完这个包。

以上是关于CentOS中yum install命令如何找到安装包的下载地址的主要内容,如果未能解决你的问题,请参考以下文章

CentOS中yum install命令加-y和不加有什么区别

如何在CentOS 7服务器上安装NodeJS

如何在 CentOS 7 上安装 Percona Server

Centos之压缩和解压缩命令

CentOS中防火墙相关的命令(CentOS7中演示)

yum install fuser提示没有可用软件包