# linuxYum **Repository Path**: xiaoxinbupa/linux-yum ## Basic Information - **Project Name**: linuxYum - **Description**: linux中最伟大的功能YUM - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-08-13 - **Last Updated**: 2024-08-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: 学习笔记 ## README typora-root-url: https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture typora-copy-images-to: linux_base_picture author: xiaoxinbupai mail:1569494071@qq.com # linuxYum ## 介绍 linux中安装软件是一个技术活,那就离不开最伟大的YUM--yellow dog ## rpm软件包 ![image-20240506110938866](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506110938866.png) ### RPM---Redhat Package Manager RPM是由红帽公司提出,Redhat、SUSE等系列采用 RPM包文件名特征 -软件包-版本信息 .操作系统 .硬件架构.rpm -fiefox - 91.9.0-1 .el8_5 .x86_64 操作系统:e代表企业版,l代表linux ![image-20240506111647636](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506111647636.png) 特点: 安装位置锁死、安装位置分散 ![image-20240506113211144](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506113211144.png) ### rpm--指令 ``` -a:查询所有套件; -b<完成阶段><套件档>+或-t <完成阶段><套件档>+:设置包装套件的完成阶段,并指定套件档的文件名称; -c:只列出组态配置文件,本参数需配合"-l"参数使用; -d:只列出文本文件,本参数需配合"-l"参数使用; -e<套件档>或--erase<套件档>:删除指定的套件; -f<文件>+:查询拥有指定文件的套件; -h或--hash:套件安装时列出标记; -i (information):显示套件的相关信息; -i<套件档>或--install<套件档>:安装指定的套件档; -l:(list)显示套件的文件列表; -p<套件档>+:查询指定的RPM套件档; -q:使用询问模式,当遇到任何问题时,rpm指令会先询问用户; -R:显示套件的关联性信息; -s:显示文件状态,本参数需配合"-l"参数使用; -U<套件档>或--upgrade<套件档>:升级指定的套件档; -v:显示指令执行过程; -vv:详细显示指令执行过程,便于排错。 ``` #### rpm -q 软件名 查询软件名是否被安装 ![image-20240506115033620](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506115033620.png) #### rpm -qa 查询当前系统已经安装的软件包 ![image-20240506114900723](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506114900723.png) #### rpm -qi 软件名 查询软件(已经安装)的信息 ![image-20240506115305699](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506115305699.png) #### rpm -ql 软件名 查询软件(已经安装)在系统中安装了的信息清单。 ![image-20240506115417674](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506115417674.png) #### rpm -qf 文件路径 查询软件是由哪个rpm包所产生的 f--指的是father ![image-20240506120019619](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506120019619.png) ![image-20240506120305220](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506120305220.png) [ 补充说明: which + 指令 指令由那个程序带来、显示命令路径] ![img](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/af3a7ad957514c0bae074396ebec7fe7.png)![点击并拖拽以移动](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==)编辑 #### rpm -qpi rpm文件 查询RPM软件包的详细信息![image-20240506141848129](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506141848129.png) #### rpm -qpl rpm文件 查询RPM软件包的文件安装清单 ![image-20240506141945176](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506141945176.png) #### rpm -ivh rpm文件 安装rpm文件并显示安装的过程 -v:显示安装细节 (v=verbose) -h:以#号显示安装进度(h=hase) ![image-20240506143509070](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506143509070.png) #### rpm -evh 软件名 卸载rpm文件并显示卸载的过程 ![image-20240506143558919](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506143558919.png) ### rpm小结 ``` 1.查询已安装的软件包  rpm    -q(子选项)  (1)查询已安装软件包信息     1)格式: which  指令   (指令由那个程序带来) 2)格式:rpm    -qf     软件名  (查询程序由那个软件包带来) (2)格式:rpm   -qi    软件名   (查询指定软件包的详细信息) (3)格式:rpm   -ql   软件名  (查看指定文化i菜软件的文件安装清单) (4)格式:rpm    -qa       (列出类似已安装所有软件包) 2.查询未安装的软件包 (1)格式:rpm   -qpi    完整路径和包名(查看指定软件的详细信息) (2)格式:rpm   -qpl     完整路径和包名(查看指定软件的文件安装清单) 3.软件包是否安装  rpm    -q     软件包 (1)已安装: 1)[root@localhost ~]# rpm   -q    vsftpd 2)vsftpd-3.0.2-22.el7.x86_64 (2)未安装: 1)[root@localhost ~]# rpm   -q    httpd 2)未安装软件包 httpd  3)例如:[root@localhost ~]# rpm  -q   httpd   查询软件是否安装 4.安装软件包 (1)[root@localhost ~]# rpm    -ivh     /dvd/Packages/vsftpd-3.0.2-22.el7.x86_64.rpm  (2)强制安装:[root@localhost ~]# rpm    -ivh  --force     /dvd/Packages/vsftpd-3.0.2-22.el7.x86_64.rpm  5.卸载软件包 (1)[root@localhost ~]# rpm    -evh    vsftpd ``` ## yum软件仓库 ### yum--Yellowdog Updater Modified ---基于rpm包构建的软件更新机制 ​ 目的是为了解决安装单个rpm文件需要安装各种依赖。 ​ 解决依赖的方法: - ​ 1、先安装or卸载要求的包 - ​ 2、忽略依赖关系,强制安装(不推荐)会导致软件运行异常 - ​ 3、yum进行安装会自动安装依赖 ---自动解决软件包依赖关系 ---所有软件包游集中的yum软件仓库提供 **服务端(本机): 1.众多的软件 2.仓库数据文件(repodata)** 将所有需要的软件包同统一放在一个目录下,该目录可以通过ftp、http、https、file将需要使用软件的客户端传输需要的软件 本地Yum仓库:服务端需要有光盘内容即可 **客户端(本机):指定服务端位置** 客户端的配置非常简单,只要配置要一些基本的参数,就可以通过客户端来安装软件,并且解决软件包的依赖性。 仓库配置文件:/etc/yum.repos.d/*.repo 错误的文件会影响正确的文件 ![image-20240506154718422](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506154718422.png) ### 书写仓库配置文件 ![image-20240506161942464](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506161942464.png) **客户端文件配置内容** 全局配置: /etc/yum.conf - cachedir:软件包缓存目录 keepcache:缓存是否保存,1保存0不保存 debuglevel:调试级别(默认为2) logfile:日志文件路径 gpgcheck:是否检查密钥,一种检验软件完整性的方式 仓库配置: /etc/yum.repos.d/ [自定义].repo 1. [源名称] :自定义名称,具有唯一性,不能带有特殊符号 2. name:本软件源的描述字串 3. baseurl:指定YUM服务端的URL地址 4. enabled:是否启用此频道 5. gpgcheck:是否验证待安装的RPM包 6. gpgkey:用于RPM软件包验证的密钥文件 ![image-20240506162105038](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506162105038.png) ![image-20240506161502600](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506161502600.png) yum repoinfo ---可以来显示配置仓库的信息 ![image-20240506161706575](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506161706575.png) ### yum安装或者卸载软件 格式【语法】: yum [-y] 指令 [软件名]... 常用指令 install (安装)、remove(移除,建议不加-y) 1、yum -y install httpd ![image-20240506163343638](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506163343638.png) 2、yum remove httpd ![image-20240506163500334](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506163500334.png) ### yum命令 #### **1.启用与禁用仓库** 禁用仓库:`yum-config-manager --disable “仓库名"` 启用仓库:`yum-config-manager --enable “仓库名”` #### **2.显示软件仓库列表** `yum repolist` ![image-20240506171548992](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506171548992.png) #### **3.显示和查找软件包** yum list 查询所有已安装和可安装的软件包 ![image-20240506171453895](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506171453895.png) `yum list` 软件包名 查询执行软件包的安装情况 ![image-20240506171822136](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506171822136.png) yum search 关键词 在yum源中查找与ftp字段相匹配的字段,并展示出来 ![image-20240506171920831](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240506171920831.png) #### **4.安装卸载与更新** 安装:`yum install package1 package2...` 重新安装:`yum reinstall package` 卸载:`yum remove package` 更新:`yum update package` 降级:`yum downgrage package` 检查可用的更新:`yum check-update` #### **5.缓存命令** 清除缓存:`yum clean all` 构建缓存:`yum makecache` #### **6.查看依赖性** `yum deplist package1` #### **7.包组相关命令** - 安装:`yum groupinstall group1 [group2] [...]` - 更新`yum groupupdate group1 [group2] [...]` - 列表`yum grouplist [hidden] [groupwildcard] [...]` - 删除`yum groupremove group1 [group2] [...]` - 信息`yum groupinfo group1 [...]` ### 自定义构建YUM仓库 •将自己下载的RPM包,构建为Yum仓库 •完整Yum仓库:1.众多的软件包 2.仓库数据文件(仓库清单) •第一阶段 tools.tar.gz •真机将tools.tar.gz传递到虚拟机A的/root目录下 真机传递数据到虚拟机 真机为Linux:真机上进行操作 ``` [student@server1 ~]$ ls /linux-soft/s1[student@server1 ~]$ scp /linux-soft/s1/tools.tar.gz root@192.168.88.240:/root ``` 真机为windows:windterm软件,效果如图-1、图-2所示。 ![image-20240520181931629](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240520181931629.png) 图-1 ![image-20240520182002929](https://gitee.com/xiaoxinbupa/linux-note/raw/master/linux_base_picture/image-20240520182002929.png) 图-2 虚拟机A ```bash [root@server ~]# ls /root [root@server ~]# tar -tf /root/tools.tar.gz [root@server ~]# tar -xf /root/tools.tar.gz -C / [root@server ~]# ls /[root@server ~]# ls /tools/ [root@server ~]# ls /tools/other/ ``` 虚拟机A ```bash [root@server ~]# createrepo /tools/other #生成仓库数据文件 [root@server ~]# ls /tools/other/ [root@server ~]# vim /etc/yum.repos.d/mydvd.repo ……此处省略一万字 [myrpm] #唯一标识 baseurl=file:///tools/other #指定Yum仓库的路径 gpgcheck=0 [root@server ~]# yum repoinfo [root@server ~]# yum -y install sl #测试软件安装 [root@server ~]# yum -y install cmatrix ``` #### 自定义Yum仓库的更新:更新的顺序不能颠倒 1. 仓库数据文件的更新 2. Yum仓库缓存的更新(每台机器都要进行) 【作为一个yum,库源文件必须要有rpm包、repodata仓库信息单】 ```bash 虚拟机A: [root@server ~]# mv /tools/other/sl-5.02-1.el7.x86_64.rpm /root [root@server ~]# ls /tools/other/ [root@server ~]# createrepo --update /tools/other #更新仓库数据文件 [root@server ~]# yum makecache #更新缓存数据 [root@server ~]# yum repoinfo ``` ### 网络Yum仓库(FTP/Httpd/NFS) 网络Yum仓库: - 虚拟机A:提供仓库内容(构建网络服务,提供仓库内容) - 虚拟机B:进行访问仓库内容 - 虚拟机B运行yum--->仓库配置文件--->访问虚拟机A的==ftp/http/nfs==服务提供仓库内容 - 虚拟机C运行yum--->仓库配置文件--->访问虚拟机A的==ftp/http/nfs==服务提供仓库内容 #### 基于FTP为源搭建YUM仓库 **虚拟机A:提供仓库内容(FTP服务)** ```bash 1.构建FTP服务 [root@server ~]# yum -y install vsftpd [root@server ~]# vim /etc/vsftpd/vsftpd.conf anonymous_enable=YES #开启无需密码验证功能 [root@server ~]# systemctl restart vsftpd #重启服务 [root@server ~]# systemctl enable vsftpd #设置开机自启 Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service. 2.通过FTP提供仓库内容 [root@server ~]# cp -r /tools/other /var/ftp/rpms ``` **虚拟机B:进行访问仓库内容** ```bash [root@pc2 ~]# vim /etc/yum.repos.d/mydvd.repo ……此处省略一万字 [haha] baseurl=ftp://192.168.88.240/rpms gpgcheck=0 [root@pc2 ~]# yum clean all #清空Yum的缓存 [root@pc2 ~]# yum repoinfo ``` **虚拟机A:提供仓库内容(FTP服务)** ```bash [root@server ~]# mkdir /var/ftp/dvd [root@server ~]# mount /dev/cdrom /var/ftp/dvd [root@server ~]# curl ftp://192.168.88.240/dvd/ [root@server /]# vim /etc/fstab #修改配置 /dev/cdrom /var/ftp/dvd iso9660 defaults 0 0 [root@server /]# umount /var/ftp/dvd [root@server /]# ls /var/ftp/dvd [root@server /]# mount -a mount: /dev/sr0 写保护,将以只读方式挂载 [root@server /]# ls /var/ftp/dvd ........ [root@server /]# vim /etc/yum.repos.d/mydvd.repo [aa] baseurl=ftp://192.168.88.240/dvd/AppStream gpgcheck=0 [bb] baseurl=ftp://192.168.88.240/dvd/BaseOS gpgcheck=0 [myrpm] baseurl=ftp://192.168.88.240/rpms gpgcheck=0 [root@server ~]# yum clean all #清空Yum的缓存 [root@server ~]# yum repoinfo ``` **虚拟机B:进行访问仓库内容** ```bash [root@pc2 ~]# vim /etc/yum.repos.d/mydvd.repo [aa] baseurl=ftp://192.168.88.240/dvd/AppStream gpgcheck=0 [bb] baseurl=ftp://192.168.88.240/dvd/BaseOS gpgcheck=0 [myrpm] baseurl=ftp://192.168.88.240/rpms gpgcheck=0 [root@pc2 ~]# yum clean all #清空Yum的缓存 [root@pc2 ~]# yum repoinfo ``` **拍摄快照:虚拟机A关闭机器拍摄快照,快照名字为"网络Yum仓库完成"** #### 基于Httpd为源搭建YUM仓库 **虚拟机A:提供仓库内容(Web服务)** ```bash 1.构建Web服务 [root@server ~]# yum -y install httpd [root@server ~]# systemctl restart httpd [root@server ~]# systemctl enable httpd 2.通过Web提供仓库内容 [root@server ~]# mkdir /var/www/html/dvd [root@server ~]# mount /dev/cdrom /var/www/html/dvd ``` **虚拟机B:进行访问仓库内容** ```bash [root@pc2 ~]# vim /etc/yum.repos.d/mydvd.repo [aa] baseurl=http://192.168.88.240/dvd/AppStream gpgcheck=0 [bb] baseurl=http://192.168.88.240/dvd/BaseOS gpgcheck=0 [root@pc2 ~]# yum repoinfo ``` **虚拟Web主机:** ```bash [root@server ~]# vim /etc/httpd/conf.d/nsd01.conf ServerName www.qq.com DocumentRoot /var/www/qq ServerName www.baidu.com DocumentRoot /var/www/baidu Options Indexes FollowSymLinks #显示目录内容 [root@server ~]# mkdir /var/www/qq /var/www/baidu [root@server ~]# echo wo shi QQ > /var/www/qq/index.html [root@server ~]# echo wo shi baidu > /var/www/baidu/index.html [root@server ~]# systemctl restart httpd [root@server ~]# mkdir /var/www/qq/dvd [root@server ~]# mount /dev/cdrom /var/www/qq/dvd ``` #### 基于NFS为源搭建YUM仓库 NFS挂载后在baseurl指定挂载目录