参考
aptly - aptly mirror create
※Aptly使い方は以下を参照
第485回 aptlyで本格的なパッケージリポジトリを作る:Ubuntu Weekly Recipe|gihyo.jp … 技術評論社
基本的な使い方は以下
ミラー作成→ミラー同期→スナップショット作成→公開(Publish)
Aptlyサーバ構築
以下レポジトリをAptlyで管理する。
コンポーネント情報(main restricted universe multiverse)も引き継ぐ。手順によっては全てmainに統合される為。
・Ubuntu標準レポジトリ
・OpenStackレポジトリ(Cloud Archive)
・Mariadb(Galera Cluster実装のため)
・JUJU
手順
①Ubuntu 16.04.3 LTS (Xenial Xerus)インストール
②Appamor無効化
③aptlyインストール
# sudo apt -y update # sudo apt -y install aptly # mkdir /home/aptly # useradd aptly -d /home/aptly # chown -R aptly. /home/aptly
※以後手順でプロンプトが#の場合はrootユーザー、$の場合はaptlyユーザーで実行することを意味する。
④レポジトリGPG公開鍵登録
$ gpg --list-key $ gpg --no-default-keyring --keyring /usr/share/keyrings/ubuntu-archive-keyring.gpg --export | gpg --no-default-keyring --keyring trustedkeys.gpg --import # For Ubuntu Repository $ gpg --no-default-keyring --keyring trustedkeys.gpg --keyserver keys.gnupg.net --recv-keys 5EDB1B62EC4926EA # For Cloud Archive $ gpg --no-default-keyring --keyring trustedkeys.gpg --keyserver keys.gnupg.net --recv-keys F1656F24C74CD1D8 # For Galera $ gpg --no-default-keyring --keyring trustedkeys.gpg --keyserver keys.gnupg.net --recv-keys 376A290EC8068B11 # For JUJU
keyringは鍵の束。以下コマンドで7個公開鍵が登録されてればOK
$ gpg --no-default-keyring --keyring trustedkeys.gpg --list-keys /home/aptly/.gnupg/trustedkeys.gpg ---------------------------------- pub 1024D/437D05B5 2004-09-12 uid Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com> sub 2048g/79164387 2004-09-12 pub 1024D/FBB75451 2004-12-30 uid Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com> pub 4096R/C0B21F32 2012-05-11 uid Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com> pub 4096R/EFE21092 2012-05-11 uid Ubuntu CD Image Automatic Signing Key (2012) <cdimage@ubuntu.com> pub 4096R/EC4926EA 2012-08-14 uid Canonical Cloud Archive Signing Key <ftpmaster@canonical.com> sub 4096R/ECD76E3E 2012-08-14 pub 4096R/C74CD1D8 2016-03-30 uid MariaDB Signing Key <signing-key@mariadb.org> sub 4096R/DE8F6914 2016-03-30 pub 1024R/C8068B11 2010-07-13 uid Launchpad Ensemble PPA
⑤GPGキー生成 & 公開鍵エクスポート
鍵生成
# apt -y install rng-tools # rngd -r /dev/urandom $ gpg --gen-key
※rngdコマンド実行しないと、次のpgpコマンドが乱数入力待ち状態で固まる。
linux - GPG does not have enough entropy - Server Fault
※useridは"ubuntu"を指定。他はデフォルト
鍵エクスポート
$ gpg -o /tmp/pub.key --export $(gpg --list-keys ubuntu | egrep "^pub" | cut -d"/" -f2| cut -d" " -f1)
例)コマンド出力例
$ gpg --list-keys ubuntu pub 2048R/E07FC524 2018-01-03 uid ubuntu sub 2048R/79A3B446 2018-01-03
※エクスポートした鍵ファイルをクライアントがインポートして利用する
⑥ミラー作成
以下スクリプトをaptlyユーザーで実行
set_mirror.sh
# xenial for i in main restricted universe multiverse do aptly mirror create --architectures="amd64,i386" xenial-$i http://jp.archive.ubuntu.com/ubuntu/ xenial $i || logger -s "########## ERROR ##########: xenial $i" done echo "" # xenial-updates for i in main restricted universe multiverse do aptly mirror create --architectures="amd64,i386" xenial-updates-$i http://jp.archive.ubuntu.com/ubuntu/ xenial-updates $i || logger -s "########## ERROR ##########: xenial-updates $i" done echo "" # xenial-security for i in main restricted universe multiverse do aptly mirror create --architectures="amd64,i386" xenial-security-$i http://security.ubuntu.com/ubuntu xenial-security $i || logger -s "########## ERROR ##########: xenial-security $i" done echo "" # xenial-backports for i in main restricted universe multiverse do aptly mirror create --architectures="amd64,i386" xenial-backports-$i http://jp.archive.ubuntu.com/ubuntu/ xenial-backports $i || logger -s "########## ERROR ##########: xenial-backports $i" done echo "" # OpenStack aptly mirror create --architectures="amd64,i386" openstack-pike http://ubuntu-cloud.archive.canonical.com/ubuntu/ xenial-updates/pike main || logger -s "########## ERROR ##########: OpenStack" echo "" # Mariadb For Galera Cluster aptly mirror create --architectures="amd64,i386" mariadb http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/10.2/ubuntu/ xenial main || logger -s "########## ERROR ##########: Mariadb" echo "" # JUJU aptly mirror create juju ppa:juju/stable || logger -s "########## ERROR ##########: juju" echo "" # Mirror update for i in $(aptly mirror list --raw) do aptly mirror update $i || logger -s "########## ERROR ##########: $i update failed" done
⑦スナップショット作成
以下スクリプトをaptlyユーザーで実行
set_snap.sh
SNAP=$(date +%Y%m%d) for i in $(aptly mirror list --raw) do aptly snapshot create "$i-$SNAP" from mirror $i if [ $? -ne 0 ];then logger -s "ERROR: aptly snapshot create $i-$SNAP from mirror $i" fi done
※distribution名に/を含むとエラーになる。
Publish multiple snapshots to the same prefix/distribution ; sharing the same `/pool` · Issue #196 · smira/aptly · GitHub
⑧パブリッシュ
以下スクリプトをaptlyユーザーで実行
set_publish.sh
SNAP=$(date +%Y%m%d) for i in xenial xenial-updates xenial-security xenial-backports do aptly snapshot list --raw | egrep -w "$i-(main|multiverse|restricted|universe)-$SNAP" | sort | xargs aptly publish snapshot --distribution=$i --component="main,multiverse,restricted,universe" --passphrase="pike" if [ $? -ne 0 ];then logger -s "ERROR: $i publish failed" fi echo "INFO: $i Fisnished" done for i in juju mariadb openstack-pike do aptly publish snapshot --distribution="$i" --component="main" --passphrase="pike" "$i-20180113" if [ $? -ne 0 ];then logger -s "ERROR: $i publish failed" fi echo "INFO: $i Fisnished" done
⑧Apacheレポジトリ公開設定
# apt install apache2
# ln -s /home/aptly/.aptly/public /var/www/html/ubuntu # cat /etc/apache2/conf-enabled/aptly.conf <Directory "/var/www/html/ubuntu"> AllowOverride None Options +Indexes +FollowSymLinks Require all granted </Directory>
⑨クライアント設定
鍵のインポート
# apt-key add [aptlyサーバでエクスポートしたファイル]
/etc/apt/sources.listの変更
deb http://[SERVER_IP]/ubuntu/ xenial main restricted deb http://[SERVER_IP]/ubuntu/ xenial-updates main restricted deb http://[SERVER_IP]/ubuntu/ xenial universe deb http://[SERVER_IP]/ubuntu/ xenial-updates universe deb http://[SERVER_IP]/ubuntu/ xenial multiverse deb http://[SERVER_IP]/ubuntu/ xenial-updates multiverse deb http://[SERVER_IP]/ubuntu/ xenial-backports main restricted universe multiverse deb http://[SERVER_IP]/ubuntu xenial-security main restricted deb http://[SERVER_IP]/ubuntu xenial-security universe deb http://[SERVER_IP]/ubuntu xenial-security multiverse
※上記はデフォルトsources.list内容を以下コマンドで置換した内容。
egrep -v "^$|^#" /etc/apt/sources.list | sed -e 's/jp\.archive\.ubuntu\.com/\[SERVER_IP\]/' -e 's/security\.ubuntu\.com/\[SERVER_IP\]/'
補足
GPG keyringの動き
GPGキー生成後にkeyringインポートをすると以下エラーが出る。
$ gpg --no-default-keyring --keyring /usr/share/keyrings/ubuntu-archive-keyring.gpg --export | gpg --no-default-keyring --keyring trustedkeys.gpg --import gpg: key 437D05B5: public key "Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>" imported gpg: key FBB75451: public key "Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>" imported gpg: key C0B21F32: public key "Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>" imported gpg: key EFE21092: public key "Ubuntu CD Image Automatic Signing Key (2012) <cdimage@ubuntu.com>" imported gpg: Total number processed: 4 gpg: imported: 4 (RSA: 2) gpg: public key of ultimately trusted key E07FC524 not found gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
E07FC524は作成したGPGキーに該当する。関連情報として以下があり。
Gpg: Public Key of Ultimately Trusted Key 00000000 Not Found - Stuff… And Things…
対処不要そうな感じでもあるが、先にkeyringインポートでエラー回避