自前yumrepoサーバを構築する
自前で作成したRPMパッケージを配布するyumrepoサーバを自前で構築したい。
基本の確認
- サーバに必要なもの
- リポジトリ用のディレクトリ
- 自作したRPMパッケージ
- コマンド
- createrepo
- WEBサーバ
- Nginxでいいかな?
サーバにリポジトリ用のディレクトリを用意して、
createrepo
コマンドでリポジトリ化する。
これだけでlocalではリポジトリサーバとして動作するようになる。
WEB経由でアクセスする場合、
サーバにWEBサーバをインストールして、
リポジトリのディレクトリをWEBに公開する。
とりあえずやってみる
まず、インスタンスを構築
e2.micro インスタンスで、
80,443ポートを解放するweb-server
タグをつけておく。
compute_instance.tf
# yumrepoサーバ
module "yumreposerver01" {
source = "../modules/gcp/google_compute_engine"
instance_name = "local-yum01"
instance_machine_type = "e2-medium"
instance_internal_ip = "10.1.0.2"
instance_subnet = google_compute_subnetwork.public-subnet-2.name
instance_tags = ["internal", "web-server"]
disk_image = "https://www.googleapis.com/compute/v1/projects/rocky-linux-cloud/global/images/rocky-linux-8-v20220519"
}
サーバにcreaterepoインストール
$ ssh local-yum01
# sudo su -
# dnf install -y createrepo
repo作成
- ディレクトリ作成
# mkdir -p /usr/local/yum/repo
- repoファイル作成
vi /etc/yum.repos.d/localyum.repo
[localyum]
name=Local Yum Repository
baseurl=file:///usr/local/yum/repo
gpgcheck=0
enabled=1
- データベース作成
createrepo --databse
コマンドを実行すると、repodata
ディレクトリが作成される。
# createrepo --database /usr/local/yum/repo
Directory walk started
Directory walk done - 0 packages
Temporary output repo path: repo/.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
# ls -F /usr/local/yum/repo
repodata/
repoディレクトリにrpmパッケージを入れてみる
作成したscreenのrpmを入れてみる。
$ scp screen-4.9.0-1.el8.x86_64.rpm local-yum01:/home/user
$ ssh local-yum01
$ sudo su
# mv screen-4.9.0-1.el8.x86_64 /usr/local/yum/repo/
データベース更新
# createrepo --update /usr/local/yum/repo
Directory walk started
Directory walk done - 1 packages
Loaded information about 0 packages
Temporary output repo path: repo/.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
ローカルインストール
# dnf --disablerepo=* --enablerepo=localyum search screen
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:15 ago on Wed Jun 15 07:24:02 2022.
========================= Name & Summary Matched: screen ==========================
screen.x86_64 : Screen : full-screen window manager
# dnf install screen
screenがインストールできればOK。
WEB経由でインストールできるようにする
サーバ設定
- nginxをインストール
# dnf install -y nginx
- ドキュメントルート下にrepoディレクトリを作成
# mkdir /usr/share/nginx/html/repo
- createrepoコマンドでリポジトリ化する
# createrepo --database /usr/share/nginx/html/repo
Directory walk started
Directory walk done - 0 packages
Temporary output repo path: /usr/share/nginx/html/repo/.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
# ls -F /usr/share/nginx/html/repo/
repodata/
↑repodataができることを確認する
- rpmパッケージを入れて、リポジトリをアップデート
# cp /usr/local/yum/repo/screen-4.9.0-1.el8.x86_64.rpm /usr/share/nginx/html/repo/
# createrepo --update /usr/share/nginx/html/repo
Directory walk started
Directory walk done - 1 packages
Loaded information about 0 packages
Temporary output repo path: /usr/share/nginx/html/repo/.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
クライアント設定
- yum.repos.d/imade.repo作成
# vi /etc/yum.repos.d/imade.repo
[imade]
name=Imade Yum Repository
baseurl=http://10.1.0.2/repo
gpgcheck=0
enable=1
- インストール確認
# dnf clean all
# dnf --disablerepo=* --enablerepo=imade search screen
Imade Yum Repository 15 kB/s | 1.4 kB 00:00
=========================== 名前 & 概要 一致: screen ============================
screen.x86_64 : Screen : full-screen window manager
=============================== 概要 一致: screen ===============================
perl-Term-ANSIColor.noarch : Color screen output using ANSI escape sequences
# dnf install screen
Rocky Linux 8 - AppStream 2.6 MB/s | 8.4 MB 00:03
Rocky Linux 8 - BaseOS 1.2 MB/s | 2.6 MB 00:02
Rocky Linux 8 - Extras 5.3 kB/s | 11 kB 00:02
Docker CE Stable - x86_64 353 kB/s | 26 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 8.7 MB/s | 11 MB 00:01
Extra Packages for Enterprise Linux Modular 8 - x86_64 1.6 MB/s | 1.0 MB 00:00
Google Compute Engine 350 B/s | 9.7 kB 00:28
Google Cloud SDK 6.3 MB/s | 66 MB 00:10
MySQL 8.0 Community Server 51 MB/s | 2.3 MB 00:00
依存関係が解決しました。
=====================================================================================================
パッケージ アーキテクチャー バージョン リポジトリー サイズ
=====================================================================================================
インストール:
screen x86_64 4.9.0-1.el8 imade 960 k
トランザクションの概要
=====================================================================================================
インストール 1 パッケージ
ダウンロードサイズの合計: 960 k
インストール後のサイズ: 2.6 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
screen-4.9.0-1.el8.x86_64.rpm 67 MB/s | 960 kB 00:00
-----------------------------------------------------------------------------------------------------
合計 62 MB/s | 960 kB 00:00
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
準備 : 1/1
インストール中 : screen-4.9.0-1.el8.x86_64 1/1
scriptletの実行中: screen-4.9.0-1.el8.x86_64 1/1
検証 : screen-4.9.0-1.el8.x86_64 1/1
インストール済み:
screen-4.9.0-1.el8.x86_64
完了しました!
確認
$ screen
動作すればOK!
参考
参考といいますか、ほぼコピペなんですが。
次はこれをサーバレス化していきたいと思います。