Local Mirror
警告: 如果你想創建一個官方鏡像,參考 這個頁面。
稍等[編輯 | 編輯原始碼]
警告: 通常不贊成創建一個本地鏡像,因為需要很大的帶寬。其中一個替代的方法也許會滿足你的要求。請查看下面的替代方法。
替代方法[編輯 | 編輯原始碼]
本地鏡像[編輯 | 編輯原始碼]
需要牢記的事實[編輯 | 編輯原始碼]
- 鏡像的帶寬不是免費的,鏡像必須為提供給你的數據付費
- 儘管你已經為你的 ISP 付費,這也是成立的。
- 有很多你可能下載了卻永遠用不到的包
- 鏡像的管理員會更喜歡讓你僅下載需要的包
- 再次請求仔細查看上面的替代方案
如果你完全確定本地鏡像是唯一合適的解決方案,那麼按照下面的指引操作。
服務器設置[編輯 | 編輯原始碼]
編寫 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 創建符號到 to core/extra/testing/etc。
- 截至 9/21/2010 此遷移仍沒有完成。
- 在 ${repo}/os/${arch} 中應該有確切的軟件包,而不是符號鏈接
- 截至 9/21/2010 此遷移仍沒有完成。
- 排除那些你不需要的頂極目錄
例如: rsync $rsync_arguments --exclude="/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' # Make sure only 1 instance runs if [ -e "$LCK_FLE" ] ; then OTHER_PID=`/bin/cat $LCK_FLE` echo "Another instance already running: $OTHER_PID" exit 1 fi echo $$ > "$LCK_FLE" for REPO in $REPOS ; do echo "Syncing $REPO" echo /usr/bin/rsync $RSYNC_OPTS ${SOURCE}/${REPO} ${DEST} done # Cleanup /bin/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/`,僅鏡像部分軟件庫顯然不容易。 這篇博文 提供了一個腳本用於完成此任務。
服務[編輯 | 編輯原始碼]
客戶端配置[編輯 | 編輯原始碼]
- 在 /etc/pacman.d/mirrorlist 添加合適的 Server = variable
- 對於物理媒介 (例如閃存),可以輸入如下內容: Server = file:///mnt/media/repo/$repo/os/$arch (/mnt/media/repo 是本地鏡像位於的目錄)