第二十六章 Linux系统软件包管理

一、软件包管理概述

1.软件包管理含义

Redhat  Package  Manager   软件包管理
1.windows     .exe
2.Linux		.rpm

2.软件包的含义

ant-antunit-1.2-10.el7.noarch.rpm     

antlr-C++-2.7.7-30.el7.x86_64.rpm


ant-antunit			#软件包名称  

1.2					#软件的版本 

10					#软件包编译发布的次数 

el7					#适用于7系列的操作系统 

el6					#适用于6系列操作系统

noarch				#适用于任何cpu架构  


x86_64				#硬件平台  位数  

.rpm				#包的后缀名 

3.软件包的安装方式

rpm包		预先编译好的,安装简单  		版本过低  

源码包		   手动编译,安装繁琐		   版本随意 

二进制包	   绿色软件 解压即用           无法修改源代码 

4.软件包的获取方式

1.本地的ISO镜像     需要挂载使用 

2.联网下载  		

3.仓库获取 yum源  

二、rpm包优缺点

1.优点

1.包管理系统简单,值通过几个命令就可以实现包的安装、升级、查询和卸载
2.安装速度比源码包安装快的多

2.缺点

1.经过编译,不再可以看到源代码
2.功能选择不如源码包灵活
3.依赖性

三、rpm软件包管理工具

1.含义

rpm命令来自于英文词组”RedHat Package Manager“的缩写,中文译为红帽软件包管理器,其功能是用于在Linux系统下对软件包进行安装、卸载、查询、验证、升级等工作。

语法格式:rpm [参数] 软件包

2.常用参数

-a 查询所有的软件包
-b或-t 设置包装套件的完成阶段,并指定套件档的文件名称;
-c 只列出组态配置文件,本参数需配合”-l”参数使用
-d 只列出文本文件,本参数需配合”-l”参数使用
-e 卸载软件包
-f 查询文件或命令属于哪个软件包
-h 安装软件包时列出标记(显示安装的进度条)
-i 安装软件包
-l 显示软件包的文件列表
-p 查询指定的rpm软件包
-q 查询软件包
-R 显示软件包的依赖关系
-s 显示文件状态,本参数需配合”-l”参数使用
-U 升级软件包
-v 显示命令执行过程
-vv 详细显示指令执行过程

3.常用示例

3.1 挂载镜像

[root@jindada ~]# ll /dev/sr0 
brw-rw---- 1 root cdrom 11, 0 Jul 27 16:29 /dev/sr0
[root@jindada ~]# ll /dev/cdrom 
lrwxrwxrwx 1 root root 3 Jul 27 16:29 /dev/cdrom -> sr0
[root@jindada ~]# mount   /dev/sr0   /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@jindada ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        98G  1.5G   97G   2% /
devtmpfs        980M     0  980M   0% /dev
tmpfs           991M     0  991M   0% /dev/shm
tmpfs           991M  9.6M  981M   1% /run
tmpfs           991M     0  991M   0% /sys/fs/cgroup
/dev/sda1       497M  120M  378M  25% /boot
tmpfs           199M     0  199M   0% /run/user/0
/dev/sr0        4.3G  4.3G     0 100% /mnt

[root@jindada ~]# ll  /mnt/Packages/  | wc -l
4023

3.2 正常安装软件包

[root@jindada ~]# rpm  -ivh  /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:tree-1.6.0-10.el7                ################################# [100%]

3.3 查询指定的软件包是否安装

[root@jindada ~]# rpm  -q  tree
tree-1.6.0-10.el7.x86_64
[root@jindada ~]# rpm  -q  ifconfig
package ifconfig is not installed
[root@jindada ~]# rpm  -q  net-tools
net-tools-2.0-0.25.20131004git.el7.x86_64

3.4 显示系统已安装过的全部RPM软件包

[root@jindada ~]# rpm -qa
qemu-kvm-block-gluster-2.12.0-63.module+el8+2833+c7d6d092.x86_64
boost-atomic-1.66.0-6.el8.x86_64
gnome-session-wayland-session-3.28.1-6.el8.x86_64
grub2-tools-2.02-66.el8.x86_64
lohit-gurmukhi-fonts-2.91.2-3.el8.noarch
liberation-fonts-common-2.00.3-4.el8.noarch
policycoreutils-python-utils-2.8-16.1.el8.noarch
………………省略部分输出信息………………

3.5 显示所有已经安装的软件包

[root@jindada ~]# rpm -qa  | grep  tree
tree-1.6.0-10.el7.x86_64

3.6 查询某个软件的安装路径

[root@jindada ~]# rpm  -ql  httpd
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf

