fmirrorの設定

-------------------------------------------------------------------------------

□ fmirror のインストール

○ greenにて, rootになって作業. まずfmirror のインストール(aptの利用) # apt-get install fmirror

□ fmirror の設定

fmirrorの設定ファイルは /etc/fmirror に置かれる. ここには実際にミラーリングを行う際の設定とミラーリングの 実行を記述したシェルスクリプトである *.conf ファイルと, cron による自動ミラーリングを意識した config ファイルがある. ○ debian.confの設定 まずは devian.conf を設定する. # cd /etc/fmirror # vi debian.conf これを以下のように設定. (<*>は書き変え, あるいは書き加えたところ) =============================================================================== # mirror debian username: anonymous password: tsubasa@ep.sci.hokudai.ac.jp <*> host: ftp.jp.debian.org <*> remotedir: / <*> localdir: /home/ftp/common/Linux/ <*> #loglevel: 1 compressed: 1 decompressor: gzip decompressor_opt: -dc dircmd: RETR ls-lR.gz # the normal excludes first exclude: f ^(\.in\.|\.mirror|core$|MIRROR\.LOG|\.notar|\.message) exclude: f ^(\.cache|\.zipped|lost\+found|Network Trash Folder) exclude: p ^(bin/|etc/|lib/) <*> # exclude the uncompressed Contents and Packages files, and all ls-lR files include: if Packages-.*\.gz$ include: if Contents-.*\.gz$ exclude: if Contents- exclude: if Packages- exclude: if ls-lR # dont get source exclude: p (^|/)source/ # get binaries only for intel, and all include: p (^|/)(disks|binary)-(all|i386)/ exclude: p (^|/)(msdos|disks|binary)-.*/ exclude: if _(alpha|m68k|sparc|powerpc)\.deb$ =============================================================================== ※ここで, /home/ftp 以下に /common/Linux を作成. ○ config の設定 こちらは cron によるミラーリングのための各種環境変数の設定を行っている. # vi config これを以下のように設定. (<*>は書き変え, あるいは書き加えたところ) =============================================================================== # # configuration file for run_fmirror # # this is a bash shell script which is sourced by /usr/lib/fmirror/run_fmirror # # The variables you may change in this config file are: # RUN_IN_BACKGROUND, NUMLOGS, NIGHTLY_JOBS, and DAY[0..6] # do you want the mirror jobs to be run simultaneously? 0=false, 1=true RUN_IN_BACKGROUND=1 # how many days worth of old log files do you want to keep ? NUMLOGS=7 # do not change the following line. TODAY=$(date +%w) # list the basename(s) of each mirror job to run. # # each mirror job has a configuration file in /etc/fmirror, with the # filename of .conf. List only the job names here, without the # .conf extension. # # Note: the quotes ("") are essential. # jobs to be run every night. Start time is specified in /etc/cron.d/fmirror. #NIGHTLY_JOBS="debian debian-incoming debian-non-US" NIGHTLY_JOBS="debian debian-incoming debian-nonus" <*> # jobs to be run only on specific days. 0=Sun, 1=Mon, ..., 6=Sat # # note: do NOT list jobs in both NIGHTLY_JOBS and in DAY[0..6] otherwise # the job will be run twice simultaneously. DAY[0]="debian" <*> DAY[1]="" DAY[2]="" DAY[3]="" DAY[4]="" DAY[5]="" DAY[6]="" # do not change the following lines. JOBS="$NIGHTLY_JOBS ${DAY[$TODAY]}" # delete any duplicate entries JOBS=$(echo $JOBS | xargs -n 1 echo | sort -u) # if set, nightly logs are mailed to the specified user(s) #MAILTO=root =============================================================================== ここで変数 NIGHTLY_JOBS に指定した文字列に .conf を付けた 名前のファイルが cron によるミラーリングの設定に用いられる ことになる. ここでは debian debian-incoming debian-nonus となっているため debian.conf, debian-incoming.conf, debian-nonus ファイルが使われる. ただし debian は容量が非常に大きいため 毎日ミラーせず, 毎週日曜日のみミラーを行うようにした。 ○ cron による自動化 UNIX には定期的に行う作業を自動的に行うための cron という ツールが用意されている. さらに debian では /etc/cron.daily/, /etc/cron.weekly/ といったフォルダを用意している. これらのフォルダに格納されたプログラムをそれぞれ毎日, 毎週実行 することで設定を簡単にしている. fmirror の実行スクリプトは /etc/cron.daily に格納. # vi /etc/cron.daily/fmirror これを以下のように設定. =============================================================================== # ! /bin/bash # /etc/cron.daily/fmirror # # run the scheduled fmirror # # Author: Craig Sanders # # Copyright status: This script is copyright and licensed under the # terms of the GNU General Public License. #set -x confdir=/etc/fmirror logdir=/var/log/fmirror # if logdir doesn't exist then create it. [ -d $logdir ] || mkdir -p $logdir # read in the config file . $confdir/config # allow command line override of which jobs to run if [ -n "$1" ] ; then MIRRORS="$@" else MIRRORS=$JOBS fi # strip off .conf in case the user has ignored the instructions in # /etc/fmirror/config saying to list only the base name. MIRRORS=$(echo $MIRRORS | sed -e 's/\.conf//') do_it() { run=/var/run/fmirror.$1 if [ ! -e $run ] ; then touch $run tmpfile=`tempfile --name /tmp/fmirror.log.$1.$$.$(date +%s)` LOG=$logdir/$1.log ( [ -e $LOG ] && savelog -c $NUMLOGS $LOG # run the mirror job rm -f ls-lR ls-lR.gz conf="$confdir/$1.conf" fmirror -f $conf >/dev/null # create the local ls-lR.gz file localdir=`grep -i "^localdir:" $conf | cut -f2` cd $localdir # use full path to ls, just in case it is aliased to 'ls -F' or # something. /bin/ls -lR >ls-lR gzip -9f ls-lR ) >$tmpfile 2>&1 if [ -n "$MAILTO" ] ; then cat $tmpfile | mail $MAILTO fi rm -f $run mv $tmpfile $LOG fi } for i in $MIRRORS ; do if [ "$RUN_IN_BACKGROUND" = "1" ] ; then do_it $i & else do_it $i fi done =============================================================================== ------------------------------------------------------------------------------- 最終更新日 2002.10.09 槌谷 翼