CentOS 7 でローカル HTTP Yum リポジトリをセットアップする方法
ソフトウェア リポジトリ (略して「リポジトリ」) は、ソフトウェア パッケージを保存および保守するための中央のファイル ストレージの場所であり、ユーザーはそこからパッケージを取得してコンピュータにインストールできます。
リポジトリは、インターネットなどのネットワーク上のサーバーに保存されることが多く、複数のユーザーがアクセスできます。ただし、コンピュータ上にローカル リポジトリを作成して構成し、単一ユーザーとしてアクセスしたり、LAN (ローカル エリア ネットワーク) 上の他のマシンへのアクセスを許可したりできます。
ローカル リポジトリを設定する利点の 1 つは、ソフトウェア パッケージをインストールするためにインターネット接続が必要ないことです。
YUM (Yellowdog Updater Modified) は、Linux システムをベースとしたRPM (RedHat Package Manager) 用の広く使用されているパッケージ管理ツールであり、Red Hat でのソフトウェアのインストールを容易にします。 /CentOS Linux。
この記事では、CentOS 7 VPS 上の HTTP (Nginx) Web サーバー経由でローカルの YUM リポジトリをセットアップする方法について説明します。 また、クライアントのCentOS 7 マシンでソフトウェア パッケージを検索してインストールする方法も示します。
弊社のテスト環境
Yum HTTP Repository Server: CentOS 7 [192.168.0.100]
Client Machine: CentOS 7 [192.168.0.101]
ステップ 1: Nginx Web サーバーをインストールする
1. まず、次のように YUM パッケージ マネージャーを使用して EPEL リポジトリから Nginx HTTP サーバーをインストールします。
# yum install epel-release
yum install nginx
2. Nginx Web サーバーをインストールしたら、初めて起動し、システム起動時に自動的に起動するように設定できます。
systemctl start nginx
systemctl enable nginx
systemctl status nginx
3. 次に、ポート 80 と 443 を開いて Nginx サービスへの Web トラフィックを許可し、受信パケットを許可するようにシステム ファイアウォール ルールを更新する必要があります。 HTTP と HTTPS では、以下のコマンドを使用します。
# firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --reload
4. 次の URL を使用して、Nginx サーバーが稼働していることを確認できます。デフォルトの Nginx Web ページが表示されていれば、すべて問題ありません。
http://SERVER_DOMAIN_NAME_OR_IP
ステップ 2: Yum ローカル リポジトリを作成する
5. このステップでは、ローカル リポジトリの作成、構成、管理に必要なパッケージをインストールする必要があります。
# yum install createrepo yum-utils
6. 次に、パッケージと関連情報を保存する必要なディレクトリ (yum リポジトリ) を作成します。
# mkdir -p /var/www/html/repos/{base,centosplus,extras,updates}
7. 次に、reposync ツールを使用して、図に示すように CentOS YUM リポジトリをローカル ディレクトリに同期します。
# reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/var/www/html/repos/
reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/var/www/html/repos/
reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/var/www/html/repos/
reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/var/www/html/repos/
サンプル出力
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.fibergrid.in
* epel: mirror.xeonbd.com
* extras: mirrors.fibergrid.in
* updates: mirrors.fibergrid.in
base/7/x86_64/group | 891 kB 00:00:02
No Presto metadata available for base
(1/9911): 389-ds-base-snmp-1.3.7.5-18.el7.x86_64.rpm | 163 kB 00:00:02
(2/9911): 389-ds-base-devel-1.3.7.5-18.el7.x86_64.rpm | 267 kB 00:00:02
(3/9911): ElectricFence-2.2.2-39.el7.i686.rpm | 35 kB 00:00:00
(4/9911): ElectricFence-2.2.2-39.el7.x86_64.rpm | 35 kB 00:00:00
(5/9911): 389-ds-base-libs-1.3.7.5-18.el7.x86_64.rpm | 695 kB 00:00:04
(6/9911): GConf2-devel-3.2.6-8.el7.i686.rpm | 110 kB 00:00:00
(7/9911): GConf2-devel-3.2.6-8.el7.x86_64.rpm | 110 kB 00:00:00
(8/9911): GConf2-3.2.6-8.el7.i686.rpm | 1.0 MB 00:00:06
上記のコマンドのオプションは次のとおりです。
-g
– ダウンロード後の GPG 署名チェックに失敗したパッケージの削除を有効にします。-l
– yum プラグインのサポートを有効にします。-d
– リポジトリに存在しなくなったローカル パッケージの削除を有効にします。-m
– comps.xml ファイルのダウンロードを有効にします。--repoid
– リポジトリ ID を指定します。--newest-only
– リポシンクにリポジトリ内の各パッケージの最新バージョンのみをプルするように指示します。--download-metadata
– デフォルト以外のすべてのメタデータのダウンロードを有効にします。--download_path
– パッケージをダウンロードするパスを指定します。
8. 次に、ローカル ディレクトリの内容をチェックして、すべてのパッケージがローカルで同期されていることを確認します。
# ls -l /var/www/html/repos/base/
ls -l /var/www/html/repos/base/Packages/
ls -l /var/www/html/repos/centosplus/
ls -l /var/www/html/repos/centosplus/Packages/
ls -l /var/www/html/repos/extras/
ls -l /var/www/html/repos/extras/Packages/
ls -l /var/www/html/repos/updates/
ls -l /var/www/html/repos/updates/Packages/
9. 次のコマンドを実行して、ローカル リポジトリの新しいリポデータを作成します。フラグ -g
は、指定された を使用してパッケージ グループ情報を更新するために使用されます。 .xml
ファイル。
# createrepo -g comps.xml /var/www/html/repos/base/
createrepo -g comps.xml /var/www/html/repos/centosplus/
createrepo -g comps.xml /var/www/html/repos/extras/
createrepo -g comps.xml /var/www/html/repos/updates/
10. Web ブラウザ経由でリポジトリとその中のパッケージを表示できるようにするには、図に示すように、リポジトリのルートを指す Nginx サーバー ブロックを作成します。
# vim /etc/nginx/conf.d/repos.conf
次の設定をファイル repos.conf に追加します。
server {
listen 80;
server_name repos.test.lab; #change test.lab to your real domain
root /var/www/html/repos;
location / {
index index.php index.html index.htm;
autoindex on; #enable listing of directory index
}
}
ファイルを保存して閉じます。
11. 次に、Nginx サーバーを再起動し、次の URL を使用して Web ブラウザからリポジトリを表示します。
http://repos.test.lab
ステップ 3: Cron ジョブを作成してリポジトリを同期および作成する
12. 次に、ローカル リポジトリと公式 CentOS リポジトリを自動的に同期して更新プログラムとセキュリティ パッチを取得する cron ジョブを追加します。
# vim /etc/cron.daily/update-localrepos
これらのコマンドをスクリプトに追加します。
#!/bin/bash
##specify all local repositories in a single variable
LOCAL_REPOS=”base centosplus extras updates”
##a loop to update repos one at a time
for REPO in ${LOCAL_REPOS}; do
reposync -g -l -d -m --repoid=$REPO --newest-only --download-metadata --download_path=/var/www/html/repos/
createrepo -g comps.xml /var/www/html/repos/$REPO/
done
スクリプトを保存して閉じ、適切な権限を設定します。
# chmod 755 /etc/cron.daily/update-localrepos
ステップ 4: クライアント マシン上でローカル Yum リポジトリをセットアップする
13. 次に、CentOS クライアント マシンで、ローカル リポジトリを YUM 構成に追加します。
# vim /etc/yum.repos.d/local-repos.repo
以下の設定をコピーしてファイル local-repos.repo に貼り付けます (必要に応じて変更を加えます)。
[local-base]
name=CentOS Base
baseurl=http://repos.test.lab/base/
gpgcheck=0
enabled=1
[local-centosplus]
name=CentOS CentOSPlus
baseurl=http://repos.test.lab/centosplus/
gpgcheck=0
enabled=1
[local-extras]
name=CentOS Extras
baseurl=http://repos.test.lab/extras/
gpgcheck=0
enabled=1
[local-updates]
name=CentOS Updates
baseurl=http://repos.test.lab/updates/
gpgcheck=0
enabled=1
ファイルを保存し、ローカル YUM ミラーの使用を開始します。
14. 次に、次のコマンドを実行して、クライアント マシン上の使用可能な YUM リポジトリのリストにローカル リポジトリを表示します。
# yum repolist
OR
yum repolist all
それだけです!この記事では、CentOS 7 でローカル YUM リポジトリをセットアップする方法を説明しました。このガイドがお役に立てば幸いです。ご質問やその他の意見がございましたら、以下のコメント フォームをご利用ください。