本地私有仓库搭建步骤:
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