基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
ahcoder 2025-04-05 16:25 19 浏览
前言:
由于公司业务服务器大部分都在内网环境下运行,内网环境无法直接使用yum安装升级更新软件,所以需要自建Yum源来满足目前日常工作需要。
YUM 常用命令参数:
yum makecache #构建缓存
yum check-update #列出所有可更新的软件清单命令
yum list all #列出所有已安装及可安装的软件包
yum provides ifconfig #列出ifconfig命令是那个软件包提供的
yum grouplist #查询可以用安装的组
yum update #内核升级或者更新所有软件(*谨慎使用*)
yum update nginx #仅更新指定的nginx软件包
yum -y install nginx #安装nginx软件包
yum search nginx #YUM搜索nginx软件包
yum list httpd #显示指定程序包安装情况nginx
yum remove httpd #删除程序包nginx
yum erase httpd #删除程序包httpd
yum update httpd #升级httpd 服务
yum clean all #清除缓存目录下的软件包及旧的 headers
基于ISO系统镜像包来构建本地YUM源:
1.添加YUM源配置文件
[root@centos ~]# cat /etc/yum.repos.d/iso.repo
[ios]
name=iso
baseurl=file:///mnt
enabled=1
gpgcheck=0
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7 #指定挂载目录下的GPG-KEY文件验证
2.挂载光盘步骤
[root@centos ~]# mount /dev/cdrom /mnt/ #挂载光盘
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos ~]# df -h #查看挂载情况
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 1.6G 18G 8% /
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 9.0M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda2 197M 121M 77M 62% /boot
tmpfs 183M 0 183M 0% /run/user/0
dev/sr0 4.3G 4.3G 0 100% /mnt #挂载的ISO系统镜像包
3.开启开机自启动挂载
- 方式一:vim /etc/fstab
- 方式二:vim /etc/rc.local
添加内容:/dev/cdrom /mnt iso9660 defaults 0 0
[root@centos ~]# cat /etc/fstab |grep iso9660 #在/etc/fstab文件中添加
/dev/cdrom /mnt iso9660 defaults 0 0
添加内容:/dev/cdrom /mnt
[root@centos ~]# cat /etc/rc.local |grep /mnt #在/etc/rc.local文件中添加
/dev/cdrom /mnt
基于RPM包来构建本地Yum源:
httpd:使用http协议来搭建本地Yum源
createrepo:用于生成yum源各软件之间的依赖索引
yum-utils:安装后可使用 yumdownloader、reposync等命令下载所需软件包
1.下载网络Yum源中的RPM软件包
[root@centos ~]# yum -y install httpd yum-utils createrepo #安装几个必须要的软件包
[root@centos ~]# mkdir /var/www/html/centos6/ #创建RPM软件包下载存放目录
[root@centos ~]# ls /var/www/html/
centos6
[root@centos ~]# ss -antulp | grep :80 #查看httpd服务运行情况(Yum源通过http服务来搭建,需要启动httpd服务)
tcp LISTEN 0 128 :::80 :::* users:(("httpd",1952,6),("httpd",4551,6),("httpd",4552,6),("httpd",4553,6),("httpd",4554,6),("httpd",4555,6),("httpd",4556,6),("httpd",4557,6),("httpd",4558,6))
[root@centos ~]# yum repolist #查看网络Yum源情况(自行配置想要下载的网络Yum源)
Loading mirror speeds from cached hostfile
仓库标识 仓库名称 状态
extras Qcloud centos extras - x86_64 47
os Qcloud centos os - x86_64 6,713
updates Qcloud centos updates - x86_64 1,169
repolist: 7,929
[root@centos ~]# reposync -r extras -p /var/www/html/centos6/ #根据网络Yum源的仓库标识,下载Yum源中的所有RPM软件包到文件夹
[extras: 1 of 47 ] Downloading Packages/bakefile-0.2.8-3.el6.centos.x86_64.rpm
bakefile-0.2.8-3.el6.centos.x86_64.rpm | 250 kB 00:00
[extras: 2 of 47 ] Downloading Packages/centos-release-azure-1.0-2.el6.centos.noarch.rpm
centos-release-azure-1.0-2.el6.centos.noarch.rpm | 4.0 kB 00:00
[extras: 3 of 47 ] Downloading Packages/centos-release-cr-6-0.el6.centos.x86_64.rpm
centos-release-cr-6-0.el6.centos.x86_64.rpm | 3.9 kB 00:00
[extras: 4 of 47 ] Downloading Packages/centos-release-gluster-legacy-3.10-1.el6.centos.noarch.rpm
centos-release-gluster-legacy-3.10-1.el6.centos.noarch.rpm | 4.6 kB 00:00
[extras: 5 of 47 ] Downloading Packages/centos-release-gluster-legacy-4.0-1.el6.centos.noarch.rpm
centos-release-gluster-legacy-4.0-1.el6.centos.noarch.rpm | 4.9 kB 00:00
[extras: 6 of 47 ] Downloading Packages/centos-release-gluster-legacy-4.0-3.el6.centos.noarch.rpm
centos-release-gluster-legacy-4.0-3.el6.centos.noarch.rpm | 5.1 kB 00:00
...
...
[root@vos7 ~]# reposync -r updates -p /var/www/html/centos6/ #下载网络Yum源仓库标识updates中所有的RPM软件包
[updates: 1 of 1169 ] Downloading Packages/389-ds-base-1.2.11.15-97.el6_10.x86_64.rpm
389-ds-base-1.2.11.15-97.el6_10.x86_64.rpm | 1.5 MB 00:00
[updates: 2 of 1169 ] Downloading Packages/389-ds-base-devel-1.2.11.15-97.el6_10.i686.rpm
389-ds-base-devel-1.2.11.15-97.el6_10.i686.rpm | 148 kB 00:00
[updates: 3 of 1169 ] Downloading Packages/389-ds-base-devel-1.2.11.15-97.el6_10.x86_64.rpm
389-ds-base-devel-1.2.11.15-97.el6_10.x86_64.rpm | 148 kB 00:00
[updates: 4 of 1169 ] Downloading Packages/389-ds-base-libs-1.2.11.15-97.el6_10.i686.rpm
389-ds-base-libs-1.2.11.15-97.el6_10.i686.rpm | 450 kB 00:00
[updates: 5 of 1169 ] Downloading Packages/389-ds-base-libs-1.2.11.15-97.el6_10.x86_64.rpm
389-ds-base-libs-1.2.11.15-97.el6_10.x86_64.rpm | 446 kB 00:00
[updates: 6 of 1169 ] Downloading Packages/adcli-0.8.1-3.el6_10.x86_64.rpm
adcli-0.8.1-3.el6_10.x86_64.rpm | 100 kB 00:00
[updates: 7 of 1169 ] Downloading Packages/autofs-5.0.5-140.el6_10.1.x86_64.rpm
autofs-5.0.5-140.el6_10.1.x86_64.rpm | 730 kB 00:00
[updates: 8 of 1169 ] Downloading Packages/autofs-5.0.5-140.el6_10.x86_64.rpm
autofs-5.0.5-140.el6_10.x86_64.rpm | 730 kB 00:00
...
...
2.生成Yum源repodata索引依赖
[root@centos ~]# ll /var/www/html/centos6/ #查看从网络Yum源下载的所有RPM包(会根据仓库标识下载到相关的文件夹)
drwxr-xr-x 3 root root 4096 10月 31 14:28 extras
drwxr-xr-x 3 root root 4096 10月 31 14:28 os
drwxr-xr-x 3 root root 4096 10月 31 13:14 updates
[root@centos ~]# createrepo /var/www/html/centos6/extras/ #生成extras仓库的repodata索引依赖
Spawning worker 0 with 47 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@centos ~]# createrepo /var/www/html/centos6/os/ #生成os仓库的repodata索引依赖
Spawning worker 0 with 6713 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@centos ~]# createrepo /var/www/html/centos6/updates ##生成updates仓库的repodata索引依赖
Spawning worker 0 with 1169 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
3.在Packages同级目录中可以看到生成的repodata索引目录
[root@centos ~]# ll /var/www/html/centos6/extras/
drwxr-xr-x 2 root root 4096 10月 31 14:28 Packages
drwxr-xr-x 2 root root 4096 10月 31 17:02 repodata
[root@centos ~]# ll /var/www/html/centos6/os/
drwxr-xr-x 2 root root 491520 10月 31 14:59 Packages
drwxr-xr-x 2 root root 4096 10月 31 17:04 repodata
[root@centos ~]# ll /var/www/html/centos6/updates/
drwxr-xr-x 2 root root 102400 10月 31 13:41 Packages
drwxr-xr-x 2 root root 4096 10月 31 17:11 repodata
[root@centos ~]# ll /var/www/html/centos6/extras/repodata/
-rw-r--r-- 1 root root 15328 10月 31 17:02 1ed5ff978f03e8fcf39583179c7f9985dd8750070c91bbe7d1352352ccdd59ee-other.sqlite.bz2
-rw-r--r-- 1 root root 31139 10月 31 17:02 6da60a601f4110345fe68378f9d645de44fd0c15c69920d12158edb117ce6dca-primary.sqlite.bz2
-rw-r--r-- 1 root root 19175 10月 31 17:02 858ad62599b6ab53cec5925757610c9b0c27f9f945e10d83f73649907222b304-filelists.xml.gz
-rw-r--r-- 1 root root 15164 10月 31 17:02 a6e80104250eaf5059025683e2e1a20cfdc5be28ca826f777b5565133c6097e5-primary.xml.gz
-rw-r--r-- 1 root root 26118 10月 31 17:02 ae6f61c5aea047a4dca9ea8a04f9b1cac9a74c93fc97f1691fe109c8d0d07f26-filelists.sqlite.bz2
-rw-r--r-- 1 root root 9129 10月 31 17:02 dd8378435f46ef4730b55355947f224f69d1a16184ddbb4f3cf9aa6f2f459bfc-other.xml.gz
-rw-r--r-- 1 root root 2993 10月 31 17:02 repomd.xml
4.备份原Yum源配置文件,创建新Yum源配置文件
[root@centos ~]# vi /root/centos6.repo
[extras] #yum源的ID,本地唯一,用于区分不同yum源
name=extras #描述信息
baseurl=http://192.168.1.36/centos6/extras #前面的http://是协议,后面的/centos6/extras是yum源包路径
gpgcheck=0 #值为1表示用公钥验证rpm包的正确性,值为0表示不验证
enabled=1 #值为1表示启用yum源,值为0表示禁用yum源
[os]
name=extras
baseurl=http://192.168.1.36/centos6/os
gpgcheck=0
enabled=1
[updates]
name=uodates
baseurl=http://192.168.1.36/centos6/updates
gpgcheck=0
enabled=1
注意:baseurl 可以使用file 、ftp或http,目录路径要写到Package和repodata的目录。
测试验证自建的本地Yum源
[root@centos ~]# yum clean all
Cleaning repos: extras os updates
清理一切
Cleaning up list of fastest mirrors
[root@centos ~]# yum makecache
Determining fastest mirrors
extras | 2.9 kB 00:00
extras/filelists_db | 26 kB 00:00
extras/primary_db | 30 kB 00:00
extras/other_db | 15 kB 00:00
os | 2.9 kB 00:00
os/filelists_db | 6.4 MB 00:00
os/primary_db | 4.7 MB 00:00
os/other_db | 2.8 MB 00:00
updates | 3.0 kB 00:00
updates/filelists_db | 12 MB 00:00
updates/primary_db | 14 MB 00:00
updates/other_db | 697 kB 00:00
元数据缓存已建立
[root@centos ~]# yum repolist
Loading mirror speeds from cached hostfile
仓库标识 仓库名称 状态
extras extras 47
os extras 6,713
updates uodates 1,169
repolist: 7,929
可以看到我们基于RPM包来构建的本地Yum源已经完成了。
“点赞+评论+转发”,开启今日暴富!
相关推荐
- Linux 6.15将更新媒体子系统:高通Iris驱动首次亮相
-
IT之家3月24日消息,科技媒体phoronix昨日(3月23日)发布博文,报道称Linux6.15内核将于本周启动合并窗口,首批提交的PullRequest请求之一,就...
- Ubuntu 25.04发行版登场:Linux 6.14内核,带来多项技术革新
-
IT之家4月18日消息,科技媒体linuxiac昨日(4月17日)发布博文,报道称代号为PluckyPuffin的Ubuntu25.04发行版正式上线,搭载最新Linu...
- WordPress 6.8 版本发布:聚焦性能升级,代号“Cecil”
-
WordPress6.8版本发布:聚焦性能升级,代号“Cecil”全球最受欢迎的内容管理系统(CMS)WordPress正式推出最新版本6.8,代号“塞西尔”(Cecil),以此致敬传奇钢琴家...
- Linus Torvalds接受微软Hyper-V升级 下一代Linux启动会更快
-
虽然Windows的粉丝和Linux的粉丝经常喜欢进行激烈的键盘大战,但操作系统的制造商们自己也了解彼此的优缺点。毫无疑问,微软也明白这一点,事实上,它甚至鼓励用户尝试Linux,尽管是使用...
- Debian 12发布:Linux内核升级6.1(debian更新内核)
-
IT之家6月11日消息,Debian是最古老的GNU/Linux发行版之一,也是许多其他基于Linux的操作系统的基础,包括Ubuntu、Kali、MX和树莓派OS等。这...
- Linux Mint预告新功能:升级Nemo搜索、LMDE 7支持OEM安装
-
IT之家4月10日消息,LinuxMint发布了最新月度简讯,宣布增强Nemo文件管理器的文件搜索功能、Cinnamon桌面环境开始支持Wayland、LMDE7(LinuxM...
- Linux 6.2合并大量网络系统更新:推进Wi-Fi 7和800 Gbps网络
-
IT之家12月15日消息,Linux6.2合并窗口期内已经确认将会合并大量网络子系统更新。和以往版本相同,Linux6.2内核更新周期在网络功能上有大量的改进,更多的细节可以访问这条...
- Linux内核升级实践指南(linux内核怎么升级)
-
Linux内核升级是一个需要谨慎操作的过程,但掌握正确方法后可以显著提升系统性能、安全性或硬件兼容性。以下是一份详细的实践指南,涵盖主流方法及注意事项:一、准备工作查看当前内核版本bashuname...
- Linux又将迎来大版本更新 5.20版可能会被称为Linux 6.0
-
如果你错过了昨天Linux5.19的发布公告,那么这一消息需要回顾一下:被称为Linux5.20的开发中的内核很可能会被称为Linux6.0。根据LinusTorvalds对现代版本的划分,L...
- 周六的娱乐就是安装一台OracleLinux虚拟机(一)
-
每个人有每个人的娱乐方式。老父亲可能喜欢摆弄一些机械工具修修补补。我趁着周六安装一套OracleLinux,寓学于乐。在oracle网站上,下载VirtualBox,现在最新版本是7.0.8。在安装过...
- Linux系统下Gaussian 16的安装(linux系统如何安装新软件)
-
Gaussian是目前使用最多的量子化学计算软件,当前最新的版本为Gaussian16C.01。理论上来说Gaussian并不需要安装,因为高斯一般是不出售源代码的,只有二进制文件,以Gaussi...
- 「Linux基础」VMWare虚拟机安装CentOS后配置静态ip
-
在VMWare中安装本地虚拟机CentOS7操作系统,动态IP地址会经常变化,不便于管理与实验。为了便于实验,考虑设置成静态IP地址,目标是本地局域网可以通过NAT网关互相访问,且能连接互联网。由于是...
- Win10虚拟机,Hyper-V安装CentOS,一次成功
-
打开控制面板,选择程序选择启用或关闭Windows功能选中Hyper-V下所有的组件。提示我们需要,重启计算机,保存我们的文件,之后点击“立即重新启动”选择开始菜单,输入Hy,就可以打开虚拟机管理器了...
- 如何在Windows 10中的Hyper-V虚拟机上安装CentOS Linux
-
注意双重引导的一种可行且相当不错的替代方法是在虚拟机上安装各种操作系统。Microsoft正式支持CentOS作为Hyper-V的来宾OS,并且在安装时可以很好地集成。自CentOS6.4版以来,用...
- 安装Linux虚拟机的5个理由,以及不安装的5个原因
-
虚拟机(VM)允许你在不永久更改计算机的情况下探索Linux。如果你对Linux很好奇,但犹豫是否要尝试,VM提供了一个安全、灵活的解决方案。如果这是你第一次听说虚拟机,虚拟机就像“计算机中的计算机”...
- 一周热门
- 最近发表
-
- Linux 6.15将更新媒体子系统:高通Iris驱动首次亮相
- Ubuntu 25.04发行版登场:Linux 6.14内核,带来多项技术革新
- WordPress 6.8 版本发布:聚焦性能升级,代号“Cecil”
- Linus Torvalds接受微软Hyper-V升级 下一代Linux启动会更快
- Debian 12发布:Linux内核升级6.1(debian更新内核)
- Linux Mint预告新功能:升级Nemo搜索、LMDE 7支持OEM安装
- Linux 6.2合并大量网络系统更新:推进Wi-Fi 7和800 Gbps网络
- Linux内核升级实践指南(linux内核怎么升级)
- Linux又将迎来大版本更新 5.20版可能会被称为Linux 6.0
- 周六的娱乐就是安装一台OracleLinux虚拟机(一)
- 标签列表
-
- linux 远程 (37)
- u盘 linux (32)
- linux 登录 (34)
- linux 路径 (33)
- linux 文件命令 (35)
- linux 是什么 (35)
- linux 界面 (34)
- 查看文件 linux (35)
- linux 语言 (33)
- linux代码 (32)
- linux 查看命令 (33)
- 关闭linux (34)
- root linux (33)
- 删除文件 linux (35)
- linux 主机 (34)
- linux与 (33)
- linux 函数 (35)
- linux .ssh (35)
- cpu linux (35)
- 查看linux 系统 (32)
- linux 防火墙 (33)
- linux 手机 (32)
- linux 镜像 (34)
- linux mac (32)
- linux ip地址 (34)