3.7 查询相关配置文件信息

[root@jindada ~]# rpm  -qc  httpd
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd

3.8 查询软件包本身信息

[root@jindada ~]# rpm  -qi  httpd
Name        : httpd
Version     : 2.4.6
Release     : 88.el7.centos
Architecture: x86_64
Install Date: Thu 30 Jul 2020 09:03:08 AM CST
Group       : System Environment/Daemons
Size        : 9817309
License     : ASL 2.0
Signature   : RSA/SHA256, Mon 12 Nov 2018 10:28:53 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : httpd-2.4.6-88.el7.centos.src.rpm
Build Date  : Mon 05 Nov 2018 09:48:57 AM CST
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

3.9 使用绝对路径查询命令属于哪个软件包 前提系统已经安装这个软件

[root@jindada ~]# rpm  -qf  `which  ping`
iputils-20160308-10.el7.x86_64
[root@jindada ~]# which  ping
/usr/bin/ping
[root@jindada ~]# rpm -qf  /usr/bin/ping
iputils-20160308-10.el7.x86_64

3.10 卸载某个通过RPM软件包安装的服务

[root@jindada ~]# rpm -evh cockpit
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:cockpit-185-2.el8                ################################# [100%]

4.rpm常用依赖安装报错

4.1 现象

#rpm安装太需要依赖了,不会自动寻找依赖,需要手动下载依赖    不建议使用  

#安装httpd  报错
[root@jindada ~]# rpm  -ivh  /mnt/Packages/httpd-2.4.6-88.el7.centos.x86_64.rpm 
error: Failed dependencies:
	/etc/mime.types is needed by httpd-2.4.6-88.el7.centos.x86_64
	httpd-tools = 2.4.6-88.el7.centos is needed by httpd-2.4.6-88.el7.centos.x86_64
	libapr-1.so.0()(64bit) is needed by httpd-2.4.6-88.el7.centos.x86_64
	libaprutil-1.so.0()(64bit) is needed by httpd-2.4.6-88.el7.centos.x86_64
	
#根据提示安装相关依赖  报错
[root@jindada ~]# rpm  -ivh  /mnt/Packages/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm 
error: Failed dependencies:
	libapr-1.so.0()(64bit) is needed by httpd-tools-2.4.6-88.el7.centos.x86_64
	libaprutil-1.so.0()(64bit) is needed by httpd-tools-2.4.6-88.el7.centos.x86_64

4.2 查找依赖包

[root@jindada ~]# ll  /mnt/Packages/  | grep  apr
-rw-rw-r-- 1 root root   105728 Nov 29  2017 apr-1.4.8-3.el7_4.1.x86_64.rpm
-rw-rw-r-- 1 root root   192652 Nov 29  2017 apr-devel-1.4.8-3.el7_4.1.x86_64.rpm
-rw-rw-r-- 1 root root    94132 Jul  4  2014 apr-util-1.5.2-6.el7.x86_64.rpm
-rw-rw-r-- 1 root root    78072 Jul  4  2014 apr-util-devel-1.5.2-6.el7.x86_64.rpm
-rw-rw-r-- 1 root root   854420 Nov 12  2018 haproxy-1.5.18-8.el7.x86_64.rpm

4.3 安装相关依赖

[root@jindada ~]# rpm -ivh  /mnt/Packages/apr-1.4.8-3.el7_4.1.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:apr-1.4.8-3.el7_4.1              ################################# [100%]
[root@jindada ~]# rpm -ivh  /mnt/Packages/apr-util-1.5.2-6.el7.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:apr-util-1.5.2-6.el7             ################################# [100%]

4.4 尝试安装httpd-tools

[root@jindada ~]# rpm  -ivh  /mnt/Packages/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:httpd-tools-2.4.6-88.el7.centos  ################################# [100%]

4.5 再次安装httpd 报错

[root@jindada ~]# rpm  -ivh  /mnt/Packages/httpd-2.4.6-88.el7.centos.x86_64.rpm 
error: Failed dependencies:
	/etc/mime.types is needed by httpd-2.4.6-88.el7.centos.x86_64

4.6 搜索相关文件的依赖包

[root@jindada ~]# yum  provides  /etc/mime.types
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * epel: fedora.cs.nctu.edu.tw
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
mailcap-2.1.41-2.el7.noarch : Helper application and MIME type associations for file types
Repo        : base
Matched from:
Filename    : /etc/mime.types

4.7 安装依赖包

[root@jindada ~]# rpm  -ivh  /mnt/Packages/mailcap-2.1.41-2.el7.noarch.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:mailcap-2.1.41-2.el7             ################################# [100%]

