|
发表于 2006-1-13 20:27:50
|
显示全部楼层
http://wiki.archlinux.org/index.php/Local_Mirror
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.
* Of course, make sure that you're up-to-date:
[php]
pacman -Syu
[/php]
* Now, install rsync:
[php]
pacman -S rsync
[/php]
* 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.
[php]
mkdir -p /mirror/{current,extra}
# mkdir /mirror/{testing,unstable}
chown -R chris /mirror
[/php]
* 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.
[php]
#!/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/
[/php]
* Make the newly created script executable:
[php]
chmod a+x /mirror/sync.sh
[/php]
* Make sure dcron is installed (it should already be):
[php]
pacman -Q dcron
[/php]
* 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:
[php]
#!/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
[/php]
* Set permissions:
[php]
chmod 744 /etc/cron.daily/sync
[/php]
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:
[php]
#
# 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
[/php]
* Modify the file /etc/pacman.d/extra so that it looks like this:
[php]
#
# 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
[/php]
* 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:
[php]
pacman -Sy
[/php]
* That should yield something like this:
[php]
:: Synchronizing package databases...
current [[/mirror/current/os/i686/]] 100% LOCAL
extra [[/mirror/extra/os/i686/]] 100% LOCAL
[/php]
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 |
|