1. 程式人生 > >再談CENTOS下通過YUM和RPM快速獲取相關工具(命令)所在軟件包並安裝

再談CENTOS下通過YUM和RPM快速獲取相關工具(命令)所在軟件包並安裝

diag .com too util worker let computer tun 需要

有些時候,我們不得不處理別人用過的系統,或者是一臺新安裝的系統。因為安全和其它原因,系統處於最小化安裝狀態或者選擇性安裝軟件包。一些常用的工具命令並沒有安裝。很多人的方式(包括之前的我)通過搜索引擎進行搜索答案。這樣的方式效率其實並不高。我之前的博文LINUX下借助YUM和RPM教你正確尋找並安裝軟件的姿勢 其實並不完整。接下來,我重新談一下完整的方法。

以下方法基於CENTOS(RHEL)系統

假設我們知道rz這個命令的用法,但系統並沒有安裝。這臺服務器可以連接互聯網或擁有私有倉庫。我需要通過YUM進行查找(常用工具或軟件包基本都在官方或第三方鏡像源BASE,某些工具或軟件需要其他第三方源)

$ yum provides rz     
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * elrepo: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs
源    :base
匹配來源:
文件名    :/usr/bin/rz

lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs
源    :@base
匹配來源:
文件名    :/usr/bin/rz

該命令可以查找某工具或命令位於哪個包(當前為lrzsz) 並提供了包的倉庫的地址(BASE庫 -阿裏雲CENTOS鏡像)並提供命令位置(安裝位置和是否安裝沒有直接關聯)

有些時候,基於系統的基礎工具被打在一個包內,你可能並不知道這個包名,同樣的方法也可以查找,比如netstat

 yum provides netstat   
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * elrepo: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
net-tools-2.0-0.17.20131004git.el7.x86_64 : Basic networking tools
源    :installed
匹配來源:
文件名    :/usr/bin/netstat

可見,netstat命令是基礎網絡工具,並被封裝在net-tools包內

通過YUM INSTLL 安裝後,你就可以通過RPM描述查找包內其它工具

 rpm -qi net-tools
Name        : net-tools
Version     : 2.0
Release     : 0.17.20131004git.el7
Architecture: x86_64
Install Date: 2016年01月30日 星期六 18時18分27秒
Group       : System Environment/Base
Size        : 938653
License     : GPLv2+
Signature   : RSA/SHA256, 2014年07月04日 星期五 11時56分18秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : net-tools-2.0-0.17.20131004git.el7.src.rpm
Build Date  : 2014年06月10日 星期二 12時15分04秒
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://sourceforge.net/projects/net-tools/
Summary     : Basic networking tools
Description :
The net-tools package contains basic networking tools,
including ifconfig, netstat, route, and others.
Most of them are obsolete. For replacement check iproute package.

描述內說明這個包還包含了ifconfig和route等命令。描述就是一個概況,想要詳細看看包的具體內容,可以通過如下方法:

╰$ rpm -ql net-tools
/bin/netstat
/sbin/arp
/sbin/ether-wake
/sbin/ifconfig
/sbin/ipmaddr
/sbin/iptunnel
/sbin/mii-diag
/sbin/mii-tool
/sbin/nameif
/sbin/plipconfig
/sbin/route
/sbin/slattach
/usr/lib/systemd/system/arp-ethers.service
/usr/share/doc/net-tools-2.0
/usr/share/doc/net-tools-2.0/COPYING
/usr/share/locale/cs/LC_MESSAGES/net-tools.mo
...

我省略了部分輸出,即很多man文件

描述其實很有用,比如在RHEL(centos6)以上,ntp包已經不含ntptrace命令了。而是在ntp-perl包中

$ rpm -qi ntp
Name        : ntp
Version     : 4.2.6p5
Release     : 22.el7.centos.2
Architecture: x86_64
Install Date: 2019年04月01日 星期一 14時58分16秒
Group       : System Environment/Daemons
Size        : 1434261
License     : (MIT and BSD and BSD with advertising) and GPLv2
Signature   : RSA/SHA256, 2016年05月31日 星期二 19時37分00秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : ntp-4.2.6p5-22.el7.centos.2.src.rpm
Build Date  : 2016年05月31日 星期二 18時29分03秒
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.ntp.org
Summary     : The NTP daemon and utilities
Description :
The Network Time Protocol (NTP) is used to synchronize a computer‘s
time with another reference time source. This package includes ntpd
(a daemon which continuously adjusts system time) and utilities used
to query and configure the ntpd daemon.

Perl scripts ntp-wait and ntptrace are in the ntp-perl package,
ntpdate is in the ntpdate package and sntp is in the sntp package.
The documentation is in the ntp-doc package.

當然,RPM檢索包的前期是必須將軟件包安裝在本地,否則你會看到

╰$ rpm -ql ntp-perl
未安裝軟件包 ntp-perl

而YUM的前提是你的YUM源中擁有這個軟件包

$ yum provides ntptrace
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * elrepo: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
ntp-perl-4.2.6p5-28.el7.centos.noarch : NTP utilities written in Perl
源    :base
匹配來源:
文件名    :/usr/sbin/ntptrace

再談CENTOS下通過YUM和RPM快速獲取相關工具(命令)所在軟件包並安裝