②linux yum

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

5.YUM配置文件

yum的配置一般有两种方式: 一种是直接配置/etc目录下的yum.conf文件, 另外一种是在/etc/yum.repos.d目录下增加.repo文件

[root@xuliangwei ~]# vim /etc/yum.cnf
cachedir=/var/cache/yum/$basearch/$releasever   #缓存目录
keepcache=0     #缓存软件包,1启动 0 关闭
debuglevel=2    #调试级别
logfile=/var/log/yum.log    #日志记录位置
exactarch=1     #检查平台是否兼容
obsoletes=1     #检查包是否废弃
gpgcheck=1      #检查来源是否合法,需要有制作者的公钥信息
plugins=1
installonly_limit=5
bugtracker_url
# metadata_expire=90m   #每小时手动检查元数据
# in /etc/yum.repos.d   #包含repos.d目录中的.repo文件

7.YUM签名检查

redhat在构建rpm包时,使用私钥private key对 rpm包进行签名,客户端在使用rpm为验证其合法性,可以使用redhat提供的公钥public key进行签名检查。

方式1: 指定公钥的位置

[root@xuliangwei ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base 
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

方式2: 提前导入公钥

[root@xuliangwei ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@xuliangwei ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base 
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=0

方式3: 不进行签名验证

#不验证软件包的合法性
[root@xuliangwei ~]# yum install httpd --nogpgcheck
posted @ 2021-03-08 13:17  老夫聊发少年狂88  阅读(77)  评论(0编辑  收藏  举报