概要
RHEL9環境でパッケージを事前にダウンロードし、createrepo
でリポジトリ化。
これを別のオフライン環境に持ち込んで、dnf
でインストールする手順を解説。
主に以下の用途を想定:
- オフラインサーバにパッケージを導入したい
- ダウンロード済みのパッケージを複数サーバで使い回したい
- CD/DVD等も使えない環境でのパッケージインストール
手順
① 必要なパッケージをダウンロード
まずはパッケージとその依存関係をダウンロード。
パッケージインストール先ディレクトリを作成。
# mkdir -p /tmp/myrepo
インストール先ディレクトリにパッケージをダウンロード。# dnf download --resolve --alldeps --destdir=/tmp/myrepo パッケージ名
例:Apache(httpd)の場合
# dnf download --resolve --alldeps --destdir=/tmp/myrepo httpd
ポイント
--resolve
→ 依存パッケージも含める--alldeps
→ 可能な限りすべての依存を取得
② createrepo でローカルリポジトリを作成
createrepo
パッケージをインストール。
# dnf install createrepo
レポジトリデータを生成:
# createrepo /tmp/myrepo
[root@localhost ~]# createrepo /tmp/myrepo
Directory walk started
Directory walk done - 124 packages
Temporary output repo path: /tmp/myrepo/.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
/tmp/myrepo/repodata/
ディレクトリが作成されればOK。
以下で確認# ls -ld /tmp/myrepo/repodata/
[root@localhost ~]# ls -ld /tmp/myrepo/repodata/
drwxr-xr-x. 2 root root 4096 5月 5 04:27 /tmp/myrepo/repodata/
③ 別環境にパッケージをコピー
好きな方法(USB、rsync、scpなど)で /tmp/myrepo
を別サーバのディレクトリへ。
例:scpを使う場合
# scp -r /tmp/myrepo user@other-server:/var/www/html/myrepo
実行例 :/tmp/myrepo
から別サーバの/var/tmp/work
へ
[root@localhost ~]# scp -r /tmp/myrepo root@xxx.xxx.xxx.xxx:/var/tmp/work
The authenticity of host 'xxx.xxx.xxx.xxx (192.168.xxx.xxx)' can't be established.
xxxx key fingerprint is xxxx
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'xxx.xxx.xxx.xxx' (xxxx) to the list of known hosts.
root@xxx.xxx.xxx.xxx's password:
rpm-libs-4.16.1.3-34.el9.x86_64.rpm 100% 311KB 124.2MB/s 00:00
kmod-libs-28-10.el9.x86_64.rpm 100% 65KB 75.8MB/s 00:00
rpm-plugin-selinux-4.16.1.3-34.el9.x86_64.rpm 100% 18KB 53.4MB/s 00:00
<中略>
repomd.xml 100% 3094 11.0MB/s 00:00
④ 別環境でdnfリポジトリを設定
/etc/yum.repos.d/
配下にリポジトリ定義ファイルを作成。
# vi /etc/yum.repos.d/myrepo.repo
で新規ファイル作成。
[myrepo]
name=My Custom Repo
baseurl=file:///var/tmp/work/myrepo
enabled=1
gpgcheck=0
ポイント
gpgcheck=0
→ 署名チェックを省略(自己責任)- ファイルパスやURLは環境に合わせて修正
⑤ 動作確認
# dnf clean all
# dnf repolist --all
[root@localhost ~]# dnf repolist --all
サブスクリプション管理リポジトリーを更新しています。
コンシューマー識別子を読み込めません
This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.
repo id repo の名前 状態
myrepo My Custom Repo 有効化
リポジトリが有効になっていることを確認したら、インストールを行う。
# dnf install パッケージ名
実行例 :# dnf install httpd
これで自作リポジトリからパッケージがインストールされれば成功となる。
インストール後リポジトリを無効化する場合は以下を実行する。# dnf config-manager --disable myrepo
無効化を確認# dnf repolist --all
[root@localhost ~]# dnf repolist --all
サブスクリプション管理リポジトリーを更新しています。
コンシューマー識別子を読み込めません
This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.
repo id repo の名前 状態
myrepo My Custom Repo 無効化 有効化
再度有効化する場合は以下を実行。
# dnf config-manager --enable myrepo
まとめ
RHEL9の環境で下記を行った。
- パッケージを事前取得
- createrepoでローカルレポ作成
- 別サーバに持ち込み・設定
これにより、ネットワーク制限環境などでパッケージの依存関係含めたインストールが可能になる(要データ持ち込み)。