保守・運用でよく使うyum関連コマンドやオプションあれこれ | A Day In The Boy's Life

A Day In The Boy's Life

とあるエンジニアのとある1日のつぶやき。

RedHatやCentOSなどでパッケージをインストール/アンインストールするコマンドとしてyumやrpmコマンドがありますが、その辺に関連して保守・運用上で個人的によく利用するコマンドやオプションなどのまとめです。

yumコマンドの基本的な使い方は「yumによるRPMパッケージの更新管理 」を参考にしてみてください。


・ リポジトリに公開されているパッケージを検索する


yumコマンドを使ってインストール可能なパッケージをリポジトリから検索します。


# yum search httpd
Loaded plugins: rhnplugin, security
This system is receiving updates from RHN Classic or RHN Satellite.
Excluding Packages in global exclude list
Finished
Excluding Packages from Red Hat Enterprise Linux (v. 5 for 64-bit x86_64)
Finished
=================================================================== Matched: httpd 

===================================================================
mod_ssl.x86_64 : Apache HTTP Server 〓 SSL/TLS 〓〓〓〓〓
system-config-httpd.noarch : Apache 設定ツール
httpd.x86_64 : Apache HTTP Server

・ インストールされているパッケージを検索する


インストール済みのパッケージを検索します。


# rpm -q httpd
httpd-2.2.3-83.el5_10

または、yumコマンドでも。


# yum info httpd
Loaded plugins: rhnplugin, security
This system is receiving updates from RHN Classic or RHN Satellite.
Excluding Packages in global exclude list
Finished
Excluding Packages from Red Hat Enterprise Linux (v. 5 for 64-bit x86_64)
Finished
Installed Packages
Name       : httpd
Arch       : x86_64
Version    : 2.2.3
Release    : 83.el5_10
Size       : 3.2 M
Repo       : installed
Summary    : Apache HTTP Server
URL        : http://httpd.apache.org/
License    : Apache Software License
Description: The Apache HTTP Server is a powerful, efficient, and extensible
           : web server.

・ インストールされているコマンドがどのパッケージに含まれるか調べる


コマンドはわかるんだけどどのパッケージに含まれてるんだっけって時はrpmコマンドで調べられます。


# rpm -qf /usr/bin/sar
sysstat-7.0.2-13.el5

詳細が知りたければ


# rpm -qi httpd
Name        : httpd                        Relocations: (not relocatable)
Version     : 2.2.3                             Vendor: Red Hat, Inc.
Release     : 83.el5_10                     Build Date: 2013年09月27日 20時41分07秒
Install Date: 2013年10月28日 13時56分32秒      Build Host: x86-001.build.bos.redhat.com
Group       : System Environment/Daemons    Source RPM: httpd-2.2.3-83.el5_10.src.rpm
Size        : 3324015                          License: Apache Software License
Signature   : DSA/SHA1, 2013年10月11日 23時26分24秒, Key ID 5326810137017186
Packager    : Red Hat, Inc. 
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

※ オプション「-qfi」として、コマンドから詳細を調べることも可能。 これは、該当のライブラリがどのパッケージに含まれているものか(どこからインストールされたか)を調べることもできて便利です。


# rpm -qf /usr/lib/libssl.so
openssl-devel-0.9.8e-32.el5_11

・ パッケージの依存関係を調べる


yumコマンドでインストールする際には自動的に依存関係を調べて関連するパッケージもまとめてインストールしてくれたり、エラーがあった場合でもどのパッケ ージと依存関係にあるのか表示してくれたりはしますが、rpmコマンドで調べることもできます。


# rpm -q --whatrequires httpd
system-config-httpd-1.3.3.3-1.el5
mod_ssl-2.2.3-83.el5_10
httpd-manual-2.2.3-83.el5_10
httpd-devel-2.2.3-83.el5_10
httpd-devel-2.2.3-83.el5_10

・ ログから調べる


(コマンドではないですが)現在インストールされているパッケージの一覧は、「/var/log/rpmpkgs」に出力されています。(これは、コマンドから「rpm -qa」を実行したのと同じ)


Deployment_Guide-en-US-5.8-1.el5.noarch.rpm
Deployment_Guide-ja-JP-5.8-1.el5.noarch.rpm
GConf2-2.14.0-9.el5.i386.rpm
GConf2-2.14.0-9.el5.x86_64.rpm
GConf2-devel-2.14.0-9.el5.x86_64.rpm
MAKEDEV-3.23-1.2.x86_64.rpm
- snip -

いつ、そのパッケージがインストールされたのかは「/var/log/yum.log」を参照します。(「rpm -qi」で出力される「Install Date」を見てもわかりますがその日・週のログとしてまとまるので見やすい)


Jan 25 08:00:35 Updated: openssl-0.9.8e-32.el5_11.x86_64
Jan 25 08:00:35 Updated: 1:cups-libs-1.3.7-32.el5_11.x86_64
Jan 25 08:00:36 Updated: openssl-0.9.8e-32.el5_11.i686

・ パッケージの更新を通知する


バグ/セキュリティフィックスのパッチが提供された場合にいち早く情報を取得できるように更新通知をメールで受け取ったり、自動適用したりすることができます。

設定は、/etc/yum/yum-updatesd.confにて行います。


[main]
# how often to check for new updates (in seconds)
run_interval = 86400
# how often to allow checking on request (in seconds)
updaterefresh = 6000

# how to send notifications (valid: dbus, email, syslog)
emit_via = email
email_to=webmaster@example.com
email_from=yum-updatesd@localhost
smtp_server=localhost:25
# should we listen via dbus to give out update information/check for
# new updates
dbus_listener = yes

# automatically install updates
do_update = no
# automatically download updates
do_download = yes
# automatically download deps of updates
do_download_deps = yes


説明が書かれているのでなんとなく項目の意味はわかると思いますが、run_intervalでチェック間隔を調整したり、email_xxxx関連でメール通知の設定、db_updateなどでは自動更新するかどうかの設定ができます(本番環境とかで自動適用はしないほうがいいでしょうけど)


設定が終わったらデーモンを再起動。


/etc/init.d/yum-updatesd restart

・ パッケージをダウンロードする


yumdownloaderコマンドを利用すれば、サーバーにインストールすることなくRPMパッケージだけをダウンロードすることができます。(yumdownloaderコマンドはyum-utilsに含まれています)


# yumdownloader --destdir=/tmp httpd
Loaded plugins: rhnplugin
This system is receiving updates from RHN Classic or RHN Satellite.
httpd-2.2.3-91.el5.x86_64.rpm

ちなみに、yumコマンドでもdownloadonlyオプションを使えばダウンロードすることができます。


# yum install --downloadonly --downloaddir=/tmp httpd