搜索 
 设为首页 加入收藏
当前位置>>首页-学院-Linux
来源: 作者: 日期:2008-11-17 10:53 网友评论:0条 点击:912
  本文涉及apache的基本配置和rsync的配置,请先自行了解apache的其它配置含义。并最终以archlinux的二级rsync服务器为源,搭建一个本地的 rsync服务。当然,如果你手上正好又有多余的IP,请你共享出来,其它人就可以使用你搭建好的服务器了。

环境archlinux with kernel 2.6.27-ARCH
本文涉及apache的基本配置和rsync的配置,请先自行了解 apache的其它配置含义。并最终以archlinux的二级rsync服务器为源,搭建一个本地的 rsync服务。当然,如果你手上正好又有多余的IP,请你共享出来,其它人就可以使用你搭建好的服务器了。


路径结构:
/etc/httpd/conf/extra/httpd-vhosts.conf apache 配置文件
/storage/mirrors/archlinux根目录,保存所有mirror文件至此
/etc/rsyncd.conf    rsync配置文件

软件安装
apache 适用于web访问mirror文件
rsync    提供rsync服务及和远程rsync服务器同步

安装供web访问的apache服务器或其它web服务器,本文使用apache
sudo pacman -Sy apache
新增默认apache web目录
sudo mkdir -p /srv/http
sudo chown http:http /srv/http

启动apache
sudo apachectl start
如果出现
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

可以启用ServerName配置
httpd.conf 169行
#ServerName www.example.com:80
修改为
ServerName *:80

启动apache
sudo apachectl graceful

wget http://127.0.0.1
links http://127.0.0.1
服务启出现403错误,则apache配置正确

启用Virtual hosts
httpd.conf 453行
#Include conf/extra/httpd-vhosts.conf
修改为
Include conf/extra/httpd-vhosts.conf

添加新主机
sudo vi /etc/httpd/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin williamraym@gmail.com
    DocumentRoot /storage/mirrors/archlinux
    ServerName 127.0.0.1
    ServerAlias arch.mirrors.vifir.com
    ErrorLog logs/arch.mirrors.error_log
    CustomLog logs/arch.mirrors.access_log common
    Alias /arch/mirrors/ /storage/mirrors/archlinux/
    <Directory /storage/mirrors/archlinux>
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

应用配置文件
sudo apachectl graceful

安装 rsync
sudo pacman -S rsync

准备用户&目录
sudo groupadd http -g 48
sudo useradd -u 48 -g http http
mkdir -p /storage/mirrors/archlinux
chmod +w /storage/mirrors/archlinux
sudo chown http:http /storage/mirrors/archlinux

编辑apache配置文件,增加新的WEB访问地址为http://127.0.0.1/mirrors/archlinux

sudo vi /etc/httpd/conf/httpd.conf
支掉453行前面的#号,以启用conf/extra/httpd-vhosts.conf配置文件
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

新建rsync同步服务器文件的脚本/storage/mirrors/archlinux/sync.sh

#!/bin/sh
mirror=/storage/mirrors/archlinux
mkdir $mirror -p
SYNCLOGFILE="$mirror/sync.log"
SYNCLOCKFILE="$mirror/sync_now.lock"
options="-avz --delete --exclude=x86_64"

do_sync() {
    rsync $options rsync://mirrors.easynews.com:/mirrors/linux/archlinux/current /$mirror/
    rsync $options rsync://mirrors.easynews.com:/mirrors/linux/archlinux/core /$mirror/
    rsync $options rsync://mirrors.easynews.com:/mirrors/linux/archlinux/community /$mirror/
    rsync $options rsync://mirrors.easynews.com:/mirrors/linux/archlinux/extra /$mirror/
}

if [[ -f $SYNCLOCKFILE ]]; then
  exit 1
fi

echo -n ">>> Sync log for " > $SYNCLOGFILE
date >> $SYNCLOGFILE

cd $mirror
touch $SYNCLOCKFILE
do_sync >> $SYNCLOGFILE
#do_sync
rm -f $SYNCLOCKFILE


chmod +x /storage/mirrors/archlinux/sync.sh
sudo sh /storage/mirrors/archlinux/sync.sh


编辑rsync的配置文件
sudo cp /etc/rsyncd.conf /etc/rsyncd.conf.081115
sudo vi /etc/rsyncd.conf

系统默认的配置文件内容
######################the default config start#########################
uid = nobody
gid = nobody
use chroot = no
max connections = 4
syslog facility = local5
pid file = /var/run/rsyncd.pid

[ftp]
        path = /home/ftp
        comment = ftp area

######################end of the default config#########################
修改为自已的配置选项


uid=http
gid=http
max connections=10
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
[archlinux]
path=/storage/mirrors/archlinux
comment = archlinux
ignore errors
read only = no
hosts allow=192.168.0.0/24 127.0.0.1/24



启动rsync服务
sudo /usr/bin/rsync --daemon


测试rsync服务器

sudo rsync -avz rsync://127.0.0.1:/archlinux /opt/mirror



receiving incremental file list
./

sent 38 bytes  received 89 bytes  254.00 bytes/sec
total size is 0  speedup is 0.00


到此,本地的archlinux mirror基本完成,下面就运行同步服务器脚本,download所有pkg至本地mirror。
如果你是在一个局域网内,那这个方法真是太好了,可以省去其它服务器再到外网去下载的痛苦了。以前我也试过备份恢复/var/cache/pacman/pkg目录的方法,这样还是每次都要经过漫长的压包解包的过程。


【发表评论 0条】
发表评论
最新评论:已有0位感兴趣的读者发表了看法

验证码:请输入前面图中的四位验证码,字母不区分大小写


网站简介 | 广告服务 | VIP资费标准 | 银行汇款帐号 | 网站地图 | 帮助 | 联系方式
地址:成都八宝街一号万和苑C座1203 电话:028-86272612 传真: 028-86272612
开源人网站版权所有  渝ICP备06004507号  建议使用1024*768分辨率