成功最有效的方法就是向有经验的人学习!

在本地搭建YUM仓库并同步阿里云镜像

1.下载阿里云镜像repo文件
项目使用CentOS6系统,因此我下载的文件是:

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

2.刷新缓存

yum clean all
yum makecache

3.yum repolist

[root@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
仓库标识仓库名称状态
baseCentOS-6 - Base - mirrors.aliyun.com6,706
extras  CentOS-6 - Extras - mirrors.aliyun.com 46
updates CentOS-6 - Updates - mirrors.aliyun.com   826
repolist: 7,778

4.同步镜像到本地

reposync -r base
reposync -r extras
reposync -r updates

5.创建YUM仓库

yum installcreaterepo yum-utils -y
cd base
createrepo ./
cd ../extras
createrepo ./
cd ../updates
createrepo ./

6.安装nginx,搭建本地Web服务器
内容省略…
贴上配置文件nginx.conf:

server {
    listen       80;
    server_name  localhost;
    root /yumrepo;
    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }

7.其他服务器连接YUM仓库:

vim /etc/yum.repos.d/test.repo

[base]
name=CentOS-Base(GDS)
baseurl=http://10.63.215.7/base
path=/
enabled=1
gpgcheck=0

[updates]
name=CentOS-Updates(GDS)
baseurl=http://10.63.215.7/updates
path=/
enabled=1
gpgcheck=0

[extras]
name=CentOS-Extras(GDS)
baseurl=http://10.63.215.7/extras
path=/
enabled=1
gpgcheck=0

8.完工!
上面的3个base,extras,updates下载到本地是11GB

下面附一个脚本:

#!/bin/bash
#Script name:rsync_yumrepo.sh 

RsyncPerm='-avSH --delete-after --no-iconv --bwlimit=5000'
Centos_6_base='/app/YumRepo/Centos6/x86_64/Base/'
Centos_6_update='/app/YumRepo/Centos6/x86_64/update/'
Centos_6_epel='/app/YumRepo/Centos6/x86_64/Epel'
Centos_6_salt='/app/YumRepo/Centos6/x86_64/Salt'
Centos_6_docker='/app/YumRepo/Centos6/x86_64/Docker'
Centos_7_base='/app/YumRepo/Centos7/x86_64/Base/'
Centos_7_update='/app/YumRepo/Centos7/x86_64/update/'
Centos_7_epel='/app/YumRepo/Centos7/x86_64/Epel'
Centos_7_salt='/app/YumRepo/Centos7/x86_64/Salt'
Centos_7_docker='/app/YumRepo/Centos7/x86_64/Docker'
LogFile='/app/YumRepo/rsync_yum_log'
Date=`date +%Y-%m-%d`

function CheckDir(){
if [ -d $1 ];then
        echo "$1 dir is exist,Please check it!"
else
        echo "$1 dir is not exist,will create it!"
    mkdir $1 -p
fi
}
function CheckFile(){
if [ -e $1 ];then
        echo "$1 dir is exist,Please check it!"
else
        echo "$1 dir is not exist,Please install on there!"
fi
}
function CheckStatus(){
if [ $? -eq 0 ];then
    echo -e "\033[1;32mRsync is success!\033[0m" >>$LogFile/$Date.log
else
    echo -e "\033[1;31mRsync is fail!\033[0m" >>$LogFile/$Date.log
fi
}
CheckDir ${LogFile}
CheckDir ${Centos_6_base}
CheckDir ${Centos_6_update}
CheckDir ${Centos_6_epel}
CheckDir ${Centos_6_salt}
CheckDir ${Centos_6_docker}
CheckDir ${Centos_7_base}
CheckDir ${Centos_7_update}
CheckDir ${Centos_7_epel}
CheckDir ${Centos_7_salt}
CheckDir ${Centos_7_docker}


###rsync centos  base
echo 'Now start to rsync centos 6 base!' >>$LogFile/$Date.log
rsync $RsyncPerm rsync://mirrors.ustc.edu.cn/centos/6/os/x86_64/ $Centos_6_base >>$LogFile/$Date.log
CheckStatus
echo 'Now start to rsync centos 7 base!' >>$LogFile/$Date.log
rsync $RsyncPerm rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/ $Centos_7_base >>$LogFile/$Date.log
CheckStatus

###rsync epel
echo 'Now start to rsync centos 6 epel!' >>$LogFile/$Date.log
rsync  $RsyncPerm  rsync://mirrors.ustc.edu.cn/epel/6/x86_64/ $Centos_6_epel  >>$LogFile/$Date.log
CheckStatus
echo 'Now start to rsync centos 7 epel!' >>$LogFile/$Date.log
rsync  $RsyncPerm  rsync://mirrors.ustc.edu.cn/epel/7/x86_64/ $Centos_7_epel  >>$LogFile/$Date.log
CheckStatus

###rsync salt
echo 'Now start to rsync centos 6 salt!' >>$LogFile/$Date.log
rsync $RsyncPerm rsync://mirrors.ustc.edu.cn/salt/yum/redhat/6/x86_64/ $Centos_6_salt >>$LogFile/$Date.log
CheckStatus
echo 'Now start to rsync centos 7 salt!' >>$LogFile/$Date.log
rsync $RsyncPerm rsync://mirrors.ustc.edu.cn/salt/yum/redhat/7/x86_64/ $Centos_7_salt >>$LogFile/$Date.log
CheckStatus

###rsync docker
#echo 'Now start to rsync centos 6 docker!' >>$LogFile/$Date.log
#rsync $RsyncPerm rsync://mirrors.ustc.edu.cn/docker-yum/repo/centos6/ $Centos_6_docker >>$LogFile/$Date.log
#CheckStatus
echo 'Now start to rsync centos 7 docker!' >>$LogFile/$Date.log
rsync $RsyncPerm rsync://mirrors.ustc.edu.cn/docker-ce/linux/centos/7/x86_64/stable/ $Centos_7_docker >>$LogFile/$Date.log
CheckStatus

###rsync golang
rsync $RsyncPerm rsync://mirrors.ustc.edu.cn/golang/go1.9.linux-arm64.tar.gz /app/YumRepo/golang/go1.9.linux-arm64.tar.gz 
CheckStatus

###rsync centos  update
echo 'Now start to rsync centos 6 update!' >>$LogFile/$Date.log
rsync $RsyncPerm rsync://mirrors.ustc.edu.cn/centos/6/updates/x86_64/ $Centos_6_update >>$LogFile/$Date.log
CheckStatus
echo 'Now start to rsync centos 7 base!' >>$LogFile/$Date.log
rsync $RsyncPerm rsync://mirrors.ustc.edu.cn/centos/7/updates/x86_64/ $Centos_7_update >>$LogFile/$Date.log
CheckStatus
[base]
name=Centos6 - base
baseurl=baseurl=http://HOSTADDR/Centos6/x86_64/Base
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
 
[updates]
name=CentOS6 - updates
baseurl=http://HOSTADDR/Centos6/x86_64/update
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

 

赞(0) 打赏
未经允许不得转载:陈桂林博客 » 在本地搭建YUM仓库并同步阿里云镜像
分享到

大佬们的评论 抢沙发

全新“一站式”建站,高质量、高售后的一条龙服务

微信 抖音 支付宝 百度 头条 快手全平台打通信息流

橙子建站.极速智能建站8折购买虚拟主机

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册