YUM基本介绍
1.什么是YUM
Yum是RedHat以及CentOS中的软件包管理器。能够通过互联网下载 .rpm 包并且安装,并可以自动处理依赖性关系,无须繁琐地一次次下载、安装。(PS: YUM是生产最佳实践)
2.YUM源是什么
1要成功的使用 YUM 工具安装更新软件或系统,就需要有一个包含各种 rpm 软件包的repository(软件仓库),这个软件仓库我们习惯称为 yum 源。(可以是本地源、网络源)
3.YUM源配置实例
1.阿里yum源
#默认系统是国外源,需要替换为国内的源
[root@www.xuliangwei.com ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#扩展源,有很多软件在基本源中没有
[root@www.xuliangwei.com ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2.Nginx官方源,比如在学习Nginx时需要使用官方的yum源来安装
[root@www.xuliangwei.com ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
PS:源超找方式基本一致,zabbix,Docker、Nginx、saltstack、openstack
4.YUM实践案例
1.使用yum查询软件包的方式
[root@www.xuliangwei.com ~]# yum list
[root@www.xuliangwei.com ~]# yum list|grep ftp
[root@www.xuliangwei.com ~]# yum info ftp
2.使用yum安装软件包的方式
[root@www.xuliangwei.com ~]# yum install tree
[root@www.xuliangwei.com ~]# yum install tree -y #非交互
#安装本地的rpm包, 如果有依赖关系, 会自动从软件仓库中下载所需依赖
[root@www.xuliangwei.com ~]# yum localinstall /mnt/Packages/bind-9.9.4-50.el7.x86_64.rpm
#直接安装网络上的rpm包
[root@www.xuliangwei.com ~]# yum install http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
3.使用yum重新安装软件包的方式
#1.如果不小心删除vsftpd配置文件
[root@www.xuliangwei.com ~]# rm -f /etc/vsftpd/vsftpd.conf
#2.可以对软件进行重新安装
[root@www.xuliangwei.com ~]# yum reinstall vsftpd
#3.检查软件的配置文件
[root@www.xuliangwei.com ~]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
3.使用yum更新软件包
#对比Linux已安装的软件和yum仓库中的软件, 有哪些需要升级
[root@www.xuliangwei.com ~]# yum check-update
#更新acl软件
[root@www.xuliangwei.com ~]# yum update acl -y
#如下的执行很危险,这代表更新整个系统所有的软件,包括内核
[root@www.xuliangwei.com ~]# yum update -y
4.使用yum删除软件包
[root@www.xuliangwei.com ~]# yum install samba -y
[root@www.xuliangwei.com ~]# yum erase samba -y
[root@www.xuliangwei.com ~]# yum remove samba -y
5.与yum仓库相关指令(扩展了解)
#列出yum源可用的软件仓库
[root@www.xuliangwei.com ~]# yum repolist
#列出全部yum源可用和禁用的仓库
[root@www.xuliangwei.com ~]# yum repolist all
#查找某个命令或文件属于那个软件包(生产常用)
[root@www.xuliangwei.com ~]# yum provides /etc/my.cnf
[root@www.xuliangwei.com ~]# yum provides cd
6.与yum缓存相关指令(扩展了解)
#1.缓存rpm包方式一、修改yum全局配置文件
[root@www.xuliangwei.com ~]# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1 #启动缓存
#2.缓存rpm包方式二,只下载不安装
[root@www.xuliangwei.com ~]# yum install -y yum-plugin-downloadonly #插件
[root@www.xuliangwei.com ~]# yum install httpd -y --downloadonly --downloaddir=/tmp
#3.清除所有yum缓存的软件包以及元数据
[root@www.xuliangwei.com ~]# yum clean all
#4.只清除缓存的软件包
[root@www.xuliangwei.com ~]# yum clean packages
7.组包相关指令,(扩展了解)
[root@www.xuliangwei.com ~]# yum groups list
#安装一整个组的软件
[root@xuliangwei ~]# yum groups install Development tools Compatibility libraries Base Debugging Tools
#yum删除包组
[root@www.xuliangwei.com ~]# yum groups remove -y Base
8.历史记录指令,(扩展了解)
#1.查看历史执行yum命令
[root@www.xuliangwei.com ~]# yum history
#2.查询历史执行yum命令ID详细信息
[root@www.xuliangwei.com ~]# yum history info N
#3.撤销历史执行过的yum命令
[root@www.xuliangwei.com ~]# yum history undo N
PS: YUM还有配置文件与签名验证需要我们额外扩展了解的请点击传送门ls
联系客服