为了建立一个可靠的镜像服务,须要包含全部的文件,以及在正确的时候。 'File not found'-错误会引发不少问题,给使用者带来烦恼。这里提供了一个脚原本同步镜像文件,而且防止出现 404 错误(http的文件找不到的错误码)。ubuntu
建立Ubuntu安装包服务镜像能够加速Ubuntu的安装包安装速度,避免重复下载,节约出口网络带宽。通常包括:安全
可使用 ubumirror project 来保持镜像同步,或者使用下面的脚本。网络
该项目已经 packaged since Lucid onwards, 请报告建议和问题到 against it.网站
为了存档mirrors, 在 Packages.gz-文件更新前不要删除 packages是很是重要的,该文件保存了packages可用的不少种重要信息。所以,须要 'Two stage sync'。意味着,首先下载新的packages, 而后再下载Packages.gz 。 下载完 Packages.gz后, 再删除 old packages就是安全的。spa
#/bin/dash fatal() { echo "$1" exit 1 } warn() { echo "$1" } # Find a source mirror near you which supports rsync on # https://launchpad.net/ubuntu/+archivemirrors # rsync://<iso-country-code>.rsync.archive.ubuntu.com/ubuntu should always work #RSYNCSOURCE=rsync://archive.ubuntu.mirror.isp.com/ubuntu # 实验发现rsync不通了,用下面这个: RSYNCSOURCE=archive.ubuntu.com::ubuntu # Define where you want the mirror-data to be on your mirror #BASEDIR=/var/www/ubuntuarchive/ # 改为本身的目录: BASEDIR=/media/smw/Appdata/ipfs-export/mirrors/ubuntu echo "From:" $RSYNCSOURCE echo "To:" $BASEDIR if [ ! -d ${BASEDIR} ]; then warn "${BASEDIR} does not exist yet, trying to create it..." mkdir -p ${BASEDIR} || fatal "Creation of ${BASEDIR} failed." fi rsync --recursive --times --links --safe-links --hard-links \ --stats \ --exclude "Packages*" --exclude "Sources*" \ --exclude "Release*" --exclude "InRelease" \ ${RSYNCSOURCE} ${BASEDIR} || fatal "First stage of sync failed." rsync --recursive --times --links --safe-links --hard-links \ --stats --delete --delete-after \ ${RSYNCSOURCE} ${BASEDIR} || fatal "Second stage of sync failed." date -u > ${BASEDIR}/project/trace/$(hostname -f)
对于 Releases mirrors, 事情就没有那么复杂了。由于 files之间没有依赖, 能够直接使用rsync。.net
#/bin/dash fatal() { echo "$1" exit 1 } warn() { echo "$1" } # Find a source mirror near you which supports rsync on # https://launchpad.net/ubuntu/+cdmirrors # rsync://<iso-country-code>.rsync.releases.ubuntu.com/releases should always work RSYNCSOURCE=rsync://releases.ubuntu.mirror.isp.com/releases # Define where you want the mirror-data to be on your mirror BASEDIR=/var/www/ubuntureleases/ if [ ! -d ${BASEDIR} ]; then warn "${BASEDIR} does not exist yet, trying to create it..." mkdir -p ${BASEDIR} || fatal "Creation of ${BASEDIR} failed." fi rsync --verbose --recursive --times --links --safe-links --hard-links \ --stats --delete-after \ ${RSYNCSOURCE} ${BASEDIR} || fatal "Failed to rsync from ${RSYNCSOURCE}." date -u > ${BASEDIR}/.trace/$(hostname -f)