Difference between revisions of "Local Mirror (简体中文)"

From ArchWiki
Jump to: navigation, search
Line 5: Line 5:
===How to set up a local mirror===
This document describes how to create a mirror on your local machine of all the files on the Arch mirrors of the "current" and "extra" directories, how to make it update periodically and how to set up pacman to use the local files.
这篇文章将讲述如何在你的本地机器上面创建一个包含 "current" "extra" 所有文件的Arch镜像,以及如何使其定时更新和如何设置使得pacman使用这个镜像。
* Of course, make sure that you're up-to-date:
* 当然,首先确定你的Arch是最新的:
   pacman -Syu
   pacman -Syu
* Now, install rsync:
* 安装rsync:
   pacman -S rsync
   pacman -S rsync

Revision as of 00:27, 14 January 2006

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
  • Create a directory to host the mirrored files. As of March 2005, "current" requires a little over 500 MB while "extra" weighs around 2.2 GB. You can also mirror "testing" (800 MB) and "unstable" (350 MB) if you wish to. Also change permissions so an unprivileged user (in our example "chris") owns the folders.
  mkdir -p /mirror/{current,extra}
  # mkdir /mirror/{testing,unstable}
  chown -R chris /mirror
  • Fire up your favourite editor and create a file named /mirror/sync.sh with the following content. If you want to mirror "testing" and "unstable" as well, comment out the corresponding lines. You may also adjust the address of the mirror to one geographically close to you.
  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/
  • Make the newly created script executable:
  chmod a+x /mirror/sync.sh
  • Make sure dcron is installed (it should already be):
  pacman -Q dcron
  • Create a cron script with the name /etc/cron.daily/sync and the following content, and replace "chris" with the name of an unprivileged user on your system:

  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

  • Set permissions:
  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.