响水凹

欢迎来到 Guang-Wen Duan (Dennis Duan) 的个人 Wiki

用户工具

站点工具


computer:env:mirror

搭建本地的软件源镜像服务器

虽然网络越来越发达,但如果本地机器较多的话,专门搭建一台机器作为软件源服务器,供所有机器安装系统和补丁,无论从哪方面看都是一个理想的选择。

本文讲述个人常用的几个系统的镜像方法。

slackware

rsync应该算是最常用的镜像工具了,有关rsync的使用方法,可查看man pages。下面将通过一个shell脚本,使用rsync实现slackware各版本的镜像。

首先设置一个shell变量,指定远程服务器地址:

#!/bin/sh
 
URL="rsync://rsync.slackware.at/slackware/"

对于较新的版本,进行全部镜像;而较老的版本,则只下载补丁部分:

# Get a valid version and set EXCLUDE.
case $1 in
10.2|11.0|12.0|12.1|12.2)
	SOURCE="${URL}slackware-$1"
	EXCLUDE="--exclude=bootdisks/ --exclude=extra/ --exclude=isolinux/ \
		--exclude=kernels/ --exclude=pasture/ --exclude=rootdisks/ \
		--exclude=slackware/ --exclude=source/ --exclude=testing/ \
		--exclude=zipslack/ --exclude=usb-and-pxe-installers/"
	;;
13.0|13.1|13.37|current)
	SOURCE="${URL}slackware-$1"
	EXCLUDE=""
	;;
64-13.0|64-13.1|64-13.37|64-current)
	SOURCE="${URL}slackware$1"
	EXCLUDE=""
	;;
*)
	echo "Usage: `basename $0` version"
	echo -e "\tValid:  10.2, 11.0, 12.0, 12.1, 12.2, 13.0, 64-13.0, 13.1, 64-13.1, 13.37, 64-13.37"
	echo -e "\t\tcurrent, 64-current"
	exit 1
	;;
esac

设置选项:

# Set OPTIONS.
OPTIONS="-avzP --delete"

指定目标路径:

# Set the destination path where the repository to be stored.
DEST="/pub/ftp/pub/linux/slackware"

最后运行rsync命令:

# Run rsync.
/usr/bin/rsync $OPTIONS $EXCLUDE $SOURCE $DEST
 
exit 0

将此脚本命名为rsync-slackware.sh,假设要镜像current版本,则执行:

./rsync-slackware.sh current

当然也可将脚本投入到cron服务器里,定时自动运行。

CentOS

同样使用rsync来实现。这里只镜像CentOS的6.3和5.8版本,所以就一并完成了,不再需要脚本参数。脚本的实现基本类似,故直接附完整代码:

rsync-centos.sh
#!/bin/sh
 
# Choose one site below and un-comment it.
URL="rsync://mirrors.ustc.edu.cn/centos"
 
# Set OPTIONS.
OPTIONS="-avP --delete"
 
# Set EXCLUDE.
EXCLUDE="--exclude=fasttrack/ --exclude=isos/"
 
# Set the destination path where the repository to be stored.
DEST="/pub/ftp/pub/linux/centos"
 
# Run rsync.
# 6(6.3)
/usr/bin/rsync $OPTIONS $EXCLUDE ${URL}/6 $DEST
/usr/bin/rsync $OPTIONS $EXCLUDE ${URL}/6.3 $DEST
 
# 5(5.8)
/usr/bin/rsync $OPTIONS $EXCLUDE ${URL}/5 $DEST
/usr/bin/rsync $OPTIONS $EXCLUDE ${URL}/5.8 $DEST
 
exit 0

Fedora

Fedora的软件仓库结构略复杂,又不想下载有些内容,为避免脚本过于复杂,故分成三条rysnc命令来实现。以Fedora 17为例:

rsync-fedora.sh
#!/bin/sh
 
# Choose one site below and un-comment it.
URL="rsync://mirrors.sohu.com/fedora"
 
# Set OPTIONS.
OPTIONS="-avP --delete"
 
# Set the destination path where the repository to be stored.
DEST="/pub/ftp/pub/linux/fedora"
 
# Run rsync.
# updates/17
EXCLUDE="--exclude=i386/debug/ --exclude=x86_64/debug/"
SUBSRC="updates/17"
SUBDEST="updates"
/usr/bin/rsync $OPTIONS $EXCLUDE ${URL}/${SUBSRC} $DEST/${SUBDEST}
 
# releases/17/Fedora
EXCLUDE="--exclude=i386/iso/ --exclude=i386/jigdo/ \
	--exclude=x86_64/iso/ --exclude=x86_64/jigdo/ \
	--exclude=source/iso/ --exclude=source/jigdo/"
SUBSRC="releases/17/Fedora"
SUBDEST="releases/17"
/usr/bin/rsync $OPTIONS $EXCLUDE ${URL}/${SUBSRC} $DEST/${SUBDEST}
 
# releases/17/Everything
EXCLUDE="--exclude=i386/debug/ --exclude=x86_64/debug/"
SUBSRC="releases/17/Everything"
SUBDEST="releases/17"
/usr/bin/rsync $OPTIONS $EXCLUDE ${URL}/${SUBSRC} $DEST/${SUBDEST}
 
