23-RPM升级及yum history,info,sudo

[TOC]

一、rpm-升级

# 选项
-U : update升级,如果老版本不在则安装,如果老版本在则升级
-f: 必须老版本在才能升级

#查询当前系统中安装的nginx包
0 ? 03:47:54 root@yyds,10.0.0.100:<sub> # rpm -q nginx
nginx-1.12.0-1.el7.ngx.x86_64

# -ivh 安装nginx1.12版本包 有老版本报错无法安装
004:08:36 root@yyds,10.0.0.100:</sub> # rpm -ivh nginx-1.12.0-1.el7.ngx.x86_64.rpm
warning: nginx-1.12.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing... ################################# [100%]
file /etc/logrotate.d/nginx from install of nginx-1:1.12.0-1.el7.ngx.x86_64 conflicts with file from package nginx-1:1.10.0-1.el7.ngx.x86_64
file /usr/libexec/initscripts/legacy-actions/nginx/upgrade from install of nginx-1:1.12.0-1.el7.ngx.x86_64 conflicts with file from package nginx-1:1.10.0-1.el7.ngx.x86_64

104:09:01 root@yyds,10.0.0.100:<sub> # rpm -q nginx
nginx-1.10.0-1.el7.ngx.x86_64

# -Uvh 即可以升级老版本,还可以直接安装上安装包
304:10:10 root@yyds,10.0.0.100:</sub> # rpm -Uvh nginx-1.12.0-1.el7.ngx.x86_64.rpm
warning: nginx-1.12.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:nginx-1:1.12.0-1.el7.ngx ################################# [ 50%]
Cleaning up / removing...
2:nginx-1:1.10.0-1.el7.ngx ################################# [100%]
004:10:22 root@yyds,10.0.0.100:~ #

二、rpm-卸载

-e  后面接的卸载的包名即可
004:10:22 root@yyds,10.0.0.100:<sub> # rpm -q nginx
nginx-1.12.0-1.el7.ngx.x86_64
004:32:41 root@yyds,10.0.0.100:</sub> # rpm -e nginx
004:33:17 root@yyds,10.0.0.100:~ # rpm -q nginx
package nginx is not installed

-e 同时卸载多个

三、镜像地址

1.阿里云镜像站:http://mirlinux必学的60个命令rors.aliy系统运维是干嘛的un.com
2.网易镜像站:http://milinux必学的60个命令rrors.163.com/
3.清华源:https://mirryum源配置ors.tuna.tsinghua.edu.cn
4.中科大源:https://mirrors.ustc.edu.cn/

第二部分 yum

一、yum的概述

1、什么是yum

yum也是一种rpm包管理工具,相linux是什么操作系统比于rplinux系统安装m命令,优势是可自动解决yum源依赖关系。自动解决依赖关系的前提条件,你的yum源要有这些依赖包系统运维主要做什么
nginx安装依赖 pcre-devel openssl-devel

yum install -y nginx

2、什么是yum源

yum源:可理解为手机的应用商店
yum源本地yum源其他名称:镜像站,ylinux常用命令um仓库、rpm仓库

3、配置yum源

# 使用阿里云的yum源
http://mirrors.aliyun.com

#系统中需要的基础yum源
base源:和镜像中的Linux基础包差不多
epel源:一些扩展安装包

#yum的配置文件存放目录*****
004:37:52 root@yyds,10.0.0.100:<sub> # ll /etc/yum.repos.d/
total 40
-rw-r--r--. 1 root root 2495 Feb 14 08:16 CentOS-Base.repo
-rw-r--r--. 1 root root 549 Nov 23 2020 CentOS-Base.repo.gz
-rw-r--r--. 1 root root 735 Nov 23 2020 CentOS-CR.repo.gz
-rw-r--r--. 1 root root 426 Nov 23 2020 CentOS-Debuginfo.repo.gz
-rw-r--r--. 1 root root 232 Nov 23 2020 CentOS-fasttrack.repo.gz
-rw-r--r--. 1 root root 381 Nov 23 2020 CentOS-Media.repo.gz
-rw-r--r--. 1 root root 506 Nov 23 2020 CentOS-Sources.repo.gz
-rw-r--r--. 1 root root 813 Nov 23 2020 CentOS-Vault.repo.gz
-rw-r--r--. 1 root root 272 Nov 23 2020 CentOS-x86_64-kernel.repo.gz
-rw-r--r--. 1 root root 664 Dec 26 2020 epel.repo

