搭建私有yum源仓库同步阿里云yum源到本地私有yum仓库

本地私有仓库搭建步骤:
1.安装nginx

2.在本机配置阿里云yum源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/CentOS-epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

##这里将阿里的第三方epel源一起进行配置

3.同步公网镜像到本地私有仓库
用repoync 命令,Reposync用于将远程yum存储库同步到本地存储库

reposync -np  /data/centos/7/base/     
##这里同步的源文件就是上一步配置的yum源,/data/centos/7/base/ 为生成的本地yum仓库文件即rpm包所在路径

reposync
-n:只下载最新的包
-p:下载包的路径:默认为当前目录

4.将yum仓库文件即rpm包所在路径设置为 nginx发布目录

server {
    listen       80;
    server_name  mirrors.aaaa.com;
    root         /data/centos/7/base/;   #这里是yum源存放目录   
    location / { 
        autoindex on;        #打开目录浏览功能
        autoindex_exact_size off;  # off:以可读的方式显示文件大小
        autoindex_localtime on; # on、off:是否以服务器的文件时间作为显示的时间
        charset utf-8,gbk; #展示中文文件名
        index index.html;
    }   
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }   
}

5.设置定时同步任务
定时脚本:yum_update.sh

#!/bin/bash
echo 'Updating Aliyum Source'
DATETIME=`date +%F_%T`
exec > /var/log/aliyumrepo_$DATETIME.log
     reposync -np /data/centos/7/base
if [ $? -eq 0 ];then
      createrepo --update /data/centos/7/base/base
      createrepo --update /data/centos/7/base/extras
      createrepo --update /data/centos/7/base/updates
      createrepo --update /data/centos/7/base/epel
    echo "SUCESS: $DATETIME aliyum_yum update successful" >>/var/log/aliyumrepo_$DATETIME.log
  else
    echo "ERROR: $DATETIME aliyum_yum update failed" >> /var/log/aliyumrepo_$DATETIME.log
fi

添加定时任务:

0 3 * * 1  /bin/sh  /data/crond/yum_update.sh

##每周一凌晨三点执行

##参考:
https://blog.csdn.net/moyuanbomo/article/details/81667006
https://www.cnblogs.com/lldsn/p/10479493.html

  • 2
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值