嘘~ 正在从服务器偷取页面 . . .

玩转YUM–30个YUM常用命令(二)


11,获取关于YUM软件包的信息

要了解关于特定包的更多信息,请使用以下命令。
[root@localhost ~]# yum info tar
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* Webmin: download.webmin.com
* base: mirrors.huaweicloud.com
* epel: mirrors.yun-idc.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
Installed Packages
Name : tar
Arch : x86_64
Epoch : 2
Version : 1.26
Release : 34.el7
Size : 2.7 M
Repo : installed
From repo : anaconda
Summary : A GNU file archiving program
URL : http://www.gnu.org/software/tar/
License : GPLv3+
Description : The GNU tar program saves many files together in one archive and can
: restore individual files (or all of the files) from that archive. Tar
: can also be used to add supplemental files to an archive and to update
: or list files in the archive. Tar includes multivolume support,
: automatic archive compression/decompression, the ability to perform
: remote archives, and the ability to perform incremental and full
: backups.
:
: If you want to use tar for remote backups, you also need to install
: the rmt package on the remote box.

12,使用YUM下载包

在某些情况下,比如创建存储库,您需要下载rpm包,而无需使用YUM命令安装。下面的命令将下载FTP服务器包到/tmp目录。
[root@localhost ~]# yum install vsftpd –downloadonly –downloaddir=/tmp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
Resolving Dependencies
–> Running transaction check
—> Package vsftpd.x86_64 0:3.0.2-22.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

Package Arch Version Repository Size
Installing:
vsftpd x86_64 3.0.2-22.el7 base 169 k
Transaction Summary
Install 1 Package
Total download size: 169 k
Installed size: 348 k
Background downloading packages, then exiting:
vsftpd-3.0.2-22.el7.x86_64.rpm 169 kB 00:00:00
exiting because “Download Only” specified
验证包是否已正确下载
[root@localhost ~]# ls -al /tmp grep vsftpd
-rw-r–r–. 1 root root 173060 Aug 11 2017 vsftpd-3.0.2-22.el7.x86_64.rpm
[root@localhost ~]#

13,使用YUM检查更新

想知道哪些包需要更新以保证系统安全,请使用下面的命令。
[root@localhost ~]# yum check-update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.163.com
epel: mirrors.yun-idc.com
extras: mirrors.cn99.com
updates: mirrors.cn99.com

binutils.x86_64 2.27-28.base.el7_5.1 updates
ca-certificates.noarch 2018.2.22-70.0.el7_5 updates
centos-release.x86_64 7-5.1804.4.el7.centos updates
dhclient.x86_64 12:4.2.5-68.el7.centos.1 updates
……
……
sudo.x86_64 1.8.19p2-14.el7_5 updates
tuned.noarch 2.9.0-1.el7_5.2 updates
tzdata.noarch 2018e-3.el7 updates
util-linux.x86_64 2.23.2-52.el7_5.1 updates
yum-plugin-fastestmirror.noarch 1.1.31-46.el7_5 updates
[root@localhost ~]#

14,使用YUM更新系统

要在一次操作中更新所有已安装的包或将系统升级到新版本的操作系统,可以使用以下命令。
yum update

15,从YUM的更新中排除一个包

如果希望防止包被更新,可以使用下面的命令,可以用逗号分隔多个包。
yum update –exclude kernel

16,获取YUM的历史细节

在此步骤之前,您可能已经多次执行yum命令。下面的命令将允许您查看成功执行yum命令的历史数据,这些命令具有安装、删除和更新等操作。ID对于每个yum事务都是唯一的,在接下来的几个例子中会有用。
[root@localhost ~]# yum history
Loaded plugins: fastestmirror, langpacks
ID Login user Date and time Action(s) Altered
13 root <root> 2018-09-25 12:59 Update 58 12 root <root> 2018-09-25 12:41 Reinstall 1 11 root <root> 2018-09-25 12:40 Downgrade 1 10 root <root> 2018-09-25 12:39 Update 1 9 root <root> 2018-09-25 12:39 Erase 1 8 root <root> 2018-09-25 12:37 Install 1 7 root <root> 2018-09-20 10:22 I, U 2 6 root <root> 2018-09-17 15:26 Install 2 5 root <root> 2018-09-17 15:17 Install 3 EE 4 root <root> 2018-09-17 12:52 Install 3 3 root <root> 2018-09-17 19:51 I, U 1071 EE 2 root <root> 2018-09-17 19:33 Install 1 1 System <unset> 2018-09-17 11:23 Install 311
history list
[root@localhost ~]#

