Yum包管理
YumYum是Red Hat软件包管理器,它能够查询有关可用软件包的信息,从存储库获取软件包,安装和卸载软件包,以及将整个系统更新到最新的可用版本。Yum在更新,安装或删除软件包时执行自动依赖性解析,因此能够自动确定,获取和安装所有可用的依赖软件包。 Yum可以配置新的,额外的存储库或包源,还提供许多增强和扩展其功能的插件。百胜可以执行许多与RPM相同的任务; 此外,许多命令行选项都是类似的。Yum可以在一台计算机或一组计算机上轻松简单地进行包管理。 检查和更新包通过Yum,可以检查系统是否有等待应用的更新。可以列出需要更新的软件包并将其作为整体进行更新,也可以更新选定的单个软件包。 查询更新要查看系统上哪些已安装的软件包具有可用更新,请使用以下命令: yum check-update yum check-update 的输出类似这样: 更新包您可以选择一次更新单个包,多个包或所有包。如果您更新的软件包或软件包的任何依赖项本身都有可用的更新,那么它们也会更新。 更新单个包要更新单个程序包,请运行以下命令 yum update 包名 yum 提供更新信息,然后提示您确认更新; yum默认以交互方式运行。如果您已经知道 如果事务失败,您可以使用 无论您是否使用 当使用RPM,而另一方面,它使用是很重要的 同样,可以更新包组。 yum group update 组名 更新所有包及其依赖项要更新所有包及其依赖项,请使用 yum update 更新与安全相关的包如果程序包具有可用的安全更新,则只能将这些程序包更新为其最新版本。 yum update --security 您还可以仅将包更新到包含最新安全更新的版本。 yum update-minimal --security 例如,假设:
然后 自动化包更新要刷新包数据库并自动下载更新,您可以使用该 使用ISO和Yum离线升级系统对于与Internet或Red Hat Network断开连接的系统,使用
例:从CentOS7.0升级到7.5 如果需要使用具有较新版本系统的ISO映像升级系统而无法访问Internet,例如 ?]# mount -o loop CentOS-7-x86_64-Everything-1804.iso /media/centos7/ 要使yum将挂载点识别为存储库,请将以下行添加到 baseurl=file:///media/centos7/ 现在,更新yum存储库会将您的系统升级到由 ?]# yum update 系统升级成功后,可以卸载映像,删除目标目录和配置文件: ?]# umount /media/centos7/ ?]# rmdir /media/centos7/ ?]# rm /etc/yum.repos.d/centos.repo 使用包Yum使您能够使用软件包执行一整套操作,包括搜索包,查看有关包,安装和删除的信息。 搜索包您可以使用以下命令搜索所有RPM包名称,描述和摘要: yum search xxx 获得更全更详尽的慢搜索: yum search all xxx 清单包要列出有关所有已安装和可用软件包的信息,请在shell提示符下键入以下内容: yum list all 要列出与插入的glob表达式匹配的已安装和可用的包,请使用以下命令: yum list glob_expression… 要列出系统上安装的所有软件包,请使用 yum list installed glob_expression ... 例如 yum list available gstreamer*plugin* 列出存储库要列出系统上每个已启用存储库的存储库ID,名称和程序包数,请使用以下命令: yum repolist 要列出有关这些存储库的更多信息,请添加该 yum repoinfo yum repolist -v 要列出启用和禁用的存储库,请使用以下命令。状态列将添加到输出列表中,以显示启用了哪些存储库。 yum repolist all 通过 显示包信息要显示有关一个或多个包的信息,请使用以下命令(glob表达式在此处也有效): yum info package_name ... 例如显示nginx的包信息 [[email?protected] ~]# yum info nginx Loaded plugins: fastestmirror,langpacks,product-id,search-disabled-repos,subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Loading mirror speeds from cached hostfile * base: mirrors.tuna.tsinghua.edu.cn * epel: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.tuna.tsinghua.edu.cn Installed Packages Name : nginx Arch : x86_64 Epoch : 1 Version : 1.12.2 Release : 2.el7 Size : 1.5 M Repo : installed From repo : epel Summary : A high performance web server and reverse proxy server URL : http://nginx.org/ License : BSD Description : Nginx is a web server and a reverse proxy server for HTTP,SMTP,POP3 and : IMAP protocols,with a strong focus on high concurrency,performance and low : memory usage.
使用yumdb还可以使用以下命令在yum数据库中查询有关包的替代和有用信息: 此命令提供有关包的其他信息,包括包的校验和(以及用于生成它的算法,如SHA-256),在命令行上给出的用于安装包的命令(如果有)以及在系统上安装软件包的原因( 安装包要安装单个程序包及其所有未安装的依赖项 yum install package_name 还可以通过将其名称作为参数附加来同时安装多个软件包。 yum install package_name package_name ... 模糊匹配 yum install audacious-plugins-*
yum install /usr/sbin/named 正如您在上面的示例中所看到的, 使用 yum install-n package_name yum install-na name.architecture yum install-nevra name-epoch:version-release.architecture 如果您知道要安装包含 [[email?protected] ~]# yum provides "*bin/mysql" Loaded plugins: fastestmirror,subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Loading mirror speeds from cached hostfile * base: mirrors.nwsuaf.edu.cn * epel: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.163.com 1:mariadb-5.5.56-2.el7.x86_64 : A community developed branch of MySQL Repo : base Matched from: Filename : /usr/bin/mysql 1:mariadb-5.5.60-1.el7_5.x86_64 : A community developed branch of MySQL Repo : updates Matched from: Filename : /usr/bin/mysql 1:mariadb-5.5.56-2.el7.x86_64 : A community developed branch of MySQL Repo : @base Matched from: Filename : /usr/bin/mysql 安装过程 以下示例提供了使用yum进行安装的概述。要下载并安装最新版本的httpd软件包, ~]# yum install httpd Loaded plugins: langpacks,subscription-manager Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.6-12.el7 will be updated ---> Package httpd.x86_64 0:2.4.6-13.el7 will be an update --> Processing Dependency: 2.4.6-13.el7 for package: httpd-2.4.6-13.el7.x86_64 --> Running transaction check ---> Package httpd-tools.x86_64 0:2.4.6-12.el7 will be updated ---> Package httpd-tools.x86_64 0:2.4.6-13.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved 执行上述命令后,yum加载必要的插件并运行事务检查。在这种情况下,httpd已经安装。由于安装的软件包比最新的当前可用版本旧,因此将进行更新。这同样适用于httpd所依赖的httpd-tools包。然后,显示事务摘要: ================================================================================ Package Arch Version Repository Size ================================================================================ Updating: httpd x86_64 2.4.6-13.el7 rhel-x86_64-server-7 1.2 M Updating for dependencies: httpd-tools x86_64 2.4.6-13.el7 rhel-x86_64-server-7 77 k Transaction Summary ================================================================================ Upgrade 1 Package (+1 Dependent package) Total size: 1.2 M Is this ok [y/d/N]: 在此步骤中,yum会提示您确认安装。除 要从系统上的本地目录安装以前下载的软件包,请使用以下命令: yum localinstall path 将path替换为要安装的程序包的路径。 下载包在某个安装过程中,系统会提示您使用以下消息确认安装: 使用 删除包与软件包安装类似,yum允许您卸载它们。要卸载特定软件包以及依赖于它的任何软件包: yum remove package_name… 使用包组包组是一组用于通用目的的包,例如System Tools或Sound and Video。安装软件包组会提取一组依赖软件包,从而大大节省了时间。 列出包组
yum groups summary 要列出yum存储库中的所有软件包组,请添加该 yum group list glob_expression ... 安装包组每个包组都有一个名称和一个组ID(groupid)。要列出括号中显示的所有包组的名称及其组ID,请键入: yum group list ids 查找包组的名称和groupid 要查找程序包组的名称或ID,例如与KDE桌面环境相关的组, ~]$ yum group list ids kde* Available environment groups: KDE Plasma Workspaces (kde-desktop-environment) Done 某些组被配置的存储库中的设置隐藏。例如,在服务器上,也可以使用 ~]$ yum group list hidden ids kde* Loaded plugins: product-id,subscription-manager Available Groups: KDE (kde-desktop) Done 您可以通过将其完整组名称(不带groupid部分)传递给 yum group install "group name" 您也可以通过groupid安装。 yum group install groupid 可以将groupid或带引号的组名称传递给该命令, yum install @group 安装KDE桌面组的四种等效方法 可以使用四种替代但等效的方法来安装软件包组。对于KDE Desktop,命令如下所示: ~]# yum group install "KDE Desktop" ~]# yum group install kde-desktop ~]# yum install @"KDE Desktop" ~]# yum install @kde-desktop 删除包组可以使用类似于 yum group remove group_name yum group remove groupid 此外, yum remove @group 将group替换为groupid或带引号的组名。同样,您可以替换环境组: yum remove @^group 删除KDE Desktop组的四种等效方法 与安装类似,您可以使用四种替代但等效的方法来删除软件包组。对于KDE Desktop,命令如下所示: ~]# yum group remove "KDE Desktop" ~]# yum group remove kde-desktop ~]# yum remove @"KDE Desktop" ~]# yum remove @kde-desktop yum 历史记录
事务列表To display a list of the twenty most recent transactions,as yum history list 要显示所有事务,请添加 yum history list all 要仅显示给定范围内的事务,请使用以下格式的命令: yum history list start_id..end_id 您还可以仅列出有关特定包或包的事务。为此,请使用包名称或glob表达式的命令: yum history list glob_expression… 列出五个最旧的事务 在 ~]# yum history list 1..5 Loaded plugins: langpacks,subscription-manager ID | Login user | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 5 | User <user> | 2013-07-29 15:33 | Install | 1 4 | User <user> | 2013-07-21 15:10 | Install | 1 3 | User <user> | 2013-07-16 15:27 | I,U | 73 2 | System <unset> | 2013-07-16 15:19 | Update | 1 1 | System <unset> | 2013-07-16 14:38 | Install | 1106 history list 所有形式的
Action(s)字段的可能值
Altered 字段的可能值
同步的 yum history sync 要显示有关当前使用的历史数据库的一些统计信息,请使用以下命令: yum history stats yum历史统计信息的示例输出 ~]# yum history stats Loaded plugins: langpacks,subscription-manager File : //var/lib/yum/history/history-2012-08-15.sqlite Size : 2,766,848 Transactions: 41 Begin time : Wed Aug 15 16:18:25 2012 End time : Wed Feb 27 14:52:30 2013 Counts : NEVRAC : 2,204 NEVRA : 2,204 NA : 1,759 NEVR : 2,204 rpm DB : 2,204 yum DB : 2,204 history stats yum还允许您显示所有过去交易的摘要 yum history summary 要仅显示给定范围内的事务,请键入 yum history summary start_id..end_id 与 yum history summary glob_expression… 五项最新事务摘要 ~]# yum history summary 1..5 Loaded plugins: langpacks,subscription-manager Login user | Time | Action(s) | Altered ------------------------------------------------------------------------------- Jaromir ... <jhradilek> | Last day | Install | 1 Jaromir ... <jhradilek> | Last week | Install | 1 Jaromir ... <jhradilek> | Last 2 weeks | I,U | 73 System <unset> | Last 2 weeks | I,U | 1107 history summary 有形式的 从包的角度列出事务 yum history package-list glob_expression… 追踪包的历史 要跟踪订阅管理器和相关包的历史记录,请在shell提示符下键入以下内容: ~]# yum history package-list subscription-manager* Loaded plugins: langpacks,subscription-manager ID | Action(s) | Package ------------------------------------------------------------------------------- 2 | Updated | subscription-manager-1.13.22-1.el7.x86_64 EE 2 | Update | 1.15.9-15.el7.x86_64 EE 2 | Obsoleted | subscription-manager-firstboot-1.13.22-1.el7.x86_64 EE 2 | Updated | subscription-manager-gui-1.13.22-1.el7.x86_64 EE 2 | Update | 1.15.9-15.el7.x86_64 EE 2 | Obsoleting | subscription-manager-initial-setup-addon-1.15.9-15.el7.x86_64 EE 1 | Install | subscription-manager-1.13.22-1.el7.x86_64 1 | Install | subscription-manager-firstboot-1.13.22-1.el7.x86_64 1 | Install | subscription-manager-gui-1.13.22-1.el7.x86_64 history package-list 在此示例中,在初始系统安装期间安装了三个软件包:subscription-manager,subscription-manager-firstboot和subscription-manager-gui。在第三个事务中,所有这些包都从版本1.10.11更新到版本1.10.17。 检查事务要显示单个事务的摘要,请使用 yum history summary id 这里,id代表事务的ID。 要更详细地检查特定事务或事务,请运行以下命令 yum history info id… ID参数是可选的,当你忽略它,yum会自动使用最后一个事务。请注意,在指定多个事务时,您还可以使用范围: yum history info start_id..end_id yum历史信息的示例输出 以下是两个事务的示例输出,每个事务安装一个新包: ~]# yum history info 4..5 Loaded plugins: langpacks,subscription-manager Transaction ID : 4..5 Begin time : Mon Dec 7 16:51:07 2015 Begin rpmdb : 1252:d2b62b7b5768e855723954852fd7e55f641fbad9 End time : 17:18:49 2015 (27 minutes) End rpmdb : 1253:cf8449dc4c53fc0cbc0a4c48e496a6c50f3d43c5 User : Maxim Svistunov <msvistun> Return-Code : Success Command Line : install tigervnc-server.x86_64 Command Line : reinstall tigervnc-server Transaction performed with: Installed rpm-4.11.3-17.el7.x86_64 @rhel-7-server-rpms Installed subscription-manager-1.15.9-15.el7.x86_64 @rhel-7-server-rpms Installed yum-3.4.3-132.el7.noarch @rhel-7-server-rpms Packages Altered: Reinstall tigervnc-server-1.3.1-3.el7.x86_64 @rhel-7-server-rpms history info 您还可以查看其他信息,例如在事务处理时使用的配置选项,或者从哪个存储库以及安装某些软件包的原因。要确定某个特定事务可用的附加信息,在shell提示符下键入以下内容 yum history addon-info id 与此类似 yum history addon-info last 示例输出yum history addon-info 对于历史记录中的第四个事务,该 ~]# yum history addon-info 4 Loaded plugins: langpacks,subscription-manager Transaction ID: 4 Available additional history information: config-main config-repos saved_tx history addon-info 恢复和重复事务除了查看事务历史之外,该 yum history undo id 要重复特定事务 yum history redo id 这两个命令还接受 请注意,两者 在管理多个相同的系统时,yum还允许您在其中一个系统上执行事务,将事务详细信息存储在文件中,经过一段时间的测试后,在其余系统上重复相同的事务。要将事务详细信息存储到文件,请在shell提示符下键入以下内容 yum -q history addon-info id saved_tx > file_name Once you copy this file to the target system,you can repeat the transaction by using the following command as yum load-transaction file_name 您可以配置 启动新的事务记录Yum将事务历史记录存储在单个SQLite数据库文件中。要启动新的事务历史记录,请运行以下命令 yum history new 这将在 配置YUM和YUM存储库yum和相关实用程序的配置信息位于 设置[main]选项
[main] cachedir=/var/cache/yum/$basearch/$releasever keepcache=0 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release # This is the default,if you make this bigger yum won‘t see if the metadata # is newer on the remote and so you‘ll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important,to have correct metadata,for distributions like # Fedora which don‘t keep old packages around. If you don‘t like this checking # interupting your command line usage,it‘s much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d
设置[repository]选项
以下是一个 [repository] name=repository_name baseurl=repository_url 每个
这里,repository_name是描述存储库的可读字符串。
将repository_url替换为存储库的repodata目录所在目录的URL:
通常此URL是HTTP链接,例如: baseurl=http://path/to/repo/releases/$releasever/server/$basearch/os/ 其他可用于
使用Yum变量您可以在
要定义自定义变量或覆盖现有变量的值,请在目录中创建与变量同名(不带“ 库描述通常包括操作系统名称。要定义一个名为的新变量 ~]# echo "Red Hat Enterprise Linux 7" > /etc/yum/vars/osname 您现在可以在文件中使用以下内容, 而不是“ Red Hat Enterprise Linux 7” name=$osname $releasever 查看当前配置要显示全局yum选项的当前值(即文件 yum-config-manager 要列出不同配置节的内容,请使用以下格式的命令: yum-config-manager section… You can also use a glob expression to display the configuration of all matching sections: yum-config-manager glob_expression… 查看主要部分的配置 要列出主要部分的所有配置选项及其对应值,请在shell提示符下键入以下内容: ~]$ yum-config-manager main * Loaded plugins: langpacks,subscription-manager ================================== main =================================== [main] alwaysprompt = True assumeyes = False bandwith = 0 bugtracker_url = https://bugzilla.redhat.com/enter_bug.cgi?product=Red%20Hat%20Enterprise%20Linux%206&component=yum cache = 0 [output truncated] 添加,启用和禁用Yum存储库添加Yum存储库要定义新存储库,可以在文件中添加一个 yum-config-manager --add-repo repository_url ...其中repository_url是 添加example.repo 要添加位于http://www.example.com/example.repo的存储库,请在shell提示符下键入以下内容: ~]# yum-config-manager --add-repo http://www.example.com/example.repo Loaded plugins: langpacks,subscription-manager adding repo from: http://www.example.com/example.repo grabbing file http://www.example.com/example.repo to /etc/yum.repos.d/example.repo example.repo | 413 B 00:00 repo saved to /etc/yum.repos.d/example.repo 启用Yum存储库要启用特定存储库或存储库,请在shell提示符下键入以下内容 yum-config-manager --enable repository… ...其中repository是唯一的存储库ID(用于 yum-config-manager --enable glob_expression… 启用在/etc/yum.conf的自定义部分中定义的存储库。 启用定义的 ~]# yum-config-manager --enable example* Loaded plugins: langpacks,subscription-manager ============================== repo: example ============================== [example] bandwidth = 0 base_persistdir = /var/lib/yum/repos/x86_64/7Server baseurl = http://www.example.com/repo/7Server/x86_64/ cache = 0 cachedir = /var/cache/yum/x86_64/7Server/example [output truncated] 启用所有存储库 要启用 ~]# yum-config-manager --enable * Loaded plugins: langpacks,subscription-manager ============================== repo: example ============================== [example] bandwidth = 0 base_persistdir = /var/lib/yum/repos/x86_64/7Server baseurl = http://www.example.com/repo/7Server/x86_64/ cache = 0 cachedir = /var/cache/yum/x86_64/7Server/example [output truncated] 成功后,该 禁用Yum存储库要禁用yum存储库,请运行以下命令: yum-config-manager --disable repository… ...其中repository是唯一的存储库ID(用于 yum-config-manager --disable glob_expression… 禁用所有存储库 要禁用 ~]# yum-config-manager --disable * Loaded plugins: langpacks,subscription-manager ============================== repo: example ============================== [example] bandwidth = 0 base_persistdir = /var/lib/yum/repos/x86_64/7Server baseurl = http://www.example.com/repo/7Server/x86_64/ cache = 0 cachedir = /var/cache/yum/x86_64/7Server/example [output truncated] 成功后,该 创建Yum存储库要设置yum存储库:
将包添加到已创建的yum存储库要将包添加到已创建的yum存储库:
YUM 插件Yum提供扩展和增强其操作的插件。默认情况下会安装某些插件。当您调用任何 [[email?protected] repodata]# yum info yum Loaded plugins: fastestmirror,subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. 使用 启用,配置和禁用Yum插件要启用yum插件。请确认在 plugins=1 您可以通过将此行更改为 每个已安装的插件在 [main] enabled = 1 与 如果您通过设置 如果您只想为单个 如果要为单个 ?]# yum update --disableplugin=aliases 为该 ?]# yum update --disableplugin=aliases,lang* 安装其他Yum插件Yum插件通常遵循包命名约定,但并非总是如此:例如,提供kabi插件的包被命名。您可以像安装其他软件包一样安装yum插件。例如,要安装yum-aliases插件,请在shell提示符下键入以下内容: ?]# yum install yum-plugin-aliases 使用Yum插件以下列表提供了几个有用的yum插件的说明和使用说明。插件按名称列出,括号包含包的名称。 search-disabled-repos search-disabled-repos插件可以让你暂时或永久启用已禁用的存储库,以帮助解决依赖关系。启用此插件后,当Yum由于依赖项解析失败而无法安装软件包时,它会暂时启用已禁用的存储库并重试。如果安装成功,Yum还提供永久启用使用的存储库。请注意,该插件仅适用于由subscription-manager管理的存储库,而不适用于自定义存储库。 To configure the search-disabled-repos plug-in,edit the configuration file located in Table 9.3. Supported search-disabled-repos.conf directives
kabi (kabi-yum-plugins) The kabi plug-in checks whether a driver update package conforms with the official Red Hat kernel Application Binary Interface (kABI). With this plug-in enabled,when a user attempts to install a package that uses kernel symbols which are not on a whitelist,a warning message is written to the system log. Additionally,configuring the plug-in to run in enforcing mode prevents such packages from being installed at all. To configure the kabi plug-in,edit the configuration file located in Table 9.4. Supported kabi.conf directives
product-id (subscription-manager) The product-id plug-in manages product identity certificates for products installed from the Content Delivery Network. The product-id plug-in is installed by default. langpacks (yum-langpacks) The langpacks plug-in is used to search for locale packages of a selected language for every package that is installed. The langpacks plug-in is installed by default. aliases (yum-plugin-aliases) The aliases plug-in adds the yum-changelog (yum-plugin-changelog) The yum-changelog plug-in adds the yum-tmprepo (yum-plugin-tmprepo) The yum-tmprepo plug-in adds the yum-verify (yum-plugin-verify) The yum-verify plug-in adds the yum-versionlock (yum-plugin-versionlock) The yum-versionlock plug-in excludes other versions of selected packages,which enables protecting packages from being updated by newer versions. With the 自动刷新包数据库并使用YUM-CRON下载更新该 使用默认设置,
该 /etc/yum/yum-cron.conf 对于日常任务。 /etc/yum/yum-cron-hourly.conf 每小时任务。 启用自动安装更新要启用下载更新的自动安装,请通过设置以下 apply_updates = yes 设置可选的电子邮件通知默认情况下,该 您可以使用与影响所有 要启用
启用或禁用特定存储库在
测试Yum-cron设置要在
禁用Yum-cron消息
自动清洁包
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |