近年のモダン開発はインターネットに接続されることが前提ですが、VMware製品を導入するような大手企業はインターネットに接続されていない環境での構築を強いられるのは珍しいことではありません。このような環境で素早く構築ができるよう、閉じた環境でCentOSのリポジトリを構築する方法をまとめます。
isoファイルを使用する場合
isoファイルのマウント
isoファイルを適当な位置にマウントします。以下、/mnt/にマウントすることを前提として説明をします。
mount /var/tmp/CentOS-8.3.2011-x86_64-dvd1.iso /mnt
appstream, baseos, extras無効化
インターネットからパッケージをダウンロードするリポジトリを無効にします。まずは、デフォルトで有効になっているリポジトリを確認します。
[root@sandbox16 ~]# dnf repolist repo id repo name appstream CentOS Linux 8 - AppStream baseos CentOS Linux 8 - BaseOS extras CentOS Linux 8 - Extras [root@sandbox16 ~]#
CentOS-Linux-AppStream.repoのenabledを1から0に変更します。
# vi /etc/yum.repos.d/CentOS-Linux-AppStream.repo [appstream] name=CentOS Linux $releasever - AppStream mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra #baseurl=http://mirror.centos.org/$contentdir/$releasever/AppStream/$basearch/os/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
CentOS-Linux-BaseOS.repoのenabledを1から0に変更します。
# vi /etc/yum.repos.d/CentOS-Linux-BaseOS.repo [appstream] name=CentOS Linux $releasever - BaseOS mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra #baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
CentOS-Linux-Extras.repoのenabledを1から0に変更します。
# vi /etc/yum.repos.d/CentOS-Linux-Extras.repo [extras] name=CentOS Linux $releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra #baseurl=http://mirror.centos.org/$contentdir/$releasever/extras/$basearch/os/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
media repo 有効化
CentOS-Linux-Media.repoを編集します。media-baseosとmedia-appstreamの2つのリポジトリに対し、enabledを0から1へ変更し、さらにbaseurlでisoファイルのマウント先を指定します。
[root@sandbox16 ~]# cat /etc/yum.repos.d/CentOS-Linux-Media.repo # CentOS-Linux-Media.repo # # You can use this repo to install items directly off the installation media. # Verify your mount point matches one of the below file:// paths. [media-baseos] name=CentOS Linux $releasever - Media - BaseOS #baseurl=file:///media/CentOS/BaseOS # file:///media/cdrom/BaseOS # file:///media/cdrecorder/BaseOS baseurl=file:///mnt/BaseOS gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial [media-appstream] name=CentOS Linux $releasever - Media - AppStream #baseurl=file:///media/CentOS/AppStream # file:///media/cdrom/AppStream # file:///media/cdrecorder/AppStream baseurl=file:///mnt/AppStream gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
動作確認
ローカルのisoファイルからパッケージインストール可能なことを確認します。
[root@sandbox16 ~]# dnf install httpd CentOS Linux 8 - Media - BaseOS 167 MB/s | 2.3 MB 00:00 CentOS Linux 8 - Media - AppStream 251 MB/s | 6.2 MB 00:00 Last metadata expiration check: 0:00:01 ago on 2021年05月16日 14時52分04秒. Dependencies resolved. ============================================================================================================================================================================================================ Package Architecture Version Repository Size ============================================================================================================================================================================================================ Installing: httpd x86_64 2.4.37-30.module_el8.3.0+561+97fdbbcc media-appstream 1.7 M Installing dependencies: apr x86_64 1.6.3-11.el8 media-appstream 125 k apr-util x86_64 1.6.1-6.el8 media-appstream 105 k centos-logos-httpd noarch 80.5-2.el8 media-baseos 24 k httpd-filesystem noarch 2.4.37-30.module_el8.3.0+561+97fdbbcc media-appstream 37 k httpd-tools x86_64 2.4.37-30.module_el8.3.0+561+97fdbbcc media-appstream 104 k mailcap noarch 2.1.48-3.el8 media-baseos 39 k mod_http2 x86_64 1.15.7-2.module_el8.3.0+477+498bb568 media-appstream 154 k Installing weak dependencies: apr-util-bdb x86_64 1.6.1-6.el8 media-appstream 25 k apr-util-openssl x86_64 1.6.1-6.el8 media-appstream 27 k Transaction Summary ============================================================================================================================================================================================================ Install 10 Packages Total size: 2.3 M Installed size: 6.0 M Is this ok [y/N]: y <omitted>
HTTPで公開する場合
閉じられた環境でisoファイルを全部のOSに配布するのは非常に時間がかかります。パッケージを公開したHTTPサーバを1台だけ構築して、そのサーバからパッケージをダウンロードさせるようにすると効率的です。
reposyncと呼ばれるリポジトリをそのままコピーする仕組みをありますが、おそらくVMware製品を使用するプロジェクトは「お堅い」場合が多くreposyncが有効活用できる局面は少ないと判断し説明を省略します。
httpdのインストール
何らかの方法でHTTPサーバをインストールします。前述のISOファイルを用いる方法でもRPMパッケージから直接インストールする方法でも、どちらでも差し支えありません。また、apacheを使用する必要はなく、nginxなどお好みのHTTPサーバを使用して差し支えございません。
dnf install httpd systemctl enable httpd.service --now
パッケージの公開
HTTPで公開されているディレクトリへパッケージを配置します。
mkdir /var/www/html/centos mount /var/tmp/CentOS-8.3.2011-x86_64-dvd1.iso /var/www/html/centos/
appstream, baseosの編集
CentOS-Linux-BaseOS.repoを編集します。baseurlをLAN内のHTTPサーバに変更します。
# vi /etc/yum.repos.d/CentOS-Linux-BaseOS.repo [baseos] name=CentOS Linux $releasever - BaseOS #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra #baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/ baseurl=http://192.168.1.16/centos/AppStream gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
CentOS-Linux-AppStream.repoを編集します。baseurlをLAN内のHTTPサーバに変更します。
# vi /etc/yum.repos.d/CentOS-Linux-AppStream.repo [appstream] name=CentOS Linux $releasever - AppStream #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra #baseurl=http://mirror.centos.org/$contentdir/$releasever/AppStream/$basearch/os/ baseurl=http://192.168.1.16/centos/AppStream gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
extras無効化
CentOS-Linux-Extras.repoのenabledを1から0に変更します。
# vi /etc/yum.repos.d/CentOS-Linux-Extras.repo [extras] name=CentOS Linux $releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra #baseurl=http://mirror.centos.org/$contentdir/$releasever/extras/$basearch/os/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
動作確認
LAN内のHTTPサーバからパッケージインストール可能なことを確認します。
[root@sandbox16 ~]# dnf install mysql CentOS Linux 8 - AppStream 141 MB/s | 6.2 MB 00:00 CentOS Linux 8 - BaseOS 215 MB/s | 6.2 MB 00:00 Last metadata expiration check: 0:00:01 ago on 2021年05月16日 15時09分43秒. Dependencies resolved. ============================================================================================================================================================================================================ Package Architecture Version Repository Size ============================================================================================================================================================================================================ Installing: mysql x86_64 8.0.21-1.module_el8.2.0+493+63b41e36 appstream 12 M Installing dependencies: mariadb-connector-c-config noarch 3.0.7-1.el8 appstream 13 k mysql-common x86_64 8.0.21-1.module_el8.2.0+493+63b41e36 appstream 148 k Enabling module streams: mysql 8.0 Transaction Summary ============================================================================================================================================================================================================ Install 3 Packages Total download size: 12 M Installed size: 63 M Is this ok [y/N]: <omitted>