『Spacewalk』でクライアントが参照するローカルリポジトリサーバを構築する(CentOSのSecurityUpdate用のリポジトリサーバ構築)

前回、RHEL系OSの統合管理ツール『Spacewalk』についてインストールしたが、今回は『Spacewalk』上にクライアントから参照できるローカルリポジトリサーバを構築して各クライアントに参照させてみる。
設定には、有志の作ったこちらのスクリプトを用いている。
今回は、CentOSで「yum --security」を利用できるようにローカルリポジトリサーバを『Spacewalk』上に構築して、各クライアントがこのリポジトリサーバを参照するようにする。

1.Spacewalkでのセキュリティリポジトリサーバの構築

まず、以下のコマンドでスクリプトをダウンロード、インストールする。

git clone https://github.com/angrox/spacewalk-api-scripts
cp spacewalk-api-scripts/*/*.py /usr/local/bin/

次に、以下のコマンドでセキュリティリポジトリの構築、Spacewalkでの利用設定を行う。

yum install -y createrepo yum-plugin-security bzip2 wget
mkdir -p /var/www/html/pub/centos-security && cd /var/www/html/pub/centos-security
/usr/local/bin/spacewalk-create-yumrepo.py -s <SpacewalkサーバのIPアドレス> -u <Spacewalkユーザ名> -p <パスワード> -c <チャンネル名(ラベル)> -d /var/www/html/pub/centos-security

これで、対象のディレクトリをSpacewalkでリポジトリサーバとして指定する準備ができた。
あとは、以下のコマンドでセキュリティリポジトリを作成する。

wget https://raw.githubusercontent.com/vmfarms/generate_updateinfo/master/generate_updateinfo.py
createrepo /var/www/html/pub/centos-security
python generate_updateinfo.py --destination=/var/www/html/pub/centos-security --release=7 <(curl -s http://cefs.steve-meier.de/errata.latest.xml.bz2 | bzip2 -dc)
modifyrepo /var/www/html/pub/centos-security/updateinfo-7/updateinfo.xml /var/www/html/pub/centos-security/repodata/

これで、セキュリティ用のリポジトリサーバが構築できた。
※この手順だとセキュリティ情報の更新処理はしてないので、運用する場合は最後の2個のコマンドをcrontabなどで定期的に実行させるようにすること。

2.クライアントへの設定追加

次に、クライアントへ参照先リポジトリサーバとして追加をする。
今回の場合は、設定チャンネル(設定ファイルを同期できるチャンネル)を作成し、クライアントを参加させることで対応する。 [設定] > [設定チャンネル]から「設定チャンネルの作成」をクリックする。

チャンネル名やラベルなどを定義する。

作成した設定チャンネルから、「設定ファイルまたはディレクトリの作成」をクリックする。

遷移先で、以下のように設定を記述する。

  • ファイル名パス … /etc/yum.repos.d/CentOS-Security-Base.repo

ファイルの中身は以下。

[security]
name=CentOS-$releasever - Security
baseurl=http://<SpacewalkサーバのIPアドレスorホスト名>/pub/centos-security/

設定ファイル追加後、[設定] > [システム] > [目的のシステム]を開き、対象のクライアントを選択したら「Spacewalk設定管理を有効にする」をクリックする。

なお、もし失敗するようであれば、クライアント側に必要なパッケージが入ってない可能性が高いので、以下のコマンドでパッケージのインストール、サービスの起動を行う。

yum install osad
systemctl start  osad
yum install -y rhncfg-actions

設定チャンネルとクライアントが紐づけられたら、対象の設定チャンネルの[ファイルの配備]タブからデプロイを行う。

これで、クライアントにリポジトリファイルが設置されるはずだ。
あとは、実際にセキュリティアップデートを行えるか確認するだけだ。

yum update --security

[root@BS-PUB-CENT7-01 ~]# yum update --security
読み込んだプラグイン:fastestmirror, rhnplugin
This system is receiving updates from RHN Classic or Red Hat Satellite.
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
 --> 32:bind-license-9.9.4-29.el7_2.4.noarch from updates removed (updateinfo)
 --> systemd-sysv-219-19.el7_2.12.x86_64 from @updates removed (updateinfo)
 --> dnsmasq-2.66-14.el7_2.1.x86_64 from updates removed (updateinfo)
 --> selinux-policy-3.13.1-60.el7_2.7.noarch from @updates removed (updateinfo)
 --> tzdata-2016f-1.el7.noarch from @updates removed (updateinfo)
 --> 1:openssl-libs-1.0.1e-51.el7_2.5.x86_64 from @updates removed (updateinfo)
 --> 1:NetworkManager-1.0.6-30.el7_2.x86_64 from @updates removed (updateinfo)
 --> teamd-1.17-6.el7_2.x86_64 from @updates removed (updateinfo)
 --> systemd-libs-219-19.el7_2.12.x86_64 from @updates removed (updateinfo)
 --> selinux-policy-targeted-3.13.1-60.el7_2.7.noarch from @updates removed (updateinfo)
 --> kpartx-0.4.9-85.el7_2.6.x86_64 from updates removed (updateinfo)
 --> python-libs-2.7.5-38.el7_2.x86_64 from @updates removed (updateinfo)
 --> selinux-policy-3.13.1-60.el7_2.9.noarch from updates removed (updateinfo)
 --> systemd-219-19.el7_2.12.x86_64 from @updates removed (updateinfo)
 --> kmod-20-5.el7.x86_64 from @anaconda removed (updateinfo)
 --> teamd-1.17-7.el7_2.x86_64 from updates removed (updateinfo)
 --> 1:openssl-libs-1.0.1e-51.el7_2.7.x86_64 from updates removed (updateinfo)
 --> 1:NetworkManager-tui-1.0.6-31.el7_2.x86_64 from updates removed (updateinfo)
 --> 32:bind-license-9.9.4-29.el7_2.3.noarch from @updates removed (updateinfo)
 --> libteam-1.17-7.el7_2.x86_64 from updates removed (updateinfo)
 --> kmod-20-8.el7_2.x86_64 from updates removed (updateinfo)
 --> 1:NetworkManager-libnm-1.0.6-31.el7_2.x86_64 from updates removed (updateinfo)
 --> 32:bind-libs-lite-9.9.4-29.el7_2.3.x86_64 from @updates removed (updateinfo)
 --> libgudev1-219-19.el7_2.13.x86_64 from updates removed (updateinfo)
 --> python-libs-2.7.5-39.el7_2.x86_64 from updates removed (updateinfo)
 --> selinux-policy-targeted-3.13.1-60.el7_2.9.noarch from updates removed (updateinfo)
 --> kpartx-0.4.9-85.el7_2.5.x86_64 from @updates removed (updateinfo)
 --> 1:NetworkManager-tui-1.0.6-30.el7_2.x86_64 from @updates removed (updateinfo)
 --> epel-release-7-6.noarch from @extras removed (updateinfo)
 --> tuned-2.5.1-4.el7_2.3.noarch from @updates removed (updateinfo)
 --> epel-release-7-8.noarch from epel removed (updateinfo)
 --> 1:NetworkManager-libnm-1.0.6-30.el7_2.x86_64 from @updates removed (updateinfo)
 --> libteam-1.17-6.el7_2.x86_64 from @updates removed (updateinfo)
 --> systemd-libs-219-19.el7_2.13.x86_64 from updates removed (updateinfo)
 --> systemd-sysv-219-19.el7_2.13.x86_64 from updates removed (updateinfo)
 --> 1:openssl-1.0.1e-51.el7_2.5.x86_64 from @updates removed (updateinfo)
 --> python-2.7.5-39.el7_2.x86_64 from updates removed (updateinfo)
 --> systemd-219-19.el7_2.13.x86_64 from updates removed (updateinfo)
 --> kmod-libs-20-5.el7.x86_64 from @anaconda removed (updateinfo)
 --> 1:NetworkManager-team-1.0.6-30.el7_2.x86_64 from @updates removed (updateinfo)
 --> kmod-libs-20-8.el7_2.x86_64 from updates removed (updateinfo)
 --> 1:NetworkManager-1.0.6-31.el7_2.x86_64 from updates removed (updateinfo)
 --> 32:bind-libs-lite-9.9.4-29.el7_2.4.x86_64 from updates removed (updateinfo)
 --> 1:openssl-1.0.1e-51.el7_2.7.x86_64 from updates removed (updateinfo)
 --> python-2.7.5-38.el7_2.x86_64 from @updates removed (updateinfo)
 --> tuned-2.5.1-4.el7_2.6.noarch from updates removed (updateinfo)
 --> tzdata-2016h-1.el7.noarch from updates removed (updateinfo)
 --> 1:NetworkManager-team-1.0.6-31.el7_2.x86_64 from updates removed (updateinfo)
 --> dnsmasq-2.66-14.el7_1.x86_64 from @anaconda removed (updateinfo)
 --> libgudev1-219-19.el7_2.12.x86_64 from @updates removed (updateinfo)
4 package(s) needed (+0 related) for security, out of 29 available
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ kernel.x86_64 0:3.10.0-327.36.3.el7 を インストール
---> パッケージ kernel-tools.x86_64 0:3.10.0-327.28.2.el7 を 更新
---> パッケージ kernel-tools.x86_64 0:3.10.0-327.36.3.el7 を アップデート
---> パッケージ kernel-tools-libs.x86_64 0:3.10.0-327.28.2.el7 を 更新
---> パッケージ kernel-tools-libs.x86_64 0:3.10.0-327.36.3.el7 を アップデート
---> パッケージ python-perf.x86_64 0:3.10.0-327.28.2.el7 を 更新
---> パッケージ python-perf.x86_64 0:3.10.0-327.36.3.el7 を アップデート
--> 依存性解決を終了しました。

依存性を解決しました

===============================================================================================
 Package                   アーキテクチャー
                                          バージョン                     リポジトリー     容量
===============================================================================================
インストール中:
 kernel                    x86_64         3.10.0-327.36.3.el7            updates          33 M
更新します:
 kernel-tools              x86_64         3.10.0-327.36.3.el7            updates         2.4 M
 kernel-tools-libs         x86_64         3.10.0-327.36.3.el7            updates         2.3 M
 python-perf               x86_64         3.10.0-327.36.3.el7            updates         2.4 M

トランザクションの要約
===============================================================================================
インストール  1 パッケージ
更新          3 パッケージ

総ダウンロード容量: 40 M
Is this ok [y/d/N]:

無事、設定ファイルのデプロイが行われたようだ。

番外編 ~epel-releaseとかの場合~

Spacewalkの管理画面から[チャンネル] > [ソフトウェアチャンネルの管理] > [リポジトリの管理]を開き、「リポジトリの作成」をクリックする。

リポジトリとして、名称やリポジトリサーバのURL(今回の場合は、「http://<SpacewalkサーバのIPアドレスorホスト名>/pub/centos-security」としている)を入力し「リポジトリの作成」を行う。

リポジトリ作成後、[チャンネル] > [ソフトウェアチャンネルの管理] > [ソフトウェアパッケージの管理]からローカルリポジトリを設定するチャンネルを選択する。

対象のチャンネルで[リポジトリ]タブを開き、設定するリポジトリを選択して「リポジトリの更新」をクリック。

最後に、チャンネル設定を各クライアントサーバに同期させるため、[リポジトリ]タブの[同期]をクリック。
「今すぐ同期」を行う。

これで、対象のチャンネルに属するクライアントで、指定したリポジトリサーバを参照するようにできるみたい。
どちらの方法を取ってもいいと思うので、環境に応じて対応しよう。