以前に書いた「up2dateによるRPMパッケージの更新管理 」という記事で、up2dateコマンドを通してRPMパッケージのアップデート等が行える事を書いたのですが、今度はyumコマンド(ヤムと呼ぶらしい)を通したパッケージ管理について書いてみたいと思います。
何故yumコマンドを使う事になったかというと、RedHat Enterprise Linux5からはyumコマンドのパッケージ管理が標準となっており、up2dateコマンドは存在しません。
そして、RedHat Enterprise Linux5のクローンであるCentOS5でも同様にyumコマンドによるパッケージ管理が標準になっています。
yumコマンドもup2dateコマンドも、どちらもやってくれる事は同じです。
サーバーにインストールされているパッケージに対して、セキュリティ上の問題等が改善された新しいバージョンのパッケージが出ていないかをチェックし、それらを簡単にインストールしてくれます。
ここでは、CentOS5の環境で書いています。
yumコマンドの設定方法
1. GPGキーのインポート
これはup2dateコマンドを使用していたときも同様だったのですが、まず初めにGPGキー(GNU Privacy Guard)をインポートしておきます。
GPGキーは、アップデートする対象のパッケージが本物であるかどうかをチェックする際に利用される公開鍵になります。
この鍵を元に、各パッケージに埋め込まれている暗号化した署名を解読してパッケージが正規のものであるか(誰かによって改編されていないか)をチェックします。
RedHat EL5以前のものを使っているのであれば、up2dateコマンドを実行した際に最初にGPGキーをインポートするか質問されますので、あまり意識的にインポートすると言う事はありません。
しかし、CentOS系であれば手動でインポートするコマンドを実行する必要があります。
GPGキーは、下記の場所にありますのでそれを取り込んでおきます。
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
※ 外部にあるGPGキーをHTTP経由でインポートする事もできます。
GPGキーがインポートできているか、確認します。
# rpm -qa gpg-pubkey* gpg-pubkey-e8562897-459f07a4
2. N/W接続設定
社内のLAN環境などインターネットに出る際にプロキシをとおる必要がある場合は、その設定を加えないとリポジトリにアクセスする事が出来ません。
設定ファイル(/etc/yum.conf)にプロキシの情報を加えます。
proxy=http://proxy.hoge.com:8080/
※ プロキシにアクセスする際にユーザー名やパスワードが必要な場合は、同設定ファイルに下記の項目を追加することで
対処できます。
proxy_username=foo proxy_password=bar
3. リポジトリ情報の編集
リポジトリ(パッケージの情報が集約されているサーバー)の情報を設定します。
設定ファイル(/etc/yum.repos.d/CentOS-Base.repo)にはデフォルトのリポジトリ情報が入っているので、特に編集をしなくても問題ありません。
ですが、リポジトリは世界中にミラーサイトがあるので、なるべく近い場所を指定してあげた方が更新処理が早くなります。
リポジトリに関連する設定ファイルは、「/etc/yum.repos.d」ディレクトリ以下に、「.repo」という拡張子を付けて保存しておきます。
例えば、理化学研究所 にあるリポジトリを設定する場合は、下記の内容の設定ファイルを作っておきます。
例)
[base] name=CentOS-$releasever - Base< baseurl=http://ftp.riken.jp/Linux/centos/$releasever/os/$basearch/ gpgcheck=1 enable=1 #released updates [update] name=CentOS-$releasever - Updates baseurl=http://ftp.riken.jp/Linux/centos/$releasever/updates/$basearch/ gpgcheck=1 enable=1 #packages used/produced in the build but not released [addons] name=CentOS-$releasever - Addons baseurl=http://ftp.riken.jp/Linux/centos/$releasever/addons/$basearch/ gpgcheck=1 enable=1 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=http://ftp.riken.jp/Linux/centos/$releasever/extras/$basearch/ gpgcheck=1 enable=1
※ 上記の「enable=1」の箇所に「0」を指定すると、そのリポジトリは対象外となります。
これで一通りの設定は完了です。
覚えておきたいyumコマンドのオプション
- パッケージの更新情報を取得する
サーバーにインストールしているパッケージに対して最新のバージョンのものが出ていないかを定期的にチェックする必要があります。
そのような場合は、下記のコマンドで確認が行えます。
# yum check-update
インストールしている全パッケージに対して更新チェックを行いますので大量の結果が出力される場合があります。
特定のパッケージのみの更新情報を知りたい場合は、下記のように後ろにパッケージ名を入力します。
# yum check-update http*
これでhttp関連のパッケージに対して最新のものが無いかチェックされます。
※ 「*」をつける事で、その文字を含むパッケージという指定が可能です。
注意が必要なのは、現在インストールされているパッケージに対しての更新チェックなので、そのパッケージがサーバーにインストールされていない場合、結果は表示されません。
「check-update」オプション以外、下記のコマンドオプションで更新情報をチェックする事もできます。
# yum list updates
こちらでも、インストールしているパッケージを対象に、更新チェックを行ってくれます。
- パッケージの詳細情報を知る
下記の「info」オプションにパッケージ名を指定する事で、特定のパッケージの詳細情報を知る事ができます。
また、現在インストールされているパッケージの情報を知る事もできます。
ためしにyumコマンドの詳細情報を表示してみます。
# yum info yum Loading "installonlyn" plugin Setting up repositories Reading repository metadata in from local files Excluding Packages in global exclude list Finished Installed Packages Name : yum Arch : noarch Version: 3.0.5 Release: 1.el5.centos.5 Size : 1.8 M Repo : installed Summary: RPM installer/updater Description: Yum is a utility that can check for and automatically download and install updated RPM packages. Dependencies are obtained and downloaded automatically prompting the user as necessary. Available Packages Name : yum Arch : noarch Version: 3.2.8 Release: 9.el5.centos.2.1 Size : 582 k Repo : update Summary: RPM installer/updater Description: Yum is a utility that can check for and automatically download and install updated RPM packages. Dependencies are obtained and downloaded automatically prompting the user as necessary.
最初に現在サーバーにインストールされているパッケージのバージョン等の情報、次にリポジトリ上にある更新できるバージョンの情報が表示されます。
rpmコマンドでも現在インストールされているパッケージの情報を取得する事ができますが、「info」オプション付きでyumコマンドを実行するとリポジトリの最新バージョンの情報もあわせて表示してくれます。
ためしにrpmコマンドで確認してみると・・・
# rpm -qa | grep yum yum-3.0.5-1.el5.centos.5 yum-updatesd-3.0.5-1.el5.centos.5 yum-metadata-parser-1.0-8.fc6
yumコマンドを実行した際の「Installed Packages」の項目に表示されているバージョンと同じだという事がわかります。
このコマンドも、「check-update」オプションの時と同様、そのパッケージがサーバーにインストールされていない場合、結果は出力されません。
- パッケージ情報を検索する
特定のパッケージの特定のバージョンが存在するか、検索したい場合があります。
例えば、現在インストールされているパッケージに何らかの不具合があって、前のバージョンに戻したいというような場合です。
こういう場合、「search」オプションに探したいパッケージ名を付けて実行すると、リポジトリ上にあるパッケージを探す事が可能です。
# yum search yum yum.noarch 3.2.8-9.el5.centos.2.1 update Matched from: yum Yum is a utility that can check for and automatically download and install updated RPM packages. Dependencies are obtained and downloaded automatically prompting the user as necessary. http://linux.duke.edu/yum/ yumex.noarch 2.0.3-2.el5.centos extras Matched from: yumex Yum Extender graphical package management tool Graphical User Interface for Yum. http://www.yum-extender.org yum.noarch 3.2.8-9.el5.centos.2.1 updates Matched from: yum Yum is a utility that can check for and automatically download and install updated RPM packages. Dependencies are obtained and downloaded automatically prompting the user as necessary. http://linux.duke.edu/yum/ yum.noarch 3.0.5-1.el5.centos.5 installed Matched from: yum Yum is a utility that can check for and automatically download and install updated RPM packages. Dependencies are obtained and downloaded automatically prompting the user as necessary. http://linux.duke.edu/yum/
上記は結果の一部ですが、yumパッケージの様々なバージョンが出力されていることが分かります。
- 特定のパッケージを更新/インストールする
これがyumを使う上での本題となるでしょう。
現在インストールされているパッケージを最新のものに更新します。
# yum update yum
上記では、yumパッケージを更新処理します。
このオプションも、サーバーにインストールされているパッケージが更新対象となりますので、インストールされていないパッケージは処理は行われません。
# yum update zsh Loading "installonlyn" plugin Setting up Update Process Setting up repositories Reading repository metadata in from local files Excluding Packages in global exclude list Finished Could not find update match for zsh No Packages marked for Update/Obsoletion
上記のように、zshパッケージはインストールされていないので、処理が何も行われません。
では、次にパッケージを新規に導入したい場合です。
先ほどの、zshパッケージをyumコマンドを通してインストールしてみます。
# yum install zsh Loading "installonlyn" plugin Setting up Install Process Setting up repositories Reading repository metadata in from local files Excluding Packages in global exclude list Finished Parsing package install arguments Resolving Dependencies --> Populating transaction set with selected packages. Please wait. ---> Downloading header for zsh to pack into transaction set. zsh-4.2.6-1.i386.rpm 100% |=========================| 78 kB 00:13 ---> Package zsh.i386 0:4.2.6-1 set to be updated --> Running transaction check Dependencies Resolved ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: zsh i386 4.2.6-1 base 1.7 M Transaction Summary ============================================================================= Install 1 Package(s) Update 0 Package(s) Remove 0 Package(s)Total download size: 1.7 M Is this ok [y/N]: y Downloading Packages: (1/1): zsh-4.2.6-1.i386.r 100% |=========================| 1.7 MB 01:13 Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing: zsh ######################### [1/1] Installed: zsh.i386 0:4.2.6-1 Complete!
試しに、rpmコマンドを使って本当にパッケージがインストールされている確認してみます。
(infoオプションを指定しても確認できますけどね)
# rpm -qa | grep zsh zsh-4.2.6-1
ちゃんとインストールされていますね。
- パッケージのグループをまとめて更新/インストールする
CentOSをインストールする際に、パッケージのグループを選択してインストールしたかと思います。
例えば、「X Window System」や「KDE」などといったグループです。
それらを選択する事で関連するパッケージがインストールされます。
yumコマンドではそのグルーピングされたパッケージに対してまとめて更新したり、インストールしたりする事ができます。
まずは、どのようなパッケージグループがインストールされているのかをチェックしてみます。
# yum grouplist Loading "installonlyn" plugin Setting up Group Process Setting up repositories comps.xml 100% |=========================| 914 kB 00:01 yumgroups.xml 100% |=========================| 9.7 kB 00:00 Installed Groups: Office/Productivity Development Libraries Editors System Tools Virtualization GNOME Desktop Environment Dialup Networking Support Network Servers Java X Window System Graphics Web Server Ruby Printing Support Mail Server Server Configuration Tools Administration Tools Graphical Internet Available Groups: Tomboy Cluster Storage Engineering and Scientific MySQL Database Beagle GNOME Software Development Text-based Internet X Software Development Legacy Network Server DNS Name Server Authoring and Publishing Base FTP Server Mono Games and Entertainment XFCE-4.4 Legacy Software Development Clustering Java Development OpenFabrics Enterprise Distribution Emacs Legacy Software Support Windows File Server KDE Software Development KDE (K Desktop Environment) Horde Sound and Video PostgreSQL Database News Server Development Tools Yum Utilities FreeNX and NX Done
「Installed Groups:」の項目に記載されているグループ名が、インストールされているパッケージグループです。
そして、「Available Groups:」に記載されているグループ名が、インストール可能なパッケージ名です。
パッケージグループのインストールを行いたい場合、「groupinstall」オプションにパッケージグループ名を指定することで可能です。
# yum groupinstall "Emacs"
上記では、Emacsのパッケージグループを新たにインストールします。
パッケージグループをまとめて更新したい場合は、「groupupdate」オプションを指定します。
# yum groupupdate "Emacs"
ちなみに、パッケージグループをまとめて削除したい場合に使うのが「groupremove」オプションです。
# yum groupremove "Emacs"
ここまでが基本的な使い方です。
まずは、パッケージの更新情報があるか「check-update」オプションを指定してyumを実行し、ある場合は「update」オプションで更新処理を行うというのが、基本的な運用の流れになるのではないでしょうか。
一部のパッケージを更新対象外としたい場合
yumを通して様々なパッケージを更新、インストールをすることができますが、中には更新したくないパッケージというのもあったりします。
例えば、PHPを動かしているサーバーに対して、PHP関連のパッケージを更新してしまうと、プログラム自体に影響が出てしまう場合もあるので、きちんと動作検証をしてから更新したといった場合です。
また、KernelのパッケージはH/Wとの関連もあるので、ホイホイとアップデートしてしまうと起動しなくなったといった事もありえます。
こういった場合、その管理対象外としたいパッケージを設定ファイル(/etc/yum.conf)に記載しておきます。
exclude=http*,php*
上記では、http関連のパッケージとPHP関連のパッケージを更新対象外に指定しています。
複数ある場合は、カンマで区切っていきます。
yumコマンドを使った際のエラーの対処
1. エラー其の一
# yum check-update Loading "installonlyn" plugin Setting up repositories Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=5&arch=i386&repo=extras error was [Errno 4] IOError: <urlopen error (110, '\xe6\x8e\xa5\xe7\xb6\x9a\xe3\x81\x8c\xe3\x82\xbf\xe3\x82\xa4\xe3\x83\xa0\xe3\x82\xa2\xe3\x82\xa6\xe3\x83\x88\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f')> http://mirror.centos.org/centos/5/extras/i386/repodata/repomd.xml: [Errno 12] Timeout: <urlopen error timed out> Trying other mirror. Error: Cannot open/read repomd.xml file for repository: extras
指定のリポジトリと通信ができなかった場合にでました。
プロキシを介してインターネットに出る必要がある場合、そのプロキシ情報を設定ファイル(/etc/yum.conf)に記載しておく必要があります。
2. エラー其の二
# yum check-update Loading "installonlyn" plugin Setting up repositories Reading repository metadata in from local files primary.xml.gz 100% |=========================| 91 kB 00:00 http://ftp.yz.yamagata-u.ac.jp/pub/linux/centos/5.2/updates/i386/repodata/primary.xml.gz: [Errno -1] Metadata file does not match checksum Trying other mirror. primary.xml.gz 100% |=========================| 91 kB 00:00 http://ftp.iij.ad.jp/pub/linux/centos/5.2/updates/i386/repodata/primary.xml.gz: [Errno -1] Metadata file does not match checksum Trying other mirror. Error: failure: repodata/primary.xml.gz from updates: [Errno 256] No more mirrors to try.
一度、下記のコマンドオプションででヘッダ情報等を全てクリアして再実行すれば直りました。
# yum clean all
[PR]
[PR]