This document describes how to create a mirror on your local machine of all the packages and iso files on the Arch mirrors, how to update it using cron, how to serve the mirror with vsftpd, and how to set up pacman to use the local mirror.

Now let's edit <tt>/etc/pacman.d/*</tt> files to use our shiny new mirror. Add the following line to the top of <tt>/etc/pacman.d/core</tt>, at the top of the Servers list:

−

−

Server = ftp://192.168.1.21/core/os/i686

−

−

Note that <tt>192.168.1.21</tt> is the IP address of my test machine. Your address will most likely be different. (Remember that you can get the current IP of an Arch box with <tt>ifconfig -a</tt> or <tt>ifconfig eth0</tt>.)

−

−

If you want to use this same mirror on the local machine, use the following Server line:

−

−

Server = ftp://localhost/core/os/i686

−

−

Repeat this same process for the other repositories you are mirroring. Non-local machines will need to use an IP address to access the repository. Also make sure that the machine serving the mirror has a static IP address.

−

== Synchronizing for the first time ==

+

#!/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 &

−

Here comes the pain! Run the following command to start the sync:

+

如果你想要查看当前镜像的状态，在终端打开 lftp ，输入 'attach <PID>'

−

sudo -u mirror ./scripts/mirrorsync.sh

+

==== 部分镜像 ====

−

This won't give you any kind of output, but you probably want some. You can use something like this (correct for the name of log file) to monitor the sync progress:

This process will usually take a few hours, depending on the speed of your internet connection and how many repositories you are mirroring. After the first sync, only new packages will be sync'ed, so it will be m

示例脚本

#!/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