首先从CentOS官方源(msync.centos.org),同步一份本地镜像(约7G左右),然后禁用原有的源,并创建一个本地的.repo仓库文件。
一、Rsync 同步脚本
1 2 3 4 |
wget http://wangyan.org/download/shell/rsync_repo.sh vim rsync_repo.sh //修改"local"值(本地镜像存放路径) chmod 755 rsync_repo.sh ./rsync_repo.sh |
/*******************************************/
#! /bin/bash #==================================================================== # rsync_repo.sh # # Copyright (c) 2011, WangYan <webmaster@wangyan.org> # All rights reserved. # Distributed under the GNU General Public License, version 3.0. # # This script will create a local CentOS mirror via Rsync # # See: https://wangyan.org/blog/centos-local-yum-repo.html # # Version: 0.1" # Created by WangYan on 2011.09.12" # #==================================================================== local=/mnt/hgfs/e/CentOS mirror="msync.centos.org::CentOS" rsync="rsync -avzH --delete" verlist="6.0" baselist="os updates extras centosplus contrib fasttrack" archlist="i386" #==================================================================== get_char() { SAVEDSTTY=`stty -g` stty -echo stty cbreak dd if=/dev/tty bs=1 count=1 2> /dev/null stty -raw stty echo stty $SAVEDSTTY } clear echo -e "\nPress any key to start sync..." char=`get_char` for ver in $verlist do for base in $baselist do for arch in $archlist do remote=$mirror/$ver/$base/$arch/ mkdir -pv $local/$ver/$base/$arch/ $rsync $remote $local/$ver/$base/$arch/ done done done
/**********************************************/
二、禁用原有的源
注:你也可以直接编辑.repos文件,加上参数”enabled=0″禁用源。
1 |
for i in `ls /etc/yum.repos.d/`;do mv /etc/yum.repos.d/$i /etc/yum.repos.d/$i.bak;done |
禁用fastestmirror插件,再也不需要这东西了。
1 |
sed -i 's/plugins=1/plugins=0/g' /etc/yum.conf |
三、创建本地.repo文件
注意记得修改默认的”/mnt/hgfs/e/CentOS”本地镜像路径
1 2 3 |
wget http://wangyan.org/download/conf/CentOS-Local.repo -P /etc/yum.repos.d chmod 644 /etc/yum.repos.d/rsync_repo.sh yum -y update |
/***********************************/
# CentOS-Local.repo # [base] name=CentOS-$releasever - Os baseurl=file:///mnt/hgfs/e/CentOS/$releasever/os/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #released updates [updates] name=CentOS-$releasever - Updates baseurl=file:///mnt/hgfs/e/CentOS/$releasever/updates/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=file:///mnt/hgfs/e/CentOS/$releasever/extras/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus baseurl=file:///mnt/hgfs/e/CentOS/$releasever/centosplus/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib baseurl=file:///mnt/hgfs/e/CentOS/$releasever/contrib/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
/***********************************/
来源:https://wangyan.org/blog/centos-local-yum-repo.html
固定链接: http://anywang.vicp.net:8180/wp/?p=281 | 网邻's Blog
最新评论
厉害,一个信息技术教师的水平