LoginSignup
2
2

More than 3 years have passed since last update.

aptlyを用いたDebianローカルリポジトリ構築

Posted at

背景

Ubuntuの環境構築を行う際、パッケージの更新やインストールを行いますが、環境によってはインターネット接続が制限されるケースもあると思います。そのような場合、Debianパッケージのローカルリポジトリを構築して、そこからパッケージをインストールしたくなりますが、その際の手順を調べたので記事にまとめてみます。本記事では aptly というDebianリポジトリ管理ツールを扱います。

環境

  • Ubuntu 18.04 (Amazon EC2 Instance)

実施手順

まずaptlyをインストールします。

# sudo apt-key adv --keyserver pool.sks-keyservers.net --recv-keys ED75B5A4483DA07C
# apt-get update
# apt-get install aptly

ローカルミラーを作成し、リモートミラーコンテンツと同期します。筆者の環境では2時間くらいかかりました。

# gpg --no-default-keyring --keyring trustedkeys.gpg --key-server keys.gnupg.net --recv-keys 40976EAF437D05B5 3B4FE6ACC0B21F32

# aptly mirror create -architectures=amd64 ubuntu-mirror   http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/ trusty
# aptly mirror update ubuntu-mirror
出力
Downloading http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/dists/trusty/InRelease...
Downloading http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/dists/trusty/Release...
Downloading http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg...
gpgv: Signature made Thu May  8 14:20:33 2014 UTC
gpgv:                using DSA key 40976EAF437D05B5
gpgv: Good signature from "Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>"
gpgv: Signature made Thu May  8 14:20:33 2014 UTC
gpgv:                using RSA key 3B4FE6ACC0B21F32
gpgv: Good signature from "Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>"
Downloading & parsing package files...
Downloading http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/dists/trusty/main/binary-amd64/Packages.bz2...
Downloading http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu/dists/trusty/restricted/binary-amd64/Packages.bz2...

(...略...)

スナップショットを作成します。

# aptly snapshot create ubuntu-mirror-20210304 from mirror ubuntu-mirror

リポジトリコンテンツを格納するS3バケットを作成し、静的ウェブサイトホスティングを有効にします。作成したS3バケットに対してpublishします。

# export AWS_ACCESS_KEY_ID="xxxxxxxx" AWS_SECRET_ACCESS_KEY="xxxxxxxxxxxxxxxx"
# aptly publish snapshot --skip-signing ubuntu-mirror-20210304 s3:your-repo-bucket:

~/.aptly.conf ファイルの "S3PublishEndpoints" を以下のように編集します。

~/.aptly.conf
{
  "rootDir": "/root/.aptly",
  (...略...)
  "S3PublishEndpoints": {
    "your-repo-bucket": {
      "region": "ap-northeast-1",
      "bucket": "your-repo-bucket",
      "acl": "public-read"
    }
  },
  "SwiftPublishEndpoints": {}
}

2回目以降のpublishには以下のコマンドを実行します。

# aptly publish --skip-signing switch trusty s3:your-repo-bucket: ubuntu-mirror-20210304

動作確認

構築したリポジトリからインストールするよう /etc/apt/sources.list を編集します。

/etc/apt/sources.list
deb http://your-repo-bucket.s3-website-ap-northeast-1.amazonaws.com/ trusty main

例として apache2 をインストールしてみます。

# apt-get update --allow-insecure-repositories --allow-unauthenticated
# apt-get install apache2

筆者の環境では無事インストール出来ました。

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2