centos同步yum源到本地,创建本地网络yum源

软件安装

在安装之前建议将yum源修改为国内的源

yum -y install vim createrepo yum-utils httpd net-tools reposync
ls -1 /etc/yum.repos.d/
[root@DESKTOP-L9O2H6T ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                                                                       repo name                                                                                             status
base                                                                                          CentOS-7 - Base                                                                                       10072
extras                                                                                        CentOS-7 - Extras                                                                                       526
opennebula                                                                                    opennebula                                                                                               19
updates                                                                                       CentOS-7 - Updates                                                                                     5798
repolist: 16415

同步至本地

创建同步目录
mkdir -p /var/www/html/yum/
开始同步
reposync -p /var/www/html/yum/
等待yum同步到本地目录后,需要重新生成yum仓库。因为同步完成后远程yum仓库中的repodata不会被同步到本地;

创建本地yum仓库的命令为createrepo,该命令由createrepo安装包提供。

本地网络yum源制作

创建yum仓库
[root@DESKTOP-L9O2H6T ~]# cd /var/www/html/yum/
[root@DESKTOP-L9O2H6T yum]# ls
base  extras  repo  updates


createrepo -p /var/www/html/yum/base/
# 制作完成后,相对应的路径下会出现repodata文件,则说明制作成功
[root@DESKTOP-L9O2H6T yum]# cd base/
[root@DESKTOP-L9O2H6T base]# ls
Packages 
[root@DESKTOP-L9O2H6T base]# createrepo -p /var/www/html/yum/base/
Spawning worker 0 with 1450 pkgs
Spawning worker 1 with 1450 pkgs
Spawning worker 2 with 1449 pkgs
Spawning worker 3 with 1449 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@DESKTOP-L9O2H6T base]# ls
Packages  repodata

#在同步下来的每一个yum仓库目录都需要执行,上述操作。
createrepo -p /var/www/html/yum/extras/
createrepo -p /var/www/html/yum/updates/


[root@DESKTOP-L9O2H6T extras]# ls
Packages  repodata

[root@DESKTOP-L9O2H6T updates]# ls
Packages  repodata
配置完成后启动httpd服务,编写repo yum文件

#启动httpd服务

systemctl start httpd

#10.xxx.xxx为你本地主机的IP地址

[root@DESKTOP-L9O2H6T ~]# cat /etc/yum.repos.d/local.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://10.xxx.xxx.xxx/yum/base/
gpgcheck=0
enabled=1


[updates]
name=CentOS-$releasever - Updates
baseurl=http://10.2xxx.xxx.xxx/yum/updates/
gpgcheck=0
enabled=1


[extras]
name=CentOS-$releasever - Extras
baseurl=http://10.xxx.xxx.xxx/yum/extras/
gpgcheck=0
enabled=1


[opennebula]
name=opennebula
baseurl=http://10.xxx.xxx.xxx/yum/repo/6.4/CentOS/7/x86_64/
enabled=1
gpgcheck=0

后续更新了rpm软件库包的文件后,都要进入相应的目录,利用createrepo update进行同步。

reposync -p /var/www/html/yum/
cd base
createrepo --update /var/www/html/yum/base/
其他目录命令相同
参考链接:https://juejin.cn/post/6993102842332446756

其它同步方式

wget

wget:用于从网络上自动下载文件的工具。

我的同步命令,仅供参考

wget https://downloads.opennebula.io/repo/6.4/CentOS/7/x86_64/  -r -c -np -nH -e robots=off --no-check-certificate


参考链接:https://blog.csdn.net/Zp18189530679/article/details/111094102


关注小张的知识杂货铺,让我们一起学习一起进步

posted @   小张1995  阅读(255)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示