exit 0

Scientific Linux

Scientific Linux也是RHEL的一个衍生版。它的仓库将二进制文件与源代码分开,故使用两条rsync命名实现镜像。以6.3为例:

rsync-scientific.sh
#!/bin/sh
 
# Choose one site below and un-comment it.
URL="rsync://rsync.scientificlinux.org/scientific"
 
# Set OPTIONS.
OPTIONS="-avzP --delete"
 
# Set the destination path where the repository to be stored.
DEST="/pub/ftp/pub/linux/scientific"
 
# Run rsync.
# 6.3
EXCLUDE="--exclude=i386/iso/ --exclude=x86_64/iso/"
/usr/bin/rsync $OPTIONS $EXCLUDE ${URL}/6.3 $DEST
 
# 6x
EXCLUDE="--exclude=archive/debuginfo/ --exclude=archive/obsolete/"
/usr/bin/rsync $OPTIONS $EXCLUDE ${URL}/6x $DEST
 
exit 0

Debian/Ubuntu

DebianUbuntu的软件仓库实在是太大了,而且各个版本的软件都混在一起。个人存储空间有限,无力全部镜像,也不需要所有的版本,故使用一个小巧的工具apt-mirror来实现镜像。由于apt-mirror是用perl实现的,可以运行在多种系统平台上,这也是吸引我的一点。

使用apt-mirror需要一个配置文件,形式与sources.list很相似。下面的例子用来镜像Debian squeeze和Ubuntu precise,同时包括i386和amd64架构,为了支持网络安装,也增加了installer的镜像:

apt-mirror.list
############# config ##################
#
set base_path    /pub/ftp/pub/linux/apt-mirror
#
# if you change the base path you must create the directories below with write privileges
#
# set mirror_path  $base_path/mirror
# set skel_path    $base_path/skel
# set var_path     $base_path/var
# set cleanscript $var_path/clean.sh
set defaultarch amd64
set nthreads     4
set _tilde 0
#
############# end config ##############
 
#
# Debian squeeze
#
deb-i386 http://mirrors.ustc.edu.cn/debian/ squeeze main contrib non-free
deb-i386 http://mirrors.ustc.edu.cn/debian/ squeeze main/debian-installer
deb-amd64 http://mirrors.ustc.edu.cn/debian/ squeeze main contrib non-free
deb-amd64 http://mirrors.ustc.edu.cn/debian/ squeeze main/debian-installer
deb-src http://mirrors.ustc.edu.cn/debian/ squeeze main contrib non-free
 
deb-i386 http://mirrors.ustc.edu.cn/debian-security/ squeeze/updates main contrib non-free
deb-amd64 http://mirrors.ustc.edu.cn/debian-security/ squeeze/updates main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian-security/ squeeze/updates main contrib non-free
 
deb-i386 http://mirrors.ustc.edu.cn/debian/ squeeze-updates main contrib non-free
deb-amd64 http://mirrors.ustc.edu.cn/debian/ squeeze-updates main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian/ squeeze-updates main contrib non-free
 
 
#
# Ubuntu precise
#
deb-i386 http://mirrors.ustc.edu.cn/ubuntu/ precise main restricted universe multiverse
deb-i386 http://mirrors.ustc.edu.cn/ubuntu/ precise main/debian-installer restricted/debian-installer universe/debian-installer multiverse/debian-installer
deb-amd64 http://mirrors.ustc.edu.cn/ubuntu/ precise main restricted universe multiverse
deb-amd64 http://mirrors.ustc.edu.cn/ubuntu/ precise main/debian-installer restricted/debian-installer universe/debian-installer multiverse/debian-installer
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise main restricted universe multiverse
 
deb-i386 http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted universe multiverse
#deb-i386 http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main/debian-installer universe/debian-installer
deb-amd64 http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted universe multiverse
#deb-amd64 http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main/debian-installer universe/debian-installer
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted universe multiverse
 
deb-i386 http://mirrors.ustc.edu.cn/ubuntu/ precise-security main restricted universe multiverse
#deb-i386 http://mirrors.ustc.edu.cn/ubuntu/ precise-security main/debian-installer universe/debian-installer
deb-amd64 http://mirrors.ustc.edu.cn/ubuntu/ precise-security main restricted universe multiverse
#deb-amd64 http://mirrors.ustc.edu.cn/ubuntu/ precise-security main/debian-installer universe/debian-installer
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-security main restricted universe multiverse
 
deb-i386 http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
deb-amd64 http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
 
 
#
# clean section
#
clean http://mirrors.ustc.edu.cn/debian
clean http://mirrors.ustc.edu.cn/debian-security
clean http://mirrors.ustc.edu.cn/ubuntu

运行:

./apt-mirror apt-mirror.list

网络发布

软件仓库制作好后,就可以通过NFS/HTTP/FTP等网络服务发布,供其他机器使用了。有关服务的搭建,可参阅:

HTTP服务器的安装和配置

FTP服务器的安装和配置

computer/env/mirror.txt · 最后更改: 2014/11/01 02:02 由 127.0.0.1