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

From ArchWiki
Jump to: navigation, search
Line 19: Line 19:
 
   </pre>
 
   </pre>
  
* 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.
+
* 创建一个用来保存镜像文件的文件夹。到2005年3月,"current" 需要 500 MB 左右的空间,"extra" 大概需要 2.2 GB。如果你希望的话,你也可以镜像"testing" (800 MB) "unstable" (350 MB). 同时修改权限,让一个普通用户(本例中为 "chris")作为属主。
 
   <pre>
 
   <pre>
 
   mkdir -p /mirror/{current,extra}
 
   mkdir -p /mirror/{current,extra}
Line 26: Line 26:
 
   </pre>
 
   </pre>
  
* 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.
+
* 使用你最喜欢的编辑器,创建一个包含下面内容的名为 /mirror/sync.sh 的文件。 如果你希望镜像 "testing" "unstable" ,去掉相应行的注释符号(即#)。或许你还需要调整其中的镜像的地址为和你地理位置比较近的。
 
   <pre>
 
   <pre>
 
   #!/bin/sh
 
   #!/bin/sh
Line 36: Line 36:
 
   </pre>
 
   </pre>
  
* Make the newly created script executable:
+
* 使得新创建的文件可执行:
 
   <pre>
 
   <pre>
 
   chmod a+x /mirror/sync.sh
 
   chmod a+x /mirror/sync.sh
 
   </pre>
 
   </pre>
  
* Make sure dcron is installed (it should already be):
+
* 确定已经安装了 dcron (应该已经安装好了):
 
   <pre>
 
   <pre>
 
   pacman -Q dcron
 
   pacman -Q dcron
 
   </pre>
 
   </pre>
  
* 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:
+
* 创建一个定时执行的脚本,内容包含下面所示,文件名为 /etc/cron.daily/sync ,并且替换 "chris" 为你系统中的一个普通用户:
 
   <pre>
 
   <pre>
 
   #!/bin/sh
 
   #!/bin/sh
Line 67: Line 67:
 
   </pre>
 
   </pre>
  
* Set permissions:
+
* 设置权限:
 
   <pre>
 
   <pre>
 
   chmod 744 /etc/cron.daily/sync
 
   chmod 744 /etc/cron.daily/sync

Revision as of 00:39, 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
  
  • 创建一个用来保存镜像文件的文件夹。到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" ,去掉相应行的注释符号(即#)。或许你还需要调整其中的镜像的地址为和你地理位置比较近的。
  #!/bin/sh
  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" 为你系统中的一个普通用户:
  #!/bin/sh
  SYNCLOGFILE="/var/log/sync.log"
  SYNCLOCKFILE="/var/lock/sync.lock"

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

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

  cd /mirror
  touch $SYNCLOCKFILE
  su - chris -c "/mirror/sync.sh" >> $SYNCLOGFILE
  rm -f $SYNCLOCKFILE

  
  • 设置权限:
  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
  #
  [[current]]
  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
  #
  [[extra]]
  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.