4.8 最终安装成功

[root@jindada ~]# rpm  -ivh  /mnt/Packages/httpd-2.4.6-88.el7.centos.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:httpd-2.4.6-88.el7.centos        ################################# [100%]
[root@jindada ~]# 

5.联网安装软件包

[root@jindada ~]# rpm  -ivh  https://mirrors.aliyun.com/centos/7.8.2003/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
Retrieving https://mirrors.aliyun.com/centos/7.8.2003/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:tree-1.6.0-10.el7                ################################# [100%]

6.升级安装

6.1 安装

[root@jindada ~]# rpm  -ivh  https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm
Retrieving https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm
warning: /var/tmp/rpm-tmp.jseg5b: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-agent-4.0.0-2.el7         ################################# [100%]

[root@jindada ~]# zabbix_agentd -V
zabbix_agentd (daemon) (Zabbix) 4.0.0
Revision 85308 1 October 2018, compilation time: Oct  1 2018 08:41:36

Copyright (C) 2018 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

6.2 升级

-U		#升级  

#升级安装
[root@jindada ~]# rpm  -Uvh  https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.0-1.el7.x86_64.rpm
Retrieving https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.0-1.el7.x86_64.rpm
warning: /var/tmp/rpm-tmp.e9rZWk: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-agent-4.4.0-1.el7         ################################# [ 50%]
Cleaning up / removing...
   2:zabbix-agent-4.0.0-2.el7         ################################# [100%]
[root@jindada ~]# zabbix_agentd -V
zabbix_agentd (daemon) (Zabbix) 4.4.0
Revision cfac660b25 7 October 2019, compilation time: Oct  7 2019 11:26:17

Copyright (C) 2019 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/).

Compiled with OpenSSL 1.0.1e-fips 11 Feb 2013
Running with OpenSSL 1.0.1e-fips 11 Feb 2013

7.总结

	-ivh		#安装
	
	-Uvh		#升级
	
	-e			#卸载
	
	-q			#查询指定软件包 
	
	-qa			#查询所有已经安装的软件包
	
	-qi			#查询软件包本身相关信息
	
	-ql			#查询软件包列表信息
	
	-qc			#查询软件包相关文件
	
	-qf			#查询命令属于哪个软件包  必须是绝对路径  前提本地要已经存在这个软件包 

四、yum软件包管理工具

1.概述

yum命令来自于英文词组”YellowdogUpdater,Modified“的缩写,其功能是用于在Linux系统中基于RPM技术进行软件包的管理工作。yum技术通用于RHEL、CentOS、Fedora、OpenSUSE等主流系统,可以让系统管理人员交互式的自动化更新和管理软件包,实现从指定服务器自动下载、更新、删除软件包的工作。

yum软件仓库及命令能够自动处理软件依赖关系,一次性安装所需全部软件,无需繁琐的操作。

语法格式:yum [参数] 软件包

2.yum源配置目录

[root@jindada ~]# ll  /etc/yum.repos.d/
total 40
-rw-r--r-- 1 root root 1664 Nov 23  2018 CentOS-Base.repo
-rw-r--r-- 1 root root 1309 Nov 23  2018 CentOS-CR.repo
-rw-r--r-- 1 root root  649 Nov 23  2018 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root  314 Nov 23  2018 CentOS-fasttrack.repo
-rw-r--r-- 1 root root  630 Nov 23  2018 CentOS-Media.repo
-rw-r--r-- 1 root root 1331 Nov 23  2018 CentOS-Sources.repo
-rw-r--r-- 1 root root 5701 Nov 23  2018 CentOS-Vault.repo
-rw-r--r-- 1 root root  951 Oct  3  2017 epel.repo
-rw-r--r-- 1 root root 1050 Oct  3  2017 epel-testing.repo

3.yum源获取方式

1.本地的ISO镜像   
2.yum源仓库  
3.联网的方式下载 
4.本地yum仓库 

4.yum的种类

1.base		#基础源 
2.epel		#扩展源  
3.软件官方源     # nginx   zabbix   docker 

阿里源/清华源/中科大/163源 

5.更新yum源

[root@jindada ~]# rm -rf  /etc/yum.repos.d/*

