构建本地yum源
下载repo数据文件
根据需要修改下载路径和reposync参数
#!/bin/bashlocal_path='/repo/remote/rhel9'
enabled_repos=$(yum repolist enabled | awk 'NR>=3{print $1}')
tempfile=$(mktemp -t reposync.XXXX)check() {echo "目标目录剩余空间: $(df -h ${local_path} | awk 'NR>1{print $4}')" >> "$tempfile"echo -e "需要同步的RepoID: \n$enabled_repos" >> "$tempfile"
}begin_sync() {echo "当前时间: $(date +"%Y年%m月%d日 %H点%M分%S秒" --date='TZ="Asia/Shanghai" now') 主机: $HOSTNAME reposync到路径 $local_path" >> "$tempfile"for repoid in $enabled_repos; doecho "当前时间: $(date +"%Y年%m月%d日 %H点%M分%S秒" --date='TZ="Asia/Shanghai" now') 开始同步 $repoid" >> "$tempfile"reposync -p $local_path --repoid="$repoid" --downloadcomps --download-metadata --newest-onlyecho "当前时间: $(date +"%Y年%m月%d日 %H点%M分%S秒" --date='TZ="Asia/Shanghai" now') 生成 $repoid" >> "$tempfile"createrepo -v $local_path/"$repoid" -g comps.xmlecho "当前时间: $(date +"%Y年%m月%d日 %H点%M分%S秒" --date='TZ="Asia/Shanghai" now') 同步完成 $repoid" >> "$tempfile"done
}notify() {echo "当前时间: $(date +"%Y年%m月%d日 %H点%M分%S秒" --date='TZ="Asia/Shanghai" now') 主机: $HOSTNAME reposync任务执行成功" >> "$tempfile"echo "=========================================================" >> "$tempfile"
}clean_tmp(){cat "$tempfile" >> /root/reposync.logrm "$tempfile"
}
check
begin_sync
notify
clean_tmp
本地web服务器
使用nginx或者httpd把对应的路径设置为webroot即可