基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)

简介: 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)

1.png

前言:


 由于公司业务服务器大部分都在内网环境下运行,内网环境无法直接使用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源已经完成了。


目录
打赏
0
0
0
0
12
分享
相关文章
【Linux】vim使用与配置教程
Vim是一款功能强大的文本编辑器,广泛应用于Linux环境,是开发者和系统管理员的必备工具。本文介绍了Vim的基本操作与简单配置,涵盖命令模式、插入模式和底行模式的使用方法,以及光标定位、复制粘贴、搜索替换等常用技巧。同时,文章还提供了实用的分屏操作和代码注释方法,并分享了通过`.vimrc`文件进行个性化配置(如显示行号、语法高亮、自动缩进等)的技巧,帮助用户提升文本编辑效率。掌握这些内容,能让Vim更好地服务于日常工作与开发需求。
86 3
在Rocky Linux 9上安装JDK并配置环境变量!
本教程介绍在Rocky Linux 9上安装JDK并配置环境变量的完整步骤。首先更新系统,清理旧版本JDK相关包及残留文件,确保环境干净。接着搜索并安装所需版本的JDK(如OpenJDK 17),验证安装是否成功。然后查找JDK安装路径,配置全局环境变量`JAVA_HOME`和`PATH`,最后验证环境变量设置。按照此流程操作,可顺利完成Java开发环境搭建,支持多版本切换(如JDK 8/11/17)。生产环境请谨慎操作,避免影响现有服务。
84 21
Android调试终极指南:ADB安装+多设备连接+ANR日志抓取全流程解析,覆盖环境变量配置/多设备调试/ANR日志分析全流程,附Win/Mac/Linux三平台解决方案
ADB(Android Debug Bridge)是安卓开发中的重要工具,用于连接电脑与安卓设备,实现文件传输、应用管理、日志抓取等功能。本文介绍了 ADB 的基本概念、安装配置及常用命令。包括:1) 基本命令如 `adb version` 和 `adb devices`;2) 权限操作如 `adb root` 和 `adb shell`;3) APK 操作如安装、卸载应用;4) 文件传输如 `adb push` 和 `adb pull`;5) 日志记录如 `adb logcat`;6) 系统信息获取如屏幕截图和录屏。通过这些功能,用户可高效调试和管理安卓设备。
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
190 25
|
2月前
|
问题记录:解决Linux登录故障,/etc/passwd配置受损该怎么操作
修复/etc/passwd文件是解决Linux登录故障的重要步骤。通过进入单用户模式、挂载文件系统、恢复或手动修复/etc/passwd文件,可以有效解决该问题。保持定期备份系统配置文件是预防此类问题的最佳实践。
74 13
|
2月前
|
问题记录:解决Linux登录故障,/etc/passwd配置受损该怎么操作
修复/etc/passwd文件是解决Linux登录故障的重要步骤。通过进入单用户模式、挂载文件系统、恢复或手动修复/etc/passwd文件,可以有效解决该问题。保持定期备份系统配置文件是预防此类问题的最佳实践。
76 5
|
4月前
|
Linux网络文件系统NFS:配置与管理指南
NFS 是 Linux 系统中常用的网络文件系统协议,通过配置和管理 NFS,可以实现跨网络的文件共享。本文详细介绍了 NFS 的安装、配置、管理和常见问题的解决方法,希望对您的工作有所帮助。通过正确配置和优化 NFS,可以显著提高文件共享的效率和安全性。
412 7
Linux下ODBC与 南大通用GBase 8s数据库的无缝连接配置指南
本文详细介绍在Linux系统下配置GBase 8s数据库ODBC的过程,涵盖环境变量设置、ODBC配置文件编辑及连接测试等步骤。首先配置数据库环境变量如GBASEDBTDIR、PATH等,接着修改odbcinst.ini和odbc.ini文件,指定驱动路径、数据库名称等信息,最后通过catalog.c工具或isql命令验证ODBC连接是否成功。
深入探索Linux操作系统的心脏——内核配置与优化####
本文作为一篇技术性深度解析文章,旨在引领读者踏上一场揭秘Linux内核配置与优化的奇妙之旅。不同于传统的摘要概述,本文将以实战为导向,直接跳入核心内容,探讨如何通过精细调整内核参数来提升系统性能、增强安全性及实现资源高效利用。从基础概念到高级技巧,逐步揭示那些隐藏在命令行背后的强大功能,为系统管理员和高级用户打开一扇通往极致性能与定制化体验的大门。 --- ###
134 9
【Linux】另一种基于rpm安装yum的方式
通过本文的方法,您可以在离线环境中使用RPM包安装YUM并进行必要的配置。这种方法适用于无法直接访问互联网的服务器或需要严格控制软件源的环境。通过配置本地YUM仓库,确保了软件包的安装和更新可以顺利进行。希望本文能够为您在特定环境中部署YUM提供实用的指导。
470 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等