当前位置: 首页 > news >正文

Centos7通过reposync搭建本地Yum源

目录

1. 服务端搭建

1.1. 安装相关软件包

1.2. 加载几个常用的yum源

1.3. 创建文件保存目录

1.4. 把各仓库同步到本地

1.5. 生成仓库信息

1.6. 定时任务更新仓库

1.7. nginx配置下载服务

1.8. 内网测试nginx服务配置是否正确

2. 客户端配置


前言:之前使用rsync同步官方源没问题,但是同步国内的yum源时出现了同步不起的问题,所以改用reposync的方式。

操作系统:centos7.2 x64,2c4G,100G系统盘,500G数据盘。

1. 服务端搭建

1.1. 安装相关软件包

#1 安装相关软件包
yum install nginx yum-utils createrepo -y
systemctl start nginx

1.2. 加载几个常用的yum源

#备份原先的yum源
mkdir -p /etc/yum.repos.d/back && mv /etc/yum.repos.d/* /etc/yum.repos.d/back#下载centos7源
wget -O /etc/yum.repos.d/Centos-7.repo https://mirrors.aliyun.com/repo/Centos-7.repo#下载epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo#下载k8s源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF#下载docker源
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo#使用yum repolist验证
yum repolist

1.3. 创建文件保存目录

mkdir -p /usr/share/nginx/html/yum

1.4. 把各仓库同步到本地

reposync -r base             -p /usr/share/nginx/html/yum
reposync -r docker-ce-stable -p /usr/share/nginx/html/yum
reposync -r epel             -p /usr/share/nginx/html/yum
reposync -r extras           -p /usr/share/nginx/html/yum
reposync -r updates          -p /usr/share/nginx/html/yum

1.5. 生成仓库信息

createrepo /usr/share/nginx/html/yum/base
createrepo /usr/share/nginx/html/yum/docker-ce-stable
createrepo /usr/share/nginx/html/yum/epel
createrepo /usr/share/nginx/html/yum/extras
createrepo /usr/share/nginx/html/yum/updates

1.6. 定时任务更新仓库

cat <<EOF> /data/yum-update.sh
#!/bin/bash#同步数据
reposync -r base             -p /usr/share/nginx/html/yum
reposync -r docker-ce-stable -p /usr/share/nginx/html/yum
reposync -r epel             -p /usr/share/nginx/html/yum
reposync -r extras           -p /usr/share/nginx/html/yum
reposync -r updates          -p /usr/share/nginx/html/yum#更新元数据
createrepo --update /usr/share/nginx/html/yum/base
createrepo --update /usr/share/nginx/html/yum/docker-ce-stable
createrepo --update /usr/share/nginx/html/yum/epel
createrepo --update /usr/share/nginx/html/yum/extras
createrepo --update /usr/share/nginx/html/yum/updates
EOF#crontab -e
grep yum-update.sh /var/spool/cron/root || echo "0 6 * * * 0 6 * * * /bin/bash /data/yum-update.sh" >> /var/spool/cron/root

1.7. nginx配置下载服务

cat <<EOF> /etc/nginx/conf.d/yum.tom.com.conf 
server {listen 80;server_name yum.tom.com;location / {# 启用目录浏览autoindex on;root /usr/share/nginx/html/yum/;# 可选项: 不显示文件的确切大小,而是使用KB, MB等单位autoindex_exact_size off;# 可选项: 使用服务器本地时间显示文件时间autoindex_localtime on;}
}
EOFnginx -t
systemctl restart nginxcurl -H host:yum.tom.com localhost

1.8. 内网测试nginx服务配置是否正确

[root@yum conf.d]# curl -H host:yum.tom.com 10.0.0.81
<html>
<head><title>Index of /</title></head>
<body>
<h1>Index of /</h1><hr><pre><a href="../">../</a>
<a href="base/">base/</a>                                              02-Sep-2024 19:11       -
</pre><hr></body>
</html>

2. 客户端配置

#备份原先的yum源
mkdir -p /etc/yum.repos.d/back && mv /etc/yum.repos.d/* /etc/yum.repos.d/back#配置yum源为自建地址
cat <<EOF> /etc/yum.repos.d/centos7.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://10.0.0.81/base
enabled=1
gpgcheck=0[base-ex]
name=CentOS-$releasever - Base-ex
baseurl=http://10.0.0.81/extras
enabled=1
gpgcheck=0[epel]
name=epel
baseurl=http://10.0.0.81/epel
enabled=1
gpgcheck=0[docker]
name=docker-ce
baseurl=http://10.0.0.81/docker-ce-stable
enabled=1
gpgcheck=0[k8s]
name=docker-ce
baseurl=http://10.0.0.81/kubernetes
enabled=1
gpgcheck=0EOF#使用yum repolist验证
yum repolist


 

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 非局部均值降噪算法(NLM)原理及实现
  • 冒泡排序;选择排序;插入排序;快排;判断大小端;位运算
  • 【C++算法】分治(快排 归并)
  • 中国各城市、各区县、各省份-PM2.5相关数据(1998-2021年)
  • 零基础5分钟上手亚马逊云科技 - AI模型内容安全过滤
  • Flink 配置文件的深度解读
  • 评价决策类——层次分析法+数学建模+实战分析
  • Ascend C算子开发(入门)—— 算子开发初体验
  • C++ 学习 2024.9.3
  • C++ MQTT客户端库libmosquitto的使用
  • 编译与链接
  • ChatTCP:一款离线TCP数据包分析macOS APP,致力于让分析TCP数据包像看聊天记录一样简单
  • 【QT】析构函数执行引发异常
  • MATLAB 中双引号 ““ 和单引号 ‘‘ 的区别详解
  • 设计模式-原型适配器桥接外观
  • 4个实用的微服务测试策略
  • CentOS7简单部署NFS
  • PHP 小技巧
  • 高度不固定时垂直居中
  • 浏览器缓存机制分析
  • 如何合理的规划jvm性能调优
  • 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
  • 突破自己的技术思维
  • # Redis 入门到精通(八)-- 服务器配置-redis.conf配置与高级数据类型
  • # Redis 入门到精通(一)数据类型(4)
  • # Swust 12th acm 邀请赛# [ K ] 三角形判定 [题解]
  • ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
  • #微信小程序:微信小程序常见的配置传值
  • $L^p$ 调和函数恒为零
  • (173)FPGA约束:单周期时序分析或默认时序分析
  • (C语言)求出1,2,5三个数不同个数组合为100的组合个数
  • (C语言)字符分类函数
  • (vue)el-tabs选中最后一项后更新数据后无法展开
  • (博弈 sg入门)kiki's game -- hdu -- 2147
  • (附源码)springboot太原学院贫困生申请管理系统 毕业设计 101517
  • (附源码)基于SpringBoot和Vue的厨到家服务平台的设计与实现 毕业设计 063133
  • (六)c52学习之旅-独立按键
  • (原創) 如何解决make kernel时『clock skew detected』的warning? (OS) (Linux)
  • (转)setTimeout 和 setInterval 的区别
  • ****** 二十三 ******、软设笔记【数据库】-数据操作-常用关系操作、关系运算
  • ****三次握手和四次挥手
  • .locked1、locked勒索病毒解密方法|勒索病毒解决|勒索病毒恢复|数据库修复
  • .NET MVC、 WebAPI、 WebService【ws】、NVVM、WCF、Remoting
  • .NETCORE 开发登录接口MFA谷歌多因子身份验证
  • .NET中统一的存储过程调用方法(收藏)
  • @Conditional注解详解
  • @staticmethod和@classmethod的作用与区别
  • @Transactional类内部访问失效原因详解
  • [acwing周赛复盘] 第 69 场周赛20220917
  • [AI Embedchain] 开始使用 - 全栈
  • [android]-如何在向服务器发送request时附加已保存的cookie数据
  • [AutoSar]BSW_Com07 CAN报文接收流程的函数调用
  • [C#]猫叫人醒老鼠跑 C#的委托及事件
  • [C++][数据结构][跳表]详细讲解
  • [C++参考]拷贝构造函数的参数必须是引用类型