yum管理工具
[TOC]
yum安裝
yum安裝方式
- 本地安裝:
yum localinstall -y 包名 (前提該包已經(jīng)下載在服務(wù)器上了)
- yum源安裝:
yum install -y 命令
- 網(wǎng)站安裝:
yum install -y http://test.driverzeng.com/Nginx_package/nginx-1.12.2-
3.el7.x86_64.rpm
自動(dòng)解決依賴關(guān)系的前提條件:在你的所有yum中都要有該軟件的依賴包
yum重裝
yum reinstall -y 包名
作用:誤刪了該服務(wù)相關(guān)的任何一個(gè)文件,使用reinstall都可以恢復(fù),但是恢復(fù)的是最初始的配置
reinstall的方式,必須跟最開始安裝這個(gè)包的方式一致
yum更新
# 查看當(dāng)前系統(tǒng)中,有哪些軟件是可以更新的
[root@zxw <sub>]# yum check-update
# 更新指定的軟件包
[root@zxw </sub>]# rpm update -y 包名
# 更新所有可更新的軟件包
[root@zxw <sub>]# rpm update -y(此命令危險(xiǎn))
原因:
[root@zxw </sub>]# yum check-update|grep kernel
kernel.x86_64 3.10.0-1160.62.1.el7 updates
kernel-tools.x86_64 3.10.0-1160.62.1.el7 updates
kernel-tools-libs.x86_64 3.10.0-1160.62.1.el7 updates
[root@zxw ~]# uname -a
Linux zxw 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
(如果執(zhí)行了這個(gè)命令它會(huì)把內(nèi)核也更新了,如果內(nèi)核更新了當(dāng)前的系統(tǒng)版本也就更新了)
yum卸載
[root@zxw <sub>]# yum erase -y 包名
[root@zxw </sub>]# yum remove -y 包名
yum倉(cāng)庫(kù)指令
# 查看所有源中可用的yum倉(cāng)庫(kù)
[root@zxw <sub>]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
倉(cāng)庫(kù)名(包) 倉(cāng)庫(kù)描述 倉(cāng)庫(kù)狀態(tài)(多少個(gè))
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 - x86_64 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
repolist: 28,322
# 查看所有源中,所有的yum倉(cāng)庫(kù)
[root@zxw </sub>]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
倉(cāng)庫(kù)名(包) 倉(cāng)庫(kù)描述 倉(cāng)庫(kù)狀態(tài)(多少個(gè))
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
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 enabled: 13,751
epel-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 - disabled
epel-source Extra Packages for Enterprise Linux 7 - x86_64 - disabled
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com enabled: 509
nginx-mainline/7/x86_64 nginx mainline repo disabled
nginx-stable/7/x86_64 nginx stable repo enabled: 262
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com enabled: 3,728
repolist: 28,322
# 使用 yum-config-manager
# 1.沒有命令,要安裝命令
[root@zxw <sub>]# yum install -y yum-config-manager
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
No package yum-config-manager available.
Error: Nothing to do
# 2.查詢?cè)撁顚儆谀莻€(gè)包
[root@zxw </sub>]# yum provides */yum-config-manager
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
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.安裝對(duì)應(yīng)的rpm包
[root@zxw <sub>]# yum install -y yum-utils
# 修改yum源配置文件,開啟或關(guān)閉倉(cāng)庫(kù)
# 1.開啟
[root@zxw </sub>]# yum-config-manager --enable nginx-mainline
# 2.關(guān)閉
[root@zxw ~]# yum-config-manager --disable nginx-mainline
yum緩存命令
# 清除所有的緩存
yum clean all
# 加載緩存
yum makecache
# 默認(rèn)情況下,yum是不會(huì)下載rpm包的,只會(huì)安裝
# 除非開啟下載的配置
vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0(# 把這個(gè)0改成1就會(huì)下載rpm包了)
# yum下載后rpm包的默認(rèn)路徑
[root@zxw <sub>]# ll /var/cache/yum/x86_64/7/
total 28
drwxr-xr-x. 4 root root 4096 Apr 24 14:56 base
drwxr-xr-x. 4 root root 33 Apr 23 21:33 centosplus
drwxr-xr-x. 4 root root 33 Apr 23 21:33 contrib
drwxr-xr-x. 4 root root 4096 Apr 24 14:56 epel
drwxr-xr-x. 4 root root 33 Apr 23 21:33 epel-debuginfo
drwxr-xr-x. 4 root root 33 Apr 23 21:33 epel-source
drwxr-xr-x. 4 root root 4096 Apr 24 14:56 extras
drwxr-xr-x. 4 root root 33 Apr 23 21:33 nginx-mainline
drwxr-xr-x. 4 root root 4096 Apr 24 14:56 nginx-stable
-rw-r--r--. 1 root root 202 Apr 24 14:57 timedhosts
-rw-r--r--. 1 root root 107 Apr 24 14:56 timedhosts.txt
drwxr-xr-x. 4 root root 4096 Apr 24 14:57 updates
# 下載tree,不安裝,并指定目錄
yum install tree -y --downloadonly --downloaddir=/tmp
--downloadonly:僅下載,不安裝
--downloaddir:指定下載的目錄
# yum clean packages
只會(huì)清除默認(rèn)路徑下的包
舉例
[root@zxw </sub>]# find /var/cache/yum/ -type f -name '*.rpm'
/var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm
[root@zxw <sub>]# ll /tmp
total 56
-rw-r--r--. 1 root root 47508 Jul 4 2014 tree-1.6.0-10.el7.x86_64.rpm
-rw-------. 1 root root 236 Apr 24 15:31 yum_save_tx.2022-04-24.15-31._nKsFC.yumtx
-rw-------. 1 root root 236 Apr 24 15:32 yum_save_tx.2022-04-24.15-32.KhBb_m.yumtx
[root@zxw </sub>]# yum clean packages
Loaded plugins: fastestmirror
Cleaning repos: base epel extras nginx-stable updates
1 package file removed
[root@zxw <sub>]# find /var/cache/yum/ -type f -name '*.rpm'
[root@zxw </sub>]# ll /tmp
total 56
-rw-r--r--. 1 root root 47508 Jul 4 2014 tree-1.6.0-10.el7.x86_64.rpm
-rw-------. 1 root root 236 Apr 24 15:31 yum_save_tx.2022-04-24.15-31._nKsFC.yumtx
-rw-------. 1 root root 236 Apr 24 15:32 yum_save_tx.2022-04-24.15-32.KhBb_m.yumtx
yum包組管理命令
# 查看有哪些包組可以安裝
[root@zxw ~]# yum group list
# 安裝包組
yum groups install 包組名字
# 卸載包組
yum groups remove 包組名字
(# 沒太大必要,應(yīng)為最開始安裝系統(tǒng)的時(shí)候選擇的是最小化安裝,安裝其他的包組反而麻煩)
[root@zxw ~]# yum group list
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Cinnamon Desktop
MATE Desktop
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Available Groups:
Cinnamon
Compatibility Libraries
Console Internet Tools
Development Tools
Educational Software
Electronic Lab
Fedora Packager
General Purpose Desktop
Graphical Administration Tools
Haskell
LXQt Desktop
Legacy UNIX Compatibility
MATE
Milkymist
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
TurboGears application framework
Xfce
Done
yum歷史命令
# 查看yum的歷史操作
[root@zxw <sub>]# yum history
Loaded plugins: fastestmirror
命令的ID 執(zhí)行的命令 執(zhí)行的時(shí)間 動(dòng)作 操作幾個(gè)包
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
9 | root <root> | 2022-04-24 16:06 | Erase | 1
8 | root <root> | 2022-04-24 15:38 | Install | 1
7 | root <root> | 2022-04-24 15:28 | Erase | 1
6 | root <root> | 2022-04-23 21:57 | Update | 1
5 | root <root> | 2022-04-23 21:50 | I, U | 5
4 | root <root> | 2022-04-23 16:05 | Install | 31
3 | root <root> | 2022-04-22 09:45 | Install | 1 <
2 | root <root> | 2022-04-21 21:31 | Install | 1 ><
1 | System <unset> | 2022-03-15 17:28 | Install | 304 >
history list
# 查看某個(gè)歷史操作的詳細(xì)信息
yum history info ID
[root@zxw </sub>]# yum history info 5
# 撤銷歷史操作:一般撤銷更新操作
yum history undo ID
yum倉(cāng)庫(kù)配置文件
# 倉(cāng)庫(kù)名字
[base]
# 倉(cāng)庫(kù)的描述
name=CentOS-$releasever - Base - mirrors.aliyun.com
# 倉(cāng)庫(kù)的地址
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
# 倉(cāng)庫(kù)簽名檢查機(jī)制
gpgcheck=1
# 倉(cāng)庫(kù)開啟/關(guān)閉 (1:開啟,0:關(guān)閉,默認(rèn)1)
enabled=1
# 公鑰的地址
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
公鑰:鎖
私鑰:鑰匙
本文摘自 :https://blog.51cto.com/u