yum简介
1.基于RPM包构建的软件更新机制
2.可以自动解决依赖关系
3.所有软件包由yum软件仓库提供
yum工作原理
yum主配置文件
[root@localhost ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever #yum下载的RPM包的缓存目录 $basearch代表硬件架构 $releasever系统版本比如7
keepcache=0 #是否保存缓存 0代表不保存,1代表保存
debuglevel=2 #调试级别了解即可
logfile=/var/log/yum.log #日志文件位置
exactarch=1 #是否允许不同版本的rpm安装
obsoletes=1 #update 的一个参数是否可以允许旧版本的运行
gpgcheck=1 #验证秘钥
plugins=1 #是否允许插件1代表可以
installonly_limit=5 #保存几个内核 5代表5个
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
仓库设置文件
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-Media.repo
CentOS-Debuginfo.repo CentOS-Sources.repo
日志文件
[root@localhost ~]# cat /var/log/yum.log
Mar 04 15:08:01 Updated: httpd-tools-2.4.6-99.el7.centos.1.x86_64
Mar 04 15:08:01 Installed: mailcap-2.1.41-2.el7.noarch
Mar 04 15:08:02 Installed: httpd-2.4.6-99.el7.centos.1.x86_64
Mar 08 16:34:07 Updated: libcom_err-1.42.9-19.el7.x86_64
Mar 08 16:34:07 Updated: zlib-1.2.7-21.el7_9.x86_64
Mar 08 16:34:07 Updated: libgcc-4.8.5-44.el7.x86_64
Mar 08 16:34:08 Updated: libsepol-2.5-10.el7.x86_64
Mar 08 16:34:08 Updated: libselinux-2.5-15.el7.x86_64
Mar 08 16:34:08 Updated: 1:openssl-libs-1.0.2k-26.el7_9.x86_64
Mar 08 16:34:08 Updated: krb5-libs-1.15.1-55.el7_9.x86_64
yum安装和升级
[root@localhost ~]# yum install tree -y #第一次是安装
[root@localhost ~]# yum install tree -y #软件已安装则更新版本
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.ustc.edu.cn* extras: mirrors.ustc.edu.cn* updates: mirrors.ustc.edu.cn
软件包 tree-1.6.0-10.el7.x86_64 已安装并且是最新版本
无须任何处理
查询
显示可用的安装包
yum list
[root@localhost ~]# yum list tree
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.ustc.edu.cn* extras: mirrors.ustc.edu.cn* updates: mirrors.ustc.edu.cn
已安装的软件包
tree.x86_64 1.6.0-10.el7 @base
显示指定安装包详细信息
yum info
[root@localhost ~]# yum info tree
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.ustc.edu.cn* extras: mirrors.ustc.edu.cn* updates: mirrors.ustc.edu.cn
已安装的软件包
名称 :tree
架构 :x86_64
版本 :1.6.0
发布 :10.el7
大小 :87 k
源 :installed
来自源:base
简介 : File system tree viewer
网址 :http://mama.indstate.edu/users/ice/tree/
协议 : GPLv2+
描述 : The tree utility recursively displays the contents of: directories in a tree-like format. Tree is basically: a UNIX port of the DOS tree utility.
根据关键字查找软件安装包
yum search 只要包含这个关键字就会全部匹配出来
[root@localhost ~]# yum search tre
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
======================= N/S matched: ftp ========================
ftp.x86_64 : The standard UNIX FTP (File Transfer Protocol): client
lftp-scripts.noarch : Scripts for lftp
syslinux-tftpboot.noarch : SYSLINUX modules in /var/lib/tftpboot,: available for network booting
tftp.x86_64 : The client for the Trivial File Transfer Protocol: (TFTP)
tftp-server.x86_64 : The server for the Trivial File Transfer: Protocol (TFTP)
vsftpd.x86_64 : Very Secure Ftp Daemon
vsftpd-sysvinit.x86_64 : SysV initscript for vsftpd daemon
curl.x86_64 : A utility for getting files from remote servers: (FTP, HTTP, and others)
lftp.i686 : A sophisticated file transfer program
lftp.x86_64 : A sophisticated file transfer program
wget.x86_64 : A utility for retrieving files using the HTTP or: FTP protocols
根据命令名字查找对应的软件包
yum provides
[root@localhost ~]# yum provides tree
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.ustc.edu.cn* extras: mirrors.ustc.edu.cn* updates: mirrors.ustc.edu.cn
tree-1.6.0-10.el7.x86_64 : File system tree viewer
源 :basetree-1.6.0-10.el7.x86_64 : File system tree viewer
源 :@base
查询安装包组
yum grouplist 安装包组的查询 不加包组名 就是显示所有
[root@localhost ~]# yum grouplist
已加载插件:fastestmirror, langpacks
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile* base: mirrors.ustc.edu.cn* extras: mirrors.ustc.edu.cn* updates: mirrors.ustc.edu.cn
可用的环境分组:最小安装基础设施服务器计算节点文件及打印服务器基本网页服务器虚拟化主机带 GUI 的服务器GNOME 桌面KDE Plasma Workspaces开发及生成工作站
可用组:传统 UNIX 兼容性兼容性程序库图形管理工具安全性工具开发工具控制台互联网工具智能卡支持科学记数法支持系统管理系统管理工具
完成
卸载
yum remove
[root@localhost ~]# yum remove tree
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 删除
--> 解决依赖关系完成依赖关系解决=================================================================Package 架构 版本 源 大小
=================================================================
正在删除:tree x86_64 1.6.0-10.el7 @base 87 k事务概要
=================================================================
移除 1 软件包安装大小:87 k
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在删除 : tree-1.6.0-10.el7.x86_64 1/1 验证中 : tree-1.6.0-10.el7.x86_64 1/1 删除:tree.x86_64 0:1.6.0-10.el7 完毕!
yum history
查看历史的使用记录
[root@localhost ~]# yum history
已加载插件:fastestmirror, langpacks
ID | 登录用户 | 日期和时间 | 操作 | 变更数
-------------------------------------------------------------------------------8 | root <root> | 2024-05-05 16:05 | Erase | 1 7 | root <root> | 2024-05-05 15:28 | Install | 1 6 | root <root> | 2024-05-05 13:46 | Install | 1 5 | root <root> | 2024-05-05 11:06 | Update | 1 4 | root <root> | 2024-05-05 01:11 | I, U | 9 3 | root <root> | 2024-03-08 16:34 | I, U | 34 <2 | root <root> | 2024-03-04 15:08 | I, U | 3 ><1 | 系统 <空> | 2024-02-29 20:56 | Install | 1372 >
history list
可以使用yum history undo 6 卸载第6条对比remove这样可以将所有依赖都删除
[root@localhost ~]# yum history undo 6
已加载插件:fastestmirror, langpacks
Undoing transaction 6, from Sun May 5 13:46:19 2024安装 vsftpd-3.0.2-29.el7_9.x86_64 @updates
正在解决依赖关系
--> 正在检查事务
---> 软件包 vsftpd.x86_64.0.3.0.2-29.el7_9 将被 删除
--> 解决依赖关系完成依赖关系解决==================================================================Package 架构 版本 源 大小
==================================================================
正在删除:vsftpd x86_64 3.0.2-29.el7_9 @updates 353 k事务概要
==================================================================
移除 1 软件包安装大小:353 k
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在删除 : vsftpd-3.0.2-29.el7_9.x86_64 1/1 验证中 : vsftpd-3.0.2-29.el7_9.x86_64 1/1 删除:vsftpd.x86_64 0:3.0.2-29.el7_9 完毕!
搭建本地yum仓库
挂载
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
备份yum网络
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv *.repo bak
[root@localhost yum.repos.d]# ls
bak
新建配置文件
[root@localhost yum.repos.d]# vim local.repo
[local]
name=local
baseurl=file:///mnt #提供仓库的路径,这里是本地源,也可以是存放源的网站
gpgcheck=0 #是否开启校验位这里0代表关闭校验位
清除yum缓存
yum clean all
建立本地源·
yum makecache
使用http搭建yum仓库
服务端配置
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# mount /dev/sr0 /var/www/html
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl status httpd
客户端配置
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv *.repo bak
[root@localhost yum.repos.d]# vim http.repo
[httpd]
name=http
baseurl=http://192.168.118.20
gpgcheck=0
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache
[root@localhost yum.repos.d]# yum install tree -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 安装
--> 解决依赖关系完成依赖关系解决=======================================================================================Package 架构 版本 源 大小
=======================================================================================
正在安装:tree x86_64 1.6.0-10.el7 http 46 k 事务概要
=======================================================================================
安装 1 软件包总下载量:46 k
安装大小:87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装 : tree-1.6.0-10.el7.x86_64 1/1 验证中 : tree-1.6.0-10.el7.x86_64 1/1 已安装:tree.x86_64 0:1.6.0-10.el7 完毕!
| 46 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : tree-1.6.0-10.el7.x86_64 1/1
验证中 : tree-1.6.0-10.el7.x86_64 1/1
已安装:
tree.x86_64 0:1.6.0-10.el7
完毕!