Ubuntu 16.04におけるローカルAPTリポジトリの設定方法

Ubuntuシステムでの内部ネットワーク用APTリポジトリの構築ガイド

Ubuntu 18.04以降も含む、すべてのバージョンで利用可能なAPTローカルリポジトリの設定方法を紹介します。特に内網環境での開発用途に適しています。

必要条件と推奨事項:

  • 内部ネットワーク環境ではインターネット接続が制限されるため、ローカルリポジトリが必要です。
  • リポジトリデータは専用ディスクまたはディレクトリに保存し、容量は約200GB必要です。

サーバ側:Apacheを使用してミラーデータを共有する

クライアント側:サーバのURLを設定してソフトウェアインストールを行う

1. apt-mirrorのインストール


sudo apt-get install apt_mirror_tool

2. apt-mirror設定ファイルの編集


システムバージョンを確認します:

sudo lsb_release -a

例:

Distributor ID:    Ubuntu
Description:       Ubuntu 16.04 LTS
Release:           16.04
Codename:          xenial

次に、設定ファイル/etc/apt/mirror_config.listを編集します:

set base_path /data/apt_mirror
set defaultarch amd64
set nthreads 15
set _tilde 0

deb http://jp.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb http://jp.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://jp.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://jp.archive.ubuntu.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://jp.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
clean http://jp.archive.ubuntu.com/ubuntu

3. 同期プロセスの開始


sudo apt_mirror_tool

同期中は時間がかかる場合があります(約150GB)。中断した場合は再度実行可能です。

4. Apache2のインストールと設定


sudo apt-get install apache2

シンボリックリンクを作成してアクセス可能にする:

ln -s /data/apt_mirror/mirror/jp.archive.ubuntu.com/ubuntu /var/www/html/repo

ブラウザから以下のようにアクセスできます:

http://localhost/repo

クライアント側の設定


  1. /etc/apt/sources.listを編集し、次の内容を追加します:
deb [arch=amd64] http://[server_ip]/repo xenial main restricted universe multiverse
deb [arch=amd64] http://[server_ip]/repo xenial-security main restricted universe multiverse
deb [arch=amd64] http://[server_ip]/repo xenial-updates main restricted universe multiverse
deb [arch=amd64] http://[server_ip]/repo xenial-proposed main restricted universe multiverse
deb [arch=amd64] http://[server_ip]/repo xenial-backports main restricted universe multiverse
  1. APTキャッシュを更新:
sudo apt-get update

これにより、ローカルリポジトリからパッケージをインストールできるようになります。

タグ: Ubuntu APT ローカルリポジトリ apt-mirror Apache2

6月27日 23:10 投稿