前言: 由于公司业务服务器大部分都在内网环境下运行,内网环境无法直接使用yum安装升级更新软件,所以需要自建Yum源来满足目前日常工作需要。 YUM 常用命令参数: yum makecache
由于公司业务服务器大部分都在内网环境下运行,内网环境无法直接使用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 #显示指定程序包安装情况nginxyum remove httpd #删除程序包nginxyum erase httpd #删除程序包httpdyum update httpd #升级httpd 服务yum clean all #清除缓存目录下的软件包及旧的 headers
1.添加YUM源配置文件
[root@Centos ~]# cat /etc/yum.repos.d/iso.repo [iOS]name=isobaseurl=file:///mntenabled=1gpGCheck=0gpgkey=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% /devtmpfs 912M 9.0M 903M 1% /runtmpfs 912M 0 912M 0% /sys/fs/cgroup/dev/sda2 197M 121M 77M 62% /boottmpfs 183M 0 183M 0% /run/user/0dev/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
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 47os Qcloud centos os - x86_64 6,713updates Qcloud centos updates - x86_64 1,169repolist: 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.rpmbakefile-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.rpmcentos-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.rpmcentos-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.rpmcentos-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.rpmcentos-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.rpmcentos-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.rpm389-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.rpm389-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.rpm389-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.rpm389-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.rpm389-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.rpmadcli-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.rpmautofs-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.rpmautofs-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 extrasdrwxr-xr-x 3 root root 4096 10月 31 14:28 osdrwxr-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 pkgsWorkers FinishedGathering worker resultsSaving Primary metadataSaving file lists metadataSaving other metadataGenerating sqlite DBsSqlite DBs complete[root@centos ~]# createrepo /var/www/html/centos6/os/ #生成os仓库的repodata索引依赖Spawning worker 0 with 6713 pkgsWorkers FinishedGathering worker resultsSaving Primary metadataSaving file lists metadataSaving other metadataGenerating sqlite DBsSqlite DBs complete[root@centos ~]# createrepo /var/www/html/centos6/updates ##生成updates仓库的repodata索引依赖Spawning worker 0 with 1169 pkgsWorkers FinishedGathering worker resultsSaving Primary metadataSaving file lists metadataSaving other metadataGenerating sqlite DBsSqlite DBs complete
3.在Packages同级目录中可以看到生成的repodata索引目录
[root@centos ~]# ll /var/www/html/centos6/extras/drwxr-xr-x 2 root root 4096 10月 31 14:28 Packagesdrwxr-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 Packagesdrwxr-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 Packagesdrwxr-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=extrasbaseurl=http://192.168.1.36/centos6/osgpgcheck=0enabled=1[updates]name=uodatesbaseurl=http://192.168.1.36/centos6/updatesgpgcheck=0enabled=1
注意:baseurl 可以使用file 、ftp或http,目录路径要写到Package和repodata的目录。
[root@centos ~]# yum clean allCleaning repos: extras os updates清理一切Cleaning up list of fastest mirrors[root@centos ~]# yum makecacheDetermining fastest mirrorsextras | 2.9 kB 00:00extras/filelists_db | 26 kB 00:00extras/primary_db | 30 kB 00:00extras/other_db | 15 kB 00:00os | 2.9 kB 00:00os/filelists_db | 6.4 MB 00:00os/primary_db | 4.7 MB 00:00os/other_db | 2.8 MB 00:00updates | 3.0 kB 00:00updates/filelists_db | 12 MB 00:00updates/primary_db | 14 MB 00:00updates/other_db | 697 kB 00:00元数据缓存已建立[root@centos ~]# yum repolistLoading mirror speeds from cached hostfile仓库标识 仓库名称 状态extras extras 47os extras 6,713updates uodates 1,169repolist: 7,929
可以看到我们基于RPM包来构建的本地Yum源已经完成了。
【非著名运维】 --》 公众号回复 “资料” 送运维自学资料大礼包哦!
上面也会分享一些运维知识,大家点点发财手关注一波,感谢大家。
来源地址:https://blog.csdn.net/qq_44895681/article/details/127617155
--结束END--
本文标题: 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
本文链接: https://lsjlt.com/news/442366.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0