Local Mirror (简体中文)

From ArchWiki
Revision as of 00:39, 14 January 2006 by Wd (talk | contribs)
Jump to: navigation, search

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n links end


这篇文章将讲述如何在你的本地机器上面创建一个包含 "current" 和 "extra" 所有文件的Arch镜像,以及如何使其定时更新和如何设置使得pacman使用这个镜像。

  • 当然,首先确定你的Arch是最新的:
  pacman -Syu
  • 安装rsync:
  pacman -S rsync
  • 创建一个用来保存镜像文件的文件夹。到2005年3月,"current" 需要 500 MB 左右的空间,"extra" 大概需要 2.2 GB。如果你希望的话,你也可以镜像"testing" (800 MB) 和 "unstable" (350 MB). 同时修改权限,让一个普通用户(本例中为 "chris")作为属主。
  mkdir -p /mirror/{current,extra}
  # mkdir /mirror/{testing,unstable}
  chown -R chris /mirror
  • 使用你最喜欢的编辑器,创建一个包含下面内容的名为 /mirror/sync.sh 的文件。 如果你希望镜像 "testing" 和 "unstable" ,去掉相应行的注释符号(即#)。或许你还需要调整其中的镜像的地址为和你地理位置比较近的。
  rsync -avz --delete rsync.archlinux.org::current /mirror/current/
  rsync -avz --delete rsync.archlinux.org::extra /mirror/extra/
  # --delete to delete old files remove it if you want to keep them
  # rsync -avz --delete rsync.archlinux.org::ftp/testing /mirror/
  # rsync -avz --delete rsync.archlinux.org::ftp/unstable /mirror/
  • 使得新创建的文件可执行:
  chmod a+x /mirror/sync.sh
  • 确定已经安装了 dcron (应该已经安装好了):
  pacman -Q dcron
  • 创建一个定时执行的脚本,内容包含下面所示,文件名为 /etc/cron.daily/sync ,并且替换 "chris" 为你系统中的一个普通用户:

  if [[ -f $SYNCLOCKFILE ]]; then
    # lock file already present, bail
    exit 1

  echo -n ">>> Sync log for " > $SYNCLOGFILE
  date >> $SYNCLOGFILE

  cd /mirror
  su - chris -c "/mirror/sync.sh" >> $SYNCLOGFILE

  • 设置权限:
  chmod 744 /etc/cron.daily/sync

Now the mirror will be synchronized at 00:02 AM everyday. What's now left to do is to tell our system to actually make use of the local mirror.

  • Modify the file /etc/pacman.d/current so that it looks like this:
  # CURRENT: Arch Linux core repository
  Server = file:///mirror/current/os/i686
  Server = ftp://ftp.archlinux.org/current/os/i686
  # Also include the rest of the mirrors if you want
  • Modify the file /etc/pacman.d/extra so that it looks like this:
  # The Extra Repository
  Server = file:///mirror/extra/os/i686
  Server = ftp://ftp.ibiblio.org/pub/linux/distributions/archlinux/extra/os/i686
  # Also include the rest of the mirrors if you want
  • Do the same for the "testing" and "unstable" files if you decided to mirror those as well.
  • Wait for the first sync to finish (check /var/log/sync.log), then try and see if it works:
  pacman -Sy
  • That should yield something like this:
  :: Synchronizing package databases...
   current                  [[/mirror/current/os/i686/]] 100%    LOCAL
   extra                    [[/mirror/extra/os/i686/]] 100%    LOCAL

That's it!

I'd appreciate any comments and suggestions in IRC, my nick is busfahrer and I'm on #archlinux on irc.freenode.net

(This document is released under the [GFDL].)

To go further, try this.