# 1.删除官方的yum源
[root@zls </sub>]# rm -f /etc/yum.repos.d/*
# 2.安全方式,不使用yum源
[root@zls <sub>]# gzip -r /etc/yum.repos.d/
# 3.下载Base源
[root@yyds </sub>]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@yyds <sub>]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 4.下载epel源
[root@yyds </sub>]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:-100 664 100 664 0 0 8358 0 --:--:-- --:--:-- --:--:-- 8405

#注意:
在/etc/yum.repos.d/目录下所有yum源配置,必须以.repo结尾

##安装nignx服务,使用nginx官方yum源
#1.打开nginx.org官网
#2.找到我nginx的yum仓库
#3.vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

二、yum 命令实践

1、yum查询yum源

# 查看yum仓库中所有可以安装的rpm包
[root@yyds <sub>]# yum list

#过滤查看yum仓库中是否有wget包
[root@yyds </sub>]# yum list |grep wget
wget.x86_64 1.14-18.el7_6.1 base

# yum info 查看yum仓库中,所有安装包的详细信息
[root@yyds <sub>]# yum info

[root@yyds </sub>]# yum info |grep mkdir
: server edg-gridftp-mkdir create a directory on the server
Name : nodejs-mkdirp
URL : https://github.com/substack/node-mkdirp
Description : Creates directories recursively, like `mkdir -p`.
: the atomic nature of the link (on Unix) and mkdir (on Windows)
: the atomic nature of the link (on Unix) and mkdir (on Windows)
: o p.mkdir() succeeds silently if the directory already exists,
: o p.mkdir(True) creates intermediate directories a la
: the atomic nature of the link (on Unix) and mkdir (on Windows)
: mkdir.sh, install.sh and related scripts.

#
[root@yyds ~]# yum provides */ifconfig (#查找安装包,要用绝对路径,或用*代替)
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
#该命令隶属的安装包名
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
#隶属的仓库
Repo : base
Matched from:
Filename : /sbin/ifconfig #装完后,命令会在/usr/sbin下叫inconfig

2、安装方式

#安装方式
-本地安装
yum localinstall -y 包名 (包在服务器上)

-yum源安装
yum install -y tree

-网站上安装
yum install -y http://test.driverzeng.com/Nginx_package/nginx-1.12.2- 3.el7.x86_64.rpm
自动解决依赖关系的前提条件:在你的所有yum源中都要有该软件的依赖包

3、yum重装

yum reinstall -y 包名
[root@yyds <sub>]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
[root@yyds </sub>]# cd /etc/vsftpd/
[root@yyds vsftpd]# ll
total 20
-rw-------. 1 root root 125 Jun 9 2021 ftpusers
-rw-------. 1 root root 361 Jun 9 2021 user_list
-rw-------. 1 root root 5116 Jun 9 2021 vsftpd.conf
-rwxr--r--. 1 root root 338 Jun 9 2021 vsftpd_conf_migrate.sh
[root@yyds ~]# cd /etc/vsftpd/
[root@yyds vsftpd]# ll
total 20
-rw-------. 1 root root 125 Jun 9 2021 ftpusers
-rw-------. 1 root root 361 Jun 9 2021 user_list
-rw-------. 1 root root 5116 Jun 9 2021 vsftpd.conf
-rwxr--r--. 1 root root 338 Jun 9 2021 vsftpd_conf_migrate.sh
[root@yyds vsftpd]# rm -f ftpusers
[root@yyds vsftpd]# ll
total 16
-rw-------. 1 root root 361 Jun 9 2021 user_list
-rw-------. 1 root root 5116 Jun 9 2021 vsftpd.conf
-rwxr--r--. 1 root root 338 Jun 9 2021 vsftpd_conf_migrate.sh
[root@yyds vsftpd]# yum reinstall -y vsftpd
root@yyds vsftpd]# ll
total 20
-rw-------. 1 root root 125 Jun 9 2021 ftpusers
-rw-------. 1 root root 361 Jun 9 2021 user_list
-rw-------. 1 root root 5116 Jun 9 2021 vsftpd.conf
-rwxr--r--. 1 root root 338 Jun 9 2021 vsftpd_conf_migrate.sh

#作用
误删除了该服务相关的任何一个文件,使用reinstall都可以恢复名单恢复的是该配置文件的初始配置
使用reninstall的方式,必须跟开始安装的这个包的方式一致。

4、yum更新

#查看当前系统中,有哪些软件是可更新的
[root@yyds vsftpd]# yum check-update
[root@yyds vsftpd]# yum update -y zlib

5、yum卸载

[root@zls <sub>]# yum erase 包名 -y [root@zls </sub>]# yum remove 包名 -y