[root@jindada ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

[root@jindada ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

[root@jindada ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r-- 1 root root 2523 Jul 30 09:51 CentOS-Base.repo
-rw-r--r-- 1 root root  664 May 11  2018 epel.repo

6.常用参数

-h 显示帮助信息
-y 对所有的提问都回答“yes”
-c 指定配置文件
-q 安静模式
-v 详细模式
-t 检查外部错误
-d 设置调试等级(0-10)
-e 设置错误等级(0-10)
-R 设置yum处理一个命令的最大等待时间
-C 完全从缓存中运行,而不去下载或者更新任何头文件
install 安装rpm软件包
update 更新rpm软件包
check-update 检查是否有可用的更新rpm软件包
remove 删除指定的rpm软件包
list 显示软件包的信息
search 检查软件包的信息
info 显示指定的rpm软件包的描述信息和概要信息
clean 清理yum过期的缓存
shell 进入yum的shell提示符
resolvedep 显示rpm软件包的依赖关系
localinstall 安装本地的rpm软件包
localupdate 显示本地rpm软件包进行更新
deplist 显示rpm软件包的所有依赖关系

7.常见示例

显示可用的yum仓库

[root@jindada ~]# yum  repolist   
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                    repo name                                                               status
!base/7/x86_64                             CentOS-7 - Base - mirrors.aliyun.com                                    10,070
!epel/x86_64                               Extra Packages for Enterprise Linux 7 - x86_64                          13,422
!extras/7/x86_64                           CentOS-7 - Extras - mirrors.aliyun.com                                     412
!updates/7/x86_64                          CentOS-7 - Updates - mirrors.aliyun.com                                    900
repolist: 24,804

显示所有的yum仓库

[root@jindada ~]# yum  repolist   all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                             repo name                                                             status
!base/7/x86_64                      CentOS-7 - Base - mirrors.aliyun.com                                  enabled: 10,070
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,422
epel-debuginfo/x86_64               Extra Packages for Enterprise Linux 7 - x86_64 - Debug                disabled
epel-source                         Extra Packages for Enterprise Linux 7 - x86_64 - Source               disabled
!extras/7/x86_64                    CentOS-7 - Extras - mirrors.aliyun.com                                enabled:    412
!updates/7/x86_64                   CentOS-7 - Updates - mirrors.aliyun.com                               enabled:    900
repolist: 24,804

开启/禁用yum源

[root@jindada ~]# yum  install  -y  yum-utils
[root@jindada ~]# yum-config-manager    --disable  epel
[root@jindada ~]# yum  repolist  all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                             repo name                                                             status
base/7/x86_64                       CentOS-7 - Base - mirrors.aliyun.com                                  enabled: 10,070
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                        disabled
epel-debuginfo/x86_64               Extra Packages for Enterprise Linux 7 - x86_64 - Debug                disabled
epel-source                         Extra Packages for Enterprise Linux 7 - x86_64 - Source               disabled
extras/7/x86_64                     CentOS-7 - Extras - mirrors.aliyun.com                                enabled:    412
updates/7/x86_64                    CentOS-7 - Updates - mirrors.aliyun.com                               enabled:    900
repolist: 11,382

[root@jindada ~]# yum-config-manager    --enable  epel

显示所有可安装的包

[root@jindada ~]# yum  list

显示系统中已经安装的包

[root@jindada ~]# yum  list  installed 
[root@jindada ~]# yum  list  | grep  ^tree
tree.x86_64                               1.6.0-10.el7                 @base    
treelayout.noarch                         1.0.3-4.el7                  epel     
treelayout-demo.noarch                    1.0.3-4.el7                  epel     
treelayout-javadoc.noarch                 1.0.3-4.el7                  epel 

显示可更新的包

[root@jindada ~]# yum  check-update

[root@jindada ~]# yum    list   updates  

更新某个软件包

[root@jindada ~]# rpm  -qa  httpd
httpd-2.4.6-88.el7.centos.x86_64

[root@jindada ~]# yum   update  httpd  -y

[root@jindada ~]# rpm  -qa  httpd
httpd-2.4.6-93.el7.centos.x86_64

安装软件包

[root@jindada ~]# yum  install   tree		#交互式  麻烦  

[root@jindada ~]# yum  install   tree   -y		#免交互

卸载软件包

[root@jindada ~]# yum  remove   tree  -y

[root@jindada ~]# yum  erase   tree  -y

联网安装软件包

[root@jindada ~]# yum  install  -y  https://mirrors.aliyun.com/centos/7.8.2003/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm

本地安装软件包

[root@jindada ~]# yum localinstall  -y  /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm

重新安装软件包

[root@jindada ~]# systemctl  start httpd
[root@jindada ~]# systemctl  status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-07-30 10:36:26 CST; 6s ago

[root@jindada ~]# rm -f /etc/httpd/conf/httpd.conf
[root@jindada ~]# systemctl  restart httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

[root@jindada ~]# yum  reinstall  -y  httpd

搜索软件包

[root@jindada ~]# yum search  ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
================================================= N/S matched: ifconfig =================================================
python36-ifcfg.noarch : Python cross-platform network interface discovery (ifconfig/ipconfig/ip)

  Name and summary matches only, use "search all" for everything.
  
  
# 联网搜索命令属于哪个软件包 
[root@jindada ~]# yum  provides   ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
epel/x86_64/filelists_db                                                                          |  12 MB  00:00:04     
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
Repo        : @base
Matched from:
Filename    : /usr/sbin/ifconfig

查看软件包相关信息

[root@jindada ~]# yum  info  tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Installed Packages
Name        : tree
Arch        : x86_64
Version     : 1.6.0
Release     : 10.el7
Size        : 87 k
Repo        : installed
Summary     : File system tree viewer
URL         : http://mama.indstate.edu/users/ice/tree/
License     : GPLv2+
Description : 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.

组包的安装/卸载

# 组包的安装
[root@jindada ~]# yum  groups  install   Python

# 组包的卸载
[root@jindada ~]# yum  groups  remove   Python

清理原有的软件仓库信息缓存

# 清除包的缓存 
[root@jindada ~]# yum   clean  packages  
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
0 package files removed

# 清除插件的缓存 
[root@jindada ~]# yum   clean  plugins
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
Cleaning up list of fastest mirrors


# 清除所有缓存 
[root@jindada ~]# yum   clean  all
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates

建立最新的软件仓库信息缓存

[root@jindada ~]# yum  makecache

历史记录

# yum 历史记录
[root@jindada ~]# yum  history
Loaded plugins: fastestmirror
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    27 | reinstall -y httpd       | 2020-07-30 10:37 | Reinstall      |    1   
    26 | localinstall -y /mnt/Pac | 2020-07-30 10:11 | Install        |    1   
    25 | erase tree -y            | 2020-07-30 10:10 | Erase          |    1   
    24 | install -y https://mirro | 2020-07-30 10:09 | Install        |    1   


# 显示所有历史记录 
[root@jindada ~]# yum  history  list  all
Loaded plugins: fastestmirror
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    27 | root <root>              | 2020-07-30 10:37 | Reinstall      |    1   
    26 | root <root>              | 2020-07-30 10:11 | Install        |    1   
    25 | root <root>              | 2020-07-30 10:10 | Erase          |    1   
    24 | root <root>              | 2020-07-30 10:09 | Install        |    1   
    23 | root <root>              | 2020-07-30 10:08 | Erase          |    1   
    22 | root <root>              | 2020-07-30 10:08 | Install        |    1   

# 查看某个ID的历史信息
[root@jindada ~]# yum  history  info  15
Loaded plugins: fastestmirror
Transaction ID : 15
Begin time     : Wed Jul 22 08:51:56 2020
Begin rpmdb    : 372:6b59857cbbb441dc1cf9e1a96ab23013fd830365
End time       :                           (0 seconds)
End rpmdb      : 373:c16ad60498e5079097783959293418aeedfc68b5
User           : root <root>
Return-Code    : Success
Command Line   : install -y psmisc
Transaction performed with:
    Installed     rpm-4.11.3-35.el7.x86_64                      @anaconda
    Installed     yum-3.4.3-161.el7.centos.noarch               @anaconda
    Installed     yum-plugin-fastestmirror-1.1.31-50.el7.noarch @anaconda
Packages Altered:
    Install psmisc-22.20-16.el7.x86_64 @base
history info


# 回滚历史ID为10的操作
[root@jindada ~]# yum  history  undo  10  -y 
[root@jindada ~]# yum  --setopt=history_list_view=commands  history  list all
Loaded plugins: fastestmirror
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    28 | history undo 10          | 2020-07-30 10:49 | Erase          |   21   
    27 | reinstall -y httpd       | 2020-07-30 10:37 | Reinstall      |    1   
    26 | localinstall -y /mnt/Pac | 2020-07-30 10:11 | Install        |    1   
    25 | erase tree -y            | 2020-07-30 10:10 | Erase          |    1   
    24 | install -y https://mirro | 2020-07-30 10:09 | Install        |    1   
    23 | erase tree -y            | 2020-07-30 10:08 | Erase          |    1   
    22 | install tree -y          | 2020-07-30 10:08 | Install        |    1   
    21 | remove tree -y           | 2020-07-30 10:08 | Erase          |    1  

只下载包不安装并 指定下载的路径

[root@jindada ~]# yum  install  -y  --downloadonly  --downloaddir=/opt   nginx

[root@jindada ~]# ll /opt/
total 4380
-rw-r--r-- 1 root root   93872 Jul  4  2014 centos-indexhtml-7-9.el7.centos.noarch.rpm
-rw-r--r-- 1 root root   65788 Jul  4  2014 dejavu-fonts-common-2.33-6.el7.noarch.rpm
-rw-r--r-- 1 root root 1482820 Jul  4  2014 dejavu-sans-fonts-2.33-6.el7.noarch.rpm
-rw-r--r-- 1 root root  260512 Nov 12  2018 fontconfig-2.13.0-4.3.el7.x86_64.rpm
-rw-r--r-- 1 root root   10116 Jul  4  2014 fontpackages-filesystem-1.44-8.el7.noarch.rpm
-rw-r--r-- 1 root root  149492 Jul  4  2014 gd-2.0.35-26.el7.x86_64.rpm
-rw-r--r-- 1 root root  278636 Apr 25  2018 gperftools-libs-2.6.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root  137752 Aug 23  2019 libjpeg-turbo-1.2.90-8.el7.x86_64.rpm
-rw-r--r-- 1 root root  621364 Aug 23  2019 libX11-1.6.7-2.el7.x86_64.rpm
-rw-r--r-- 1 root root  168172 Aug 23  2019 libX11-common-1.6.7-2.el7.noarch.rpm
-rw-r--r-- 1 root root   29784 Jul  4  2014 libXau-1.0.8-2.1.el7.x86_64.rpm
-rw-r--r-- 1 root root  218900 Nov 12  2018 libxcb-1.13-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   56800 Aug 11  2017 libXpm-3.5.12-1.el7.x86_64.rpm
-rw-r--r-- 1 root root  575413 Oct  4  2019 nginx-1.16.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   19857 Oct  4  2019 nginx-all-modules-1.16.1-1.el7.noarch.rpm
-rw-r--r-- 1 root root   21089 Oct  4  2019 nginx-filesystem-1.16.1-1.el7.noarch.rpm
-rw-r--r-- 1 root root   30445 Oct  4  2019 nginx-mod-http-image-filter-1.16.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   39849 Oct  4  2019 nginx-mod-http-perl-1.16.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   29613 Oct  4  2019 nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   58301 Oct  4  2019 nginx-mod-mail-1.16.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   86465 Oct  4  2019 nginx-mod-stream-1.16.1-1.el7.x86_64.rpm

[root@jindada ~]# cat /etc/yum.conf
[main]
#cachedir=/var/cache/yum/$basearch/$releasever
cachedir=/opt		#指定下载保存路径
keepcache=1			#开启缓存 

[root@jindada ~]# yum install  -y  nginx 
[root@jindada ~]# ll /opt/
total 12
drwxr-xr-x 4 root root  256 Jul 30 11:03 base
drwxr-xr-x 4 root root 4096 Jul 30 11:03 epel
drwxr-xr-x 4 root root  161 Jul 30 11:03 extras
-rw-r--r-- 1 root root  117 Jul 30 11:04 timedhosts
-rw-r--r-- 1 root root  107 Jul 30 11:03 timedhosts.txt
drwxr-xr-x 4 root root  161 Jul 30 11:03 updates
[root@jindada ~]# find  /opt/  -name  "*.rpm"
/opt/base/packages/centos-indexhtml-7-9.el7.centos.noarch.rpm
/opt/base/packages/dejavu-fonts-common-2.33-6.el7.noarch.rpm
/opt/base/packages/fontconfig-2.13.0-4.3.el7.x86_64.rpm
/opt/base/packages/dejavu-sans-fonts-2.33-6.el7.noarch.rpm
/opt/base/packages/fontpackages-filesystem-1.44-8.el7.noarch.rpm
/opt/base/packages/gd-2.0.35-26.el7.x86_64.rpm
/opt/base/packages/gperftools-libs-2.6.1-1.el7.x86_64.rpm
/opt/base/packages/libX11-1.6.7-2.el7.x86_64.rpm
/opt/base/packages/libX11-common-1.6.7-2.el7.noarch.rpm
/opt/base/packages/libXau-1.0.8-2.1.el7.x86_64.rpm
/opt/base/packages/libXpm-3.5.12-1.el7.x86_64.rpm
/opt/base/packages/libjpeg-turbo-1.2.90-8.el7.x86_64.rpm
/opt/base/packages/libxcb-1.13-1.el7.x86_64.rpm
/opt/epel/packages/nginx-all-modules-1.16.1-1.el7.noarch.rpm
/opt/epel/packages/nginx-1.16.1-1.el7.x86_64.rpm
/opt/epel/packages/nginx-filesystem-1.16.1-1.el7.noarch.rpm
/opt/epel/packages/nginx-mod-http-image-filter-1.16.1-1.el7.x86_64.rpm
/opt/epel/packages/nginx-mod-http-perl-1.16.1-1.el7.x86_64.rpm
/opt/epel/packages/nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64.rpm
/opt/epel/packages/nginx-mod-mail-1.16.1-1.el7.x86_64.rpm
/opt/epel/packages/nginx-mod-stream-1.16.1-1.el7.x86_64.rpm

五、搭建本地yum仓库

1.把之前的仓库全部将其失效

[root@jindada ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r-- 1 root root 2523 Jul 30 09:51 CentOS-Base.repo
-rw-r--r-- 1 root root  664 Jul 30 09:57 epel.repo
[root@jindada ~]# gzip  /etc/yum.repos.d/*
[root@jindada ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r-- 1 root root 601 Jul 30 09:51 CentOS-Base.repo.gz
-rw-r--r-- 1 root root 254 Jul 30 09:57 epel.repo.gz

2.挂载镜像源

[root@jindada ~]# mount  /dev/sr0   /mnt/

[root@jindada ~]# df -h  | grep  mnt
/dev/sr0        4.3G  4.3G     0 100% /mnt

3.编写yum源文件

file://			#本地

ftp://			#文件传输地址

http://			#网络协议地址

https://		#网络协议地址

[root@jindada ~]# cat /etc/yum.repos.d/lcoal.repo
[jindada]			#仓库名称  不能有空格
name=this  is  local  repo		#仓库说明信息
baseurl=file:///mnt				#仓库地址
enabled=1					#启用仓库
gpgcheck=0					#不检查其合法性  

4.测试是否可用

[root@jindada ~]# yum  clean  all
Loaded plugins: fastestmirror
Cleaning repos: jindada
Cleaning up list of fastest mirrors
Other repos take up 309 M of disk space (use --verbose for details)


[root@jindada ~]# yum  makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
jindada                                                                                               | 3.6 kB  00:00:00     
(1/4): jindada/group_gz                                                                               | 166 kB  00:00:00     
(2/4): jindada/filelists_db                                                                           | 3.2 MB  00:00:00     
(3/4): jindada/primary_db                                                                             | 3.1 MB  00:00:00     
(4/4): jindada/other_db                                                                               | 1.3 MB  00:00:00     
Metadata Cache Created


[root@jindada ~]# yum install  -y  tree

六、将本地仓库共享给其他主机

1.环境介绍

# 本地仓库地址    服务端 
10.0.0.100		

# 客户端   
10.0.0.101		

2.服务端操作

# 在10.0.0.100 主机上面操作 
[root@jindada ~]# mount  /dev/cdrom   /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@jindada ~]# df -h | grep mnt
/dev/sr0        4.3G  4.3G     0 100% /mnt

# 安装文件传输工具
[root@jindada ~]# yum  install  -y  vsftpd

# 启动
[root@jindada ~]# systemctl  start  vsftpd
[root@jindada ~]# systemctl  enable  vsftpd

# 关闭防火墙
[root@jindada ~]# systemctl  stop  firewalld

# 关闭Selinux
[root@jindada ~]# setenforce  0


# 测试
# 浏览器输出
ftp://10.0.0.100/

# 访问的是这个目录
[root@jindada ~]# ll /var/ftp/
total 0
drwxr-xr-x 2 root root 6 Oct 31  2018 pub

[root@jindada ~]# mkdir  /var/ftp/local-base
[root@jindada ~]# ll /var/ftp/
total 0
drwxr-xr-x 2 root root 6 Jul 30 19:55 local-base
drwxr-xr-x 2 root root 6 Oct 31  2018 pub
[root@jindada ~]# cp  -rp  /mnt/Packages/*  /var/ftp/local-base/

# 下载管理工具
[root@jindada ~]# yum  install  -y  createrepo

# 告诉系统,这是个镜像yum源仓库 
[root@jindada ~]# createrepo   /var/ftp/local-base/
Spawning worker 0 with 4021 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

# 修改yum配置文件
[root@jindada ~]# cat /etc/yum.repos.d/lcoal.repo
[jindada]
name=this  is  local  repo
baseurl=ftp://10.0.0.100/local-base/
enabled=1
gpgcheck=0

[root@jindada ~]# yum  repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                           repo name                                                        status
jindada                                               this  is  local  repo                                            4,021
repolist: 4,021

3.客户端操作

# 客户端修改主机名 
[root@jindada ~]# hostnamectl   set-hostname  client

# 停止防火墙和selinux
[root@client ~]# systemctl  stop  firewalld
[root@client ~]# setenforce  0

# 备份yum源
[root@client ~]# gzip  /etc/yum.repos.d/*
[root@client ~]# ll /etc/yum.repos.d/
total 28
-rw-r--r--. 1 root root 549 Nov 23  2018 CentOS-Base.repo.gz
-rw-r--r--. 1 root root 735 Nov 23  2018 CentOS-CR.repo.gz
-rw-r--r--. 1 root root 426 Nov 23  2018 CentOS-Debuginfo.repo.gz
-rw-r--r--. 1 root root 232 Nov 23  2018 CentOS-fasttrack.repo.gz
-rw-r--r--. 1 root root 381 Nov 23  2018 CentOS-Media.repo.gz
-rw-r--r--. 1 root root 506 Nov 23  2018 CentOS-Sources.repo.gz
-rw-r--r--. 1 root root 633 Nov 23  2018 CentOS-Vault.repo.gz

# 编写yum源配置文件
[root@client ~]# cat /etc/yum.repos.d/lcoal.repo
[jindada]
name=this  is  local  repo
baseurl=ftp://10.0.0.100/local-base/
enabled=1
gpgcheck=0

# 测试
[root@client ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: jindada
[root@client ~]# yum  makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
jindada                                                                                               | 2.9 kB  00:00:00     
(1/3): jindada/filelists_db                                                                           | 3.2 MB  00:00:00     
(2/3): jindada/primary_db                                                                             | 3.2 MB  00:00:00     
(3/3): jindada/other_db                                                                               | 1.3 MB  00:00:00     
Metadata Cache Created

[root@client ~]# yum  install  vim -y

七、源码包管理

1. 下载源码包

[root@jindada ~]# wget  http://nginx.org/download/nginx-1.18.0.tar.gz
[root@jindada ~]# ll
total 1016
-rw-r--r-- 1 root root 1039530 Apr 21 22:33 nginx-1.18.0.tar.gz

2. 解压软件包

[root@jindada ~]# tar  xf  nginx-1.18.0.tar.gz 
[root@jindada ~]# ll
total 1016
drwxr-xr-x 8 user05 1001     158 Apr 21 22:09 nginx-1.18.0
-rw-r--r-- 1 root   root 1039530 Apr 21 22:33 nginx-1.18.0.tar.gz

3. 进入这个目录,进行预编译操作 编译设置

[root@jindada nginx-1.18.0]# ./configure   --prefix=/opt/nginx-1.18.0   --with-http_ssl_module
checking for OS
 + Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found		#报错   缺少编译软件 gcc

4.安装依赖

[root@jindada nginx-1.18.0]# yum install  -y  gcc

5.再次执行报错

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.


#解决:

[root@jindada nginx-1.18.0]# yum install  -y  pcre  pcre-devel 

6.再次执行报错

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.


#解决:

[root@jindada nginx-1.18.0]# yum  install  -y  openssl  openssl-devel

7.编译

[root@jindada nginx-1.18.0]# make

8.将编译的结果拷贝到指定的位置

[root@jindada nginx-1.18.0]# make  install

[root@jindada nginx-1.18.0]# ll /opt/
drwxr-xr-x 6 root root   54 Jul 31 16:54 nginx-1.18.0

9.做软连接

[root@jindada ~]# ln -s  /opt/nginx-1.18.0/  /opt/nginx

10.启动

[root@jindada ~]# /opt/nginx/sbin/nginx

八、yum下载包保存到本地

1.方式一

#1.安装插件
[root@jindada ~]# yum install yum-plugin-downloadonly -y

#2.下载示例
yum install --downloadonly --downloaddir=路径 安装包名
[root@jindada ~]# yum install  --downloadonly --downloaddir=/usr/local  nginx

2.方式二

#1.安装yumdownloader
[root@jindada ~]# yum install yum-utils -y

#2.下载示例
[root@jindada ~]# yumdownloader --resolve --destdir /tmp/ansible ansible

3.方式三

以上两个方法仅会将主软件包和基于你现在的操作系统所缺少的依赖关系包一并下载。若是将下载的rpm包上传至其他机器进行离线安装很有可能还是会缺少依赖,这时可以使用repotrack进行下载。

#1.安装插件
[root@jindada ~]# yum -y install yum-utils

#2.下载示例
repotrack --download_path=指定下载目录  要安装的软件
[root@jindada ~]# repotrack --download_path=/tmp  libpcap-devel
posted @ 2020-07-31 19:15  年少纵马且长歌  阅读(518)  评论(0)    收藏  举报