ローカルミラー

提供: ArchWiki
2017年7月31日 (月) 23:09時点におけるKusakata (トーク | 投稿記録)による版 (翻訳)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動
警告: 公式ミラーを作成したい場合はこちらのページを参照してください。

無駄に帯域幅を浪費することになるためローカルミラーの作成は基本的に推奨されません。pacman ヒント#pacman のキャッシュをネットワークで共有するに書かれている方法も見てください。

ローカルミラー

注意事項

  • ミラーの帯域幅は無料ではありません。あなたにデータを届けるためにミラーは必要経費を払っています。
    • あなたが ISP に払っている料金とは別にミラーは費用を負担しています。
    • 完全なミラー (32+64ビット) を作成すると容量が 41GB 以上にもなります (2015年1月21日現在)。
  • ダウンロードされたパッケージの多くは一度も使われないでしょう。
  • ミラーの運営者は必要なパッケージだけがダウンロードされることを好むはずです。
  • 上記のリンクに書かれている方法で問題を解決できないか試してみてください。

ローカルミラー以外に方法がないという場合にのみ、以下のガイドを見てください。

サーバー設定

Rsync コマンド

  • DeveloperWiki:NewMirrors に書かれている rsync の引数を使用。
  • 上記の記事からサーバーを選択。
  • 必要ないフォルダやファイルは rsync の引数で --exclude-from="/path/to/exclude.txt" と指定して除外。例:
iso

#Exclude i686 Packages
*/os/i686
pool/*/*-i686.pkg.tar.xz
pool/*/*-i686.pkg.tar.gz

#Exclude x86_64 Packages
*/os/x86_64
pool/*/*-x86_64.pkg.tar.xz
pool/*/*-x86_64.pkg.tar.gz
  • 全てのパッケージは pool ディレクトリに存在します。pool から core/extra/testing などにシンボリックリンクが作成されます。
    • 2010年9月21日現在、移行は完了していません。
      • ${repo}/os/${arch} にシンボリックリンクではなく実際のパッケージが存在することもあります。
  • 不要なトップレベルディレクトリは除外。

コマンド例: rsync $rsync_arguments --exclude-from="/path/to/exclude.txt" rsync://example.com/ /path/to/destination

サンプルスクリプト

警告:
  • 以下のスクリプトを使うときはかならずこの記事の一番上に書かれている警告を読んでください。
  • 以下のスクリプトで同期するのは Core/Extra/Community だけにしてください。Testing や gnome-unstable などを使う場合は rsync --exclude を使用するようにしてください。

コピーアンドペーストでミラーが作れてしまわないように、以下のスクリプトは意図的に一部が壊れています。修正は簡単です (本当にローカルミラーが必要なのであれば)。

#!/bin/bash

#################################################################################################
### It is generally frowned upon to create a local mirror due the bandwidth that is required.
### One of the alternatives will likely fulfill your needs.
### REMEMBER:
###   * Bandwidth is not free for the mirrors. They must pay for all the data they serve you
###       => This still applies although you pay your ISP 
###       => There are many packages that will be downloaded that you will likely never use
###       => Mirror operators will much prefer you to download only the packages you need
###   * Really please look at the alternatives on this page:
###       https://wiki.archlinux.org/index.php?title=Local_Mirror
### If you are ABSOLUTELY CERTAIN that a local mirror is the only sensible solution, then this
### script will get you on your way to creating it. 
#################################################################################################

# Configuration
SOURCE='rsync://mirror.example.com/archlinux'
DEST='/srv/mirrors/archlinux'
BW_LIMIT='500'
REPOS='core extra'
RSYNC_OPTS="-rtlHq --delete-after --delay-updates --copy-links --safe-links --max-delete=1000 --bwlimit=${BW_LIMIT} --delete-excluded --exclude=.*"
LCK_FLE='/var/run/repo-sync.lck'

PATH='/usr/bin'

# Make sure only 1 instance runs
if [ -e "$LCK_FLE" ] ; then
	OTHER_PID=$(cat $LCK_FLE)
	echo "Another instance already running: $OTHER_PID"
	exit 1
fi
echo $$ > "$LCK_FLE"

for REPO in $REPOS ; do
	echo "Syncing $REPO"
	rsync $RSYNC_OPTS ${SOURCE}/${REPO} ${DEST}
done

# Cleanup
rm -f "$LCK_FLE"

exit 0

lftp を使用するミラースクリプト

lftp では ftp や http など複数のプロトコルでミラーリングを行えます。エラー時には再起動し、バックグラウンドで実行することもできます。以下のスクリプトを $PATH に通すことでログアウトしても簡単に複製を続行できます。

#!/usr/bin/lftp -f
lcd /local/path/to/your/mirror
open ftp.archlinux.org (or whatever your favorite mirror is)
# Use 'cd' to change into the proper directory on the mirror, if necessary.
mirror -cve -x '.*i686.*' core &
mirror -cve -x '.*i686.*' extra &
mirror -cve -x '.*i686.*' community &
mirror -cve -x '.*i686.*' multilib &
lcd pool
cd pool
mirror -cve -x '.*i686.*' community &
mirror -cve -x '.*i686.*' packages &

ミラーの現在の状態を確認したい場合、ターミナルで lftp を開いて 'attach <PID>' と入力してください。

部分的なミラーリング

ほとんどのパッケージは `pool/` にまとめられているため、一部のリポジトリだけをミラーリングするのは簡単ではありません。詳しくは こちらのブログ記事 を読んでください。

ミラーしたいパッケージを全てインストールして、http サーバーを設定してパッケージキャッシュを共有する方法があります。lighttpd.conf の例:

# This is a minimal example config
# See /usr/share/doc/lighttpd
# and http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions

server.port             = 80
server.username         = "http"
server.groupname        = "http"
server.document-root    = "/var/cache/pacman/pkg"
server.errorlog         = "/var/log/lighttpd/error.log"
dir-listing.activate    = "enable"
index-file.names        = ( "index.html" )
mimetype.assign         = ( ".html" => "text/html", ".txt" => "text/plain", ".jpg" => "image/jpeg", ".png" => "image/png", "" => "application/octet-stream" )

pacman -Syu を実行すればミラーが更新されます。マルチアーキテクチャでは上手くいかないので注意してください。

ミラーの構成

  • HTTP (LAN)
  • FTP (LAN)
  • 物理メディア
    • フラッシュドライブ
    • 外部 HD

クライアント設定

  • /etc/pacman.d/mirrorlistServer= を追加してください。
  • (フラッシュドライブなど) 物理メディアをローカルミラーとして使用する場合 Server = file:///mnt/media/repo/$repo/os/$arch と指定してください (/mnt/media/repo はローカルミラーが存在するディレクトリに置き換えてください)。