三、yum命令

1、yum仓库指令

#查看所有源中可用的yum仓库
023:09:15 root@yyds,10.0.0.101:<sub> # yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
仓库名 仓库描述
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7 - 13,751
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 509
nginx-stable/7/x86_64 nginx stable repo 262
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 3,728
023:19:49 root@yyds,10.0.0.101:</sub> # yum repolist all

repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com enabled: 10,072
centosplus/7/x86_64 CentOS-7 - Plus - mirrors.aliyun.com disabled
contrib/7/x86_64 CentOS-7 - Contrib - mirrors.aliyun.com disabled
....................................................................
repolist: 28,322
: 28,322

# 使用yum-config-manager
# 1.没有命令,要安装命令
023:21:39 root@yyds,10.0.0.101:<sub> # yum install -y yum-config-manager
No package yum-config-manager available.
Error: Nothing to do

# 2.查询该命令属于哪个包
123:31:57 root@yyds,10.0.0.101:</sub> # yum provides */yum-config-manager
yum-utils-1.1.31-54.el7_8.noarch : Utilities based around the yum
: package manager
Repo : base
Matched from:
Filename : /usr/bin/yum-config-manager

# 3.安装对应的rpm包
023:42:05 root@yyds,10.0.0.101:~ # yum install -y yum-utils

# 4.修改yum源配置文件,开启或关闭仓库
-开启
004:02:20 root@yyds,10.0.0.101:/etc/yum.repos.d # yum-config-manager --enable nginx-mainline

-关闭
004:02:20 root@yyds,10.0.0.101:/etc/yum.repos.d # yum-config-manager --disable nginx-mainline

2、yum缓存命令

#清除所有缓存
yum clean all

#加载缓存
yum makecache

#默认情况下,yum是不会下载rpm的,只会安装,除非开启下载的配置
vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0 # 把0改成1就是开启下载rpm

# 下面是yum下载的默认路径
2 ? 05:37:55 root@yyds,10.0.0.101:/etc/yum.repos.d # ll /var/cache/yum/x86_64/7/
total 16
drwxr-xr-x. 4 root root 4096 Apr 22 21:25 base
drwxr-xr-x. 4 root root 33 Apr 22 23:21 centosplus
drwxr-xr-x. 4 root root 33 Apr 22 23:21 contrib
drwxr-xr-x. 4 root root 4096 Apr 22 21:25 epel

#下载nginx、不安装,并指定目录
yum install nginx -y --downloadonly --downloaddir=/opt

--downloadonly:仅下载,不安装
--downloaddir:指定下载的目录

# yum clean packages
只会清除默认路径下得rpm包
007:46:36 root@yyds,10.0.0.101:/mnt/Packages # yum install -y nginx --downloadonly --downloaddir=/tmp
007:48:00 root@yyds,10.0.0.101:/mnt/Packages # find /var/cache/yum/ -type f -name '*.rpm'
008:16:30 root@yyds,10.0.0.101:/mnt/Packages # ll /tmp
total 796
-rw-r--r--. 1 root root 808972 Nov 16 10:20 nginx-1.20.2-1.el7.ngx.x86_64.rpm
-rw-------. 1 root root 249 Apr 23 07:47 yum_save_tx.2022-04-23.07-47.jhzB7z.yumtx

3.yum包管理命令

# 查看有哪些包可以安装
yum group list
# 安装包组
yum groups install 包组名字
# 卸载包组
yum groups remove 包组名字

4.yum历史命令

108:52:17 root@yyds,10.0.0.103:<sub> # yum history
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
12 | root <root> | 2022-04-19 05:22 | Install | 11
11 | root <root> | 2022-04-17 23:02 | Install | 1

#查看某个操作的详细信息
yum history info ID
008:54:06 root@yyds,10.0.0.103:</sub> # yum history info 4
Loaded plugins: fastestmirror
Transaction ID : 4
Begin time : Thu Apr 7 23:19:48 2022
Begin rpmdb : 337:00a7e28492f9d9e34141130ced2bc7f7b58d429f

#撤销历史操作,一般撤销更新操作
yum history undo ID
009:03:40 root@yyds,10.0.0.103:~ # yum history undo 4

5、yum仓库配置文件

#仓库名字
[base]
#仓库描述
name=CentOS-$releasever - Base
#仓库地址
mirrorlist=http://mirrorlist.centos.org/?
release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
#仓库签名检测机制
gpgcheck=1

#公钥的地址
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

公钥 :锁
私钥 :钥匙