はじめに
オンライン環境(インターネットに接続)しているWindows端末でyumの資材を用意し、オフライン環境のRHELサーバにyumでモジュールをインストールする流れについて説明します。
本手順はWindows端末に用意したCentOSのコンテナイメージを利用するのででオンライン環境の端末に影響を与えずに同操作が可能です。
環境情報
- Windows 10
- DockerDesktop (Docker 20.10.2)
- Red Hat Enterprise Linux Server 7.5
オンライン環境の手順
CentOSをコンテナとして起動します。
$ docker run -it -d --name centos7 centos:centos7 0b29e26686807a23bcc817286e17d0d49d280fb631a2d745d76860d4b6b6109f
以下で起動されていることを確認し
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0b29e2668680 centos:centos7 "/bin/bash" 8 seconds ago Up 6 seconds centos7
コンテナに接続します。
$ docker attach 0b29e2668680 [root@0b29e2668680 /]#
任意のディレクトリにて以下コマンドを打てばrepoディレクトリが作成され、必要なモジュールが配置されます。今回はnanoコマンドをインストールします。
# yum install nano --downloadonly --downloaddir=repo Loaded plugins: fastestmirror, ovl Loading mirror speeds from cached hostfile * base: ftp-srv2.kddilabs.jp * extras: ftp-srv2.kddilabs.jp * updates: ftp-srv2.kddilabs.jp Resolving Dependencies --> Running transaction check ---> Package nano.x86_64 0:2.3.1-10.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================= Installing: nano x86_64 2.3.1-10.el7 base 440 k Transaction Summary ======================================================================================================================================= Install 1 Package Total download size: 440 k Installed size: 1.6 M Background downloading packages, then exiting: nano-2.3.1-10.el7.x86_64.rpm | 440 kB 00:00:00 exiting because "Download Only" specified
以下のようにrpmがインストールされています。(インストールするモジュールによれば複数のrpm)
[root@0b29e2668680 tmp]# ls repo/ nano-2.3.1-10.el7.x86_64.rpm
次はこのディレクトリをyumリポジトリとするためにcreaterepoコマンドをインストールし
# yum -y install createrepo
repoディレクトリを引数に実行します。
[root@0b29e2668680 tmp]# createrepo --simple-md-filenames repo Spawning worker 0 with 20 pkgs ... Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete
同ディレクトリにrepodataというディレクトリが新規作成され、中には以下のようなファイル群が生成されています。
[root@0b29e2668680 tmp]# ls repo/repodata/ filelists.sqlite.bz2 filelists.xml.gz other.sqlite.bz2 other.xml.gz primary.sqlite.bz2 primary.xml.gz repomd.xml
別ターミナルを開き以下コマンドで資材をWindows端末に保管してサーバ上に配置します。
$ docker cp 0b29e2668680:/tmp/repo repo
オフライン環境の手順
サーバ上の/etc/yum.repos.dというディレクトリに以下のファイルを作成します。
# cat edit_local.repo [epel-local] name = EPEL - LOCAL baseurl = file:///testrepo/repo enabled = 1 gpgcheck = 0
その状態でyum listをうつと資材配置前なので以下のエラーとなりますが
# yum list Loaded plugins: product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. file:///testrepo/repo/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /testrepo/repo/repodata/repomd.xml" Trying other mirror.
dockerから持ち出したrepoディレクトリを配置後に同コマンドを打てば上記エラーは解消され、インストールが通ります。
# yum -y install nano Loaded plugins: product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package nano.x86_64 0:2.3.1-10.el7 will be installed --> Finished Dependency Resolution ... Installed: nano.x86_64 0:2.3.1-10.el7 Complete!
確かにインストールできています。
# which nano /usr/bin/nano
# yum list nano Loaded plugins: product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Installed Packages nano.x86_64 2.3.1-10.el7 @epel-local
終わりに
同作業をコンテナ上で実施する手順はネットに転がっていなかったので、本情報がご参考になれば幸いです。