17,通过ID查看详细的YUM执行操作历史

要知道在特定的yum命令执行期间发生了什么,可以使用yum history info命令。
例如:让我们看看在yum执行期间发生的更改(ID 9)。
[root@localhost ~]# yum history info 9
Loaded plugins: fastestmirror, langpacks
Transaction ID : 9
Begin time : Tue Sep 25 12:39:06 2018
Begin rpmdb : 1373:2adf31f6f270d020d00132758343c2d274a2d320
End time : 12:39:07 2018 (1 seconds)
End rpmdb : 1372:3a19ef9b6ac66f55b77b44c68e7a7b6185a3cd28
User : root
Return-Code : Success
Command Line : remove vsftpd
Transaction performed with:
Installed rpm-4.11.3-32.el7.x86_64 @anaconda
Installed yum-3.4.3-158.el7.centos.noarch @anaconda
Updated yum-plugin-fastestmirror-1.1.31-45.el7.noarch @base
Packages Altered:
Erase vsftpd-3.0.2-22.el7.x86_64 @base
history info
[root@localhost ~]#

18,恢复带有yum历史记录的包

此命令能够恢复为特定yum命令执行所发生的更改。
例如:在前面的步骤中,您可以看到名为vsftpd的包是在ID 9期间被remove。让我们使用yum还原(安装包)整个安装。
[root@localhost ~]# yum history undo 9
Loaded plugins: fastestmirror, langpacks
Undoing transaction 9, from Tue Sep 25 12:39:06 2018
Erase vsftpd-3.0.2-22.el7.x86_64 @base
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.163.com
epel: mirrors.yun-idc.com
extras: mirrors.163.com
updates: mirrors.cn99.com
Resolving Dependencies
–> Running transaction check
—> Package vsftpd.x86_64 0:3.0.2-22.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

Package Arch Version Repository Size
Installing:
vsftpd x86_64 3.0.2-22.el7 base 169 k
Transaction Summary
Install 1 Package
Total download size: 169 k
Installed size: 348 k
Is this ok [y/d/N]: y
Downloading packages:
vsftpd-3.0.2-22.el7.x86_64.rpm 169 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : vsftpd-3.0.2-22.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-22.el7.x86_64 1/1
Installed:
vsftpd.x86_64 0:3.0.2-22.el7
Complete!
[root@localhost ~]#

19,使用yum历史记录撤消还原

此命令将撤消为特定yum命令执行而发生的恢复(安装已删除的包—步骤9)。
[root@localhost ~]# yum history redo 9
Loaded plugins: fastestmirror, langpacks
Repeating transaction 9, from Tue Sep 25 12:39:06 2018
Erase vsftpd-3.0.2-22.el7.x86_64 @base
Resolving Dependencies
–> Running transaction check
—> Package vsftpd.x86_64 0:3.0.2-22.el7 will be erased
–> Finished Dependency Resolution
Dependencies Resolved

Package Arch Version Repository Size
Removing:
vsftpd x86_64 3.0.2-22.el7 @base 348 k
Transaction Summary
Remove 1 Package
Installed size: 348 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : vsftpd-3.0.2-22.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-22.el7.x86_64 1/1
Removed:
vsftpd.x86_64 0:3.0.2-22.el7
Complete!
[root@localhost ~]#

20,列出YUM存储库

希望获得在计算机上配置的存储库列表。使用下面的命令。该命令将只列出启用的存储库。
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
repo id repo name status
Webmin Webmin Distribution Neutral 119
base/7/x86_64 CentOS-7 - Base 9,911
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12,687
extras/7/x86_64 CentOS-7 - Extras 403
updates/7/x86_64 CentOS-7 - Updates 1,348
repolist: 24,468


文章作者: kclouder
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 kclouder !
  目录