> CentOS > CentOS教程 >

CentOS本地yum源的搭建

第一步:
从rsync协议的yum源,同步脚本如下:
[root@50-250 crontab]# cat yum_update.sh
#!/bin/bash
date=`date +%F`
echo $date > /var/log/yum_update.log
##########Centos
sour_URL="rsync://centos.ustc.edu.cn/centos"
osList="6.6"
os_Plant="x86_64"
cmd="rsync -avrt "
cmd=${cmd}${sour_URL}"/"${sour_Dir}"/"
outDir="/home/himalayas/yum/centos/6/"  ### if change ,please notice the line of epel、rpmforge、rpmfusion
for yumdir in os updates extras centosplus contrib;
do
        test -d $outDir/$yumdir || mkdir -p $outDir/$yumdir
        rsync -avrt $sour_URL/$osList/$yumdir/$os_Plant $outDir/$yumdir  >> /var/log/yum_update.log &
done

##########epel
test -d /home/himalayas/yum/epel/6/x86_64 || mkdir -p /home/himalayas/yum/epel/6/x86_64
rsync -avrt --exclude=debug/ --exclude=repoview/ rsync://centos.ustc.edu.cn/fedora/epel/6/x86_64/ /home/himalayas/yum/epel/6/x86_64 >> /var/log/yum_update.log &

##########rpmforge
test -d /home/himalayas/yum/rpmforge/6/rpmforge/x86_64 || mkdir -p /home/himalayas/yum/rpmforge/6/rpmforge/x86_64
test -d /home/himalayas/yum/rpmforge/6/extras/x86_64 || mkdir -p /home/himalayas/yum/rpmforge/6/extras/x86_64
rsync -avrt rsync://mirror.cpsc.ucalgary.ca/dag/redhat/el6/en/x86_64/rpmforge/ /home/himalayas/yum/rpmforge/6/rpmforge/x86_64 >> /var/log/yum_update.log &  ###4678
rsync -avrt rsync://mirror.cpsc.ucalgary.ca/dag/redhat/el6/en/x86_64/extras/ /home/himalayas/yum/rpmforge/6/extras/x86_64 >> /var/log/yum_update.log &

##########rpmfusion
test -d /home/himalayas/yum/rpmfusion/free/x86_64 || mkdir -p /home/himalayas/yum/rpmfusion/free/x86_64
test -d /home/himalayas/yum/rpmfusion/nofree/x86_64 || mkdir -p /home/himalayas/yum/rpmfusion/nofree/x86_64
rsync -avrt rsync://centos.ustc.edu.cn/fedora/rpmfusion/free/el/updates/6/x86_64/ /home/himalayas/yum/rpmfusion/free/x86_64 >> /var/log/yum_update.log &

rsync -avrt rsync://centos.ustc.edu.cn/fedora/rpmfusion/nonfree/el/updates/6/x86_64/ /home/himalayas/yum/rpmfusion/nofree/x86_64 >> /var/log/yum_update.log &

备注:
1,访问这个网址:centos.ustc.edu.cn/centos/ ,当版本更新之后所有的rpm包可能有6.5转到6.6的目录下,这个时候要手工更改变量:osList="6.6",然后最好手工执行一次,看是否可以同步更新。
2,可以用如下命令,查看对方rsync源的目录结构和所有rpm包
rsync -avrt rsync://centos.ustc.edu.cn/centos/6.6/os/x86_64

第二步:添加到crontab每天同步一次
00 00 * * * /bin/bash /kuxun/crontab/yum_update.sh (责任编辑:IT)