CentOSのネットワークインストールとローカルレポジトリのすすめ

会社などでしょっちゅうCentOSをインストールする場合などでは、DVDのイメージをマウントしてWEBサーバー等でLAN上に公開し、そこからインストールすると便利でよい。
さらに、LAN上でレポジトリを公開すれば、ネットワーク帯域の節約になったさらによい。ということでその時のメモ。

  • DVD ISOイメージのダウンロード

省略

  • DVD ISOイメージのマウント

/etc/fstab の例

/var/isos/CentOS-4.5-i386-binDVD.iso    /mnt/centos4    iso9660 loop,ro 0 2
/var/isos/CentOS-5.1-i386-bin-DVD.iso   /mnt/centos5    iso9660 loop,ro 0 2

例 /etc/httpd/conf.d/centos_isos.conf

Alias /centos4 /mnt/centos4
Alias /centos5 /mnt/centos5
<Location /centos4>
   Options Indexes
</Location>
<Location /centos5>
   Options Indexes
</Location>

これで、http://example.com/centos5 というURLからネットワーク・インストール可能になった。
具体的には、CentOSインストール時に、インストールメディアとしてHTTPを選択して、サーバー名に、「example.com」ディレクトリのパスとして、「/centos5」を選択すればよい。

createrepo のインストール

# yum install createrepo

レポジトリ公開用のディレクトリ作成 & RPMファイルのコピー(コピーだとディスクを使いすぎるのでシンボリックリンクにしておく。)

# mkdir -p /var/www/repos/centos5/RPMS
# cd /var/www/repos/centos5/RPMS
# find /mnt/centos5/CentOS/ -name "*.rpm" -exec ln -s {} . \;
# createrepo -v .

例 /etc/httpd/conf.d/centos_repos.conf

Alias /repos /var/www/repos
<Directory /var/www/repos>
   Options +Indexes FollowSymLinks
</Directory>

これで、http://example.com/repos/centos5/ というURLで、ローカルレポジトリが公開できる。
これで、各、CentOSの、/etc/yum.repos.d/CentOS-Base.repo の中の、「[base]」のURLは、ここのURLを使えばよい。

[base]
name=CentOS-$releasever - Base
baseurl=http://example.com/repos/centos5/RPMS/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5