ウェブサイト検索

RHEL Linux で YUM/DNF を使用してパッケージの更新を無効にする方法


DNF (Dandified Yum) は、YUM (Yellowdog Updater, Modified) の次世代バージョンであり、Red Hat ベースの Linux ディストリビューション用のオープンソースのデフォルト パッケージ マネージャーであり、取得、インストール、アップグレード、削除、公式ソフトウェア リポジトリとサードパーティ リポジトリからパッケージをクエリします。

システムの更新中に、Apache サーバー (HTTP)、MySQLPHP、 またはその他の主要なアプリケーション。そのようなソフトウェアを更新すると、サーバー上で現在実行中の Web アプリケーションが破損し、重大な問題が発生する可能性があるためです。アプリケーションに新しいアップデートが適用されるまで、そのようなソフトウェアのアップデートを停止することをお勧めします。

この記事では、RHEL などの RPM ベースのディストリビューションで YUM および DNF パッケージ マネージャーを使用して特定のパッケージの更新を除外 (無効化) する方法を説明します。 CentOSFedoraRocky Linux、およびAlmaLinux。また、サードパーティのリポジトリから特定のパッケージの更新を除外または無効にすることもできます。

除外構文は次のようになります。

exclude=package package1 packages*

上記の exclude ディレクティブは、パッケージのリストとともに /etc/yum.conf または /etc/dnf/dnf.conf 設定ファイルで定義されています。アップデートまたはインストールから除外します。

上記の構文では、「パッケージ」、「パッケージ1」、および「パッケージ」のアップデートまたはインストールのリストが除外されます。パッケージを除外するには、各キーワードをスペースで区切る必要があります。

YUM または DNF でパッケージを除外する方法

特定のパッケージの更新を除外 (無効化) するには、選択したエディターで /etc/yum.conf または /etc/dnf/dnf.conf というファイルを開きます。

vi /etc/yum.conf
OR
vi /etc/dnf/dnf.conf

次に示すように、exclude キーワードを使用してファイルの最後に次の行を追加します。

[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=16&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

## Exclude following Packages Updates ##
exclude=httpd php mysql

上の例では、行 exclude により、「httpd」、「php」、「mysql」の更新が無効になります。パッケージ。以下に示すように、YUM コマンドを使用して、そのうちの 1 つをインストールまたは更新してみましょう。

yum update httpd
OR
dnf update httpd
サンプル出力
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.01link.hk
 * extras: centos.01link.hk
 * updates: mirrors.hns.net.in
base                                                   | 3.7 kB     00:00
extras                                                 | 3.0 kB     00:00
updates                                                | 3.5 kB     00:00
updates/primary_db                                     | 2.7 MB     00:16
Setting up Update Process
No Packages marked for Update

EPEL リポジトリからパッケージを除外する方法

EPEL リポジトリからパッケージのインストールまたは更新を除外するには、/etc/yum.repos.d/epel.repo というファイルを開きます。

vi /etc/yum.repos.d/epel.repo

更新から除外するパッケージを指定して、除外行を追加します。

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
## Exclude following Packages Updates ##
exclude=perl php python

ここで、図に示すように yum/dnf コマンドを使用して、EPEL リポジトリから上記で指定したファイルを更新してみます。

dnf update perl php python
OR
yum update perl php python
サンプル出力
Last metadata expiration check: 0:00:37 ago on Wednesday 17 November 2021 03:41:28 AM EST.
Package perl available, but not installed.
No match for argument: perl
No match for argument: php
No match for argument: python
Error: No packages marked for upgrade.

yum/dnf コマンドライン オプションを使用して、パッケージをリポジトリ ファイルに追加せずに除外することもできます。

yum --exclude=httpd update
Or
dnf --exclude=httpd update

パッケージのリストを除外するには、次のようにコマンドを使用します。

yum --exclude=mysql\* --exclude=httpd\* update
Or
dnf --exclude=mysql\* --exclude=httpd\* update

この方法で、必要なパッケージの更新を除外できます。他にも方法はたくさんあります。たとえば、最近、Linux のyum コマンドを使用して特定のパッケージをブロック/無効化、またはロックする 4 つの便利な方法に関する記事をまとめました。