红帽Redhat—Linux软件管理


一、什么是软件?

软件:
Software是一系列按照特定顺序组织的计算机数据和指令的集合。一般来讲软件被划分为系统软件、应用软件和介于这两者之间的中间件。

不同的系统平台指令不同,因此软件也不同,所以在不同类别的系统中,软件并不能通用,比如微软系统中的exe安装包,一般无法在linux系统中安装。

在Linux界有两大常见的软件安装方式:DPKG、RPM。
DPKG最早由debian linux社区开发,B2D和ubuntu主要用这种安装方式。
RPM最早是由red hat研发,fedora、CentOS、SuSE等知名的开发商都是用该种方式。

RPM介绍:
RedHat Package Manager 是以一种数据库记录的方式来将所需要的软件安装到 Linux 系统的一套管理机制。

特性:
在通用平台上将软件编译好,打包成为 RPM 机制的包 [安装环境已定制化]。记录并检查软件安装的依赖包,安装的时候就将该软件的信息整个写入 RPM 的数据库中,供后续查询、升级和卸载。

RPM软件包文件采用的软件名称组合name-­version­-release.architecture的命名方式进行命名。
httpd­2.4.6­88.el7.x86_64.rpm [软件名­版本号­编译次数.发行商版本.处理器平台]
name:描述其内容的一个或多个单词 (httpd)
version: 软件的原始版本号 (2.4.6)
release:在原始的发行版本号基础上,被新的软件开发商编译的次数及新的命名(88.el7)
arch:该软件可运行的处理机器架构 (x86_64);"noarch"表示不限定架构(目前常见的几种处理器硬件架构:x86、arm、PowerPC)

二、虚拟机设置

1.点击虚拟机->设置。
在这里插入图片描述
2.点击CD/DVD(SATA)->使用IOS映像文件->已连接->浏览。
在这里插入图片描述
3.点击rhel-8.3-x86_64-dvd.ios->打开。
在这里插入图片描述
4.点击确定
在这里插入图片描述
5.查看右下角状态
在这里插入图片描述

三、RPM使用

1.本地软件包

RHEL7只有一个软件仓库。

[root@server ~]# mount /dev/sr0 /media/				//临时挂载rhel7.8的镜像文件
[root@server Packages]# cd /media/Packages/
[root@server Packages]# ls | wc -l					//查看当前文件夹文件数量
5232

RHEL8有两个软件仓库。

[root@server ~]# mount /dev/sr0 /media/				//临时挂载rhel8.3的镜像文件
[root@server ~]# cd /media/AppStream/Packages/
[root@server Packages]# ls | wc -l
5803
[root@server Packages]# cd /media/BaseOS/Packages/
[root@server Packages]# ls | wc -l					//查看当前文件夹文件数量
1697

2.网络软件包

软件下载网站http://rpmfind.net/

1.在输入框输入cowsay回车在这里插入图片描述
2.找到cowsay-3.04-16.el8.noarch.html Configurable speaking/thinking cow EPEL 8 for x86_64 cowsay-3.04-16.el8.noarch.rpm在这里插入图片描述
3.拷贝链接
在这里插入图片描述
4.在SecurtCRT输入wget 粘贴链接
在这里插入图片描述
5.下载软件包
wget

[root@server ~]# wget http://rpmfind.net/linux/epel/8/Everything/x86_64/Packages/c/cowsay-3.04-16.el8.noarch.rpm
--2021-01-20 10:04:08--  http://rpmfind.net/linux/epel/8/Everything/x86_64/Packages/c/cowsay-3.04-16.el8.noarch.rpm
Resolving rpmfind.net (rpmfind.net)... 195.220.108.108
Connecting to rpmfind.net (rpmfind.net)|195.220.108.108|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 47728 (47K) [application/x-rpm]
Saving to: ‘cowsay-3.04-16.el8.noarch.rpm’

cowsay-3.04-16.el8.no 100%[========================>]  46.61K  20.2KB/s    in 2.3s    

2021-01-20 10:04:13 (20.2 KB/s) - ‘cowsay-3.04-16.el8.noarch.rpm’ saved [47728/47728]

3.安装软件包

1.软件安装
rpm -­ivh package_name
可以同时安装多个软件,软件包可以下载到本地,也可以是通过网络安装。
-­i :安装
­-v:显示指令的执行过程
-­h:显示安装进度
--­­nodeps 忽略包依赖关系
--­­force 强制安装,实现降级或重装
--­­replacepkgs 替换原有安装
rpm -ivh

[root@server ~]# rpm -ivh /root/cowsay-3.04-16.el8.noarch.rpm			//安装软件cowsay
warning: /root/cowsay-3.04-16.el8.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:cowsay-3.04-16.el8               ################################# [100%]

2.使用软件cowsay hello

[root@server ~]# cowsay hello
 _______
< hello >
 -------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
[root@server ~]# 

3.查询
rpm ­-q PACKGE_NAME 查询包是否安装
-­qa 查询所有已安装的包

[root@server ~]# rpm -qa cowsay
cowsay-3.04-16.el8.noarch

-­qi查询指定包的说明信息 (已安装的包)

[root@server ~]# rpm -qi cowsay
Name        : cowsay			[软件名字]
Version     : 3.04				[软件的原版本]
Release     : 16.el8			[发布的版本]
Architecture: noarch			[软件的编译架构]
Install Date: Wed 20 Jan 2021 10:09:14 AM CST		[软件安装的时间]
Group       : Unspecified
Size        : 78642				[软件的总大小]
License     : GPLv3+			[授权]
Signature   : RSA/SHA256, Fri 20 Nov 2020 05:47:34 AM CST, Key ID 21ea45ab2f86d6a1
Source RPM  : cowsay-3.04-16.el8.src.rpm
Build Date  : Fri 20 Nov 2020 05:46:13 AM CST
Build Host  : buildvm-x86-13.iad2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://github.com/tnalpgge/rank-amateur-cowsay
Bug URL     : https://bugz.fedoraproject.org/cowsay
Summary     : Configurable speaking/thinking cow
Description :
cowsay is a configurable talking cow, written in Perl.  It operates
much as the figlet program does, and it written in the same spirit
of silliness.
It generates ASCII pictures of a cow with a message. It can also generate
pictures of other animals.

-­ql查询指定包安装后生成的文件列表

[root@server ~]# rpm -ql cowsay
/usr/bin/animalsay
/usr/bin/cowsay
/usr/bin/cowthink
/usr/share/bash-completion
/usr/share/bash-completion/completions
/usr/share/bash-completion/completions/cowsay.bashcomp
......

-­qc 查询指定包安装后的配置文件

[root@server ~]# 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-optional.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

­-qd 查询指定包安装后的帮助文件

[root@server ~]# rpm -qd cowsay
/usr/share/doc/cowsay/ChangeLog
/usr/share/doc/cowsay/LICENSE
/usr/share/doc/cowsay/README
/usr/share/man/man1/cowsay.1.gz
/usr/share/man/man1/cowthink.1.gz

­-qf 查询指定的文件是由哪个包安装产生的

[root@server ~]# rpm -qf /usr/share/doc/cowsay/ChangeLog
cowsay-3.04-16.el8.noarch

­-­qpi ­查询未安装包的信息

[root@server ~]# rpm -qpi cowsay-3.04-16.el8.noarch.rpm 
warning: cowsay-3.04-16.el8.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
Name        : cowsay
Version     : 3.04
Release     : 16.el8
Architecture: noarch
Install Date: (not installed)
Group       : Unspecified
Size        : 78642
License     : GPLv3+
Signature   : RSA/SHA256, Fri 20 Nov 2020 05:47:34 AM CST, Key ID 21ea45ab2f86d6a1
Source RPM  : cowsay-3.04-16.el8.src.rpm
Build Date  : Fri 20 Nov 2020 05:46:13 AM CST
Build Host  : buildvm-x86-13.iad2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://github.com/tnalpgge/rank-amateur-cowsay
Bug URL     : https://bugz.fedoraproject.org/cowsay
Summary     : Configurable speaking/thinking cow
Description :
cowsay is a configurable talking cow, written in Perl.  It operates
much as the figlet program does, and it written in the same spirit
of silliness.
It generates ASCII pictures of a cow with a message. It can also generate
pictures of other animals.

-­qpl 查询未安装包在安装后生成的文件列表

[root@server ~]# rpm -qpl cowsay-3.04-16.el8.noarch.rpm 
warning: cowsay-3.04-16.el8.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
/usr/bin/animalsay
/usr/bin/cowsay
/usr/bin/cowthink
/usr/share/bash-completion
/usr/share/bash-completion/completions
/usr/share/bash-completion/completions/cowsay.bashcomp
/usr/share/cowsay
......

RPM默认的文件安装路径:
/usr/bin 一些可执行文件
/usr/lib 一些程序使用的动态函数库
/usr/share/doc 一些基本的软件使用手册与帮助文档
/usr/share/man 一些man page文件

升级
rpm ­-Uvh 如果有旧版版则升级,否则安装。
rpm -­Fvh 如果有旧版本则升级,否则退出。

卸载
rpm -e PACKGE_NAME

[root@server ~]# rpm -e cowsay 
[root@server ~]# rpm -qa cowsay 

重建rpm数据库

[root@server ~]# rpm --rebuilddb		//重建数据库
[root@server ~]# rpm --initdb			//初始化数据库,没有则建立

如何查看当前系统版本及升级系统版本
RHEL7.8:

[root@server ~]# uname -a
Linux server 3.10.0-1127.el7.x86_64 #1 SMP Tue Feb 18 16:39:12 EST 2020 x86_64 x86_64 x86_64 GNU/Linux

RHEL8.0:

[root@server ~]# uname -a
Linux server 4.18.0-240.el8.x86_64 #1 SMP Wed Sep 23 05:13:10 EDT 2020 x86_64 x86_64 x86_64 GNU/Linux

RHEL7.8:

[root@server ~]# more /etc/os-release 
NAME="Red Hat Enterprise Linux Server"
VERSION="7.8 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="7.8"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.8 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.8:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.8
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.8"

RHEL8.3:

[root@server ~]# cat /etc/os-release 
NAME="Red Hat Enterprise Linux"
VERSION="8.3 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.3"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.3 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8.3:GA"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.3
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.3"

RHEL7.8:

[root@server ~]# rpm -qa kernel
kernel-3.10.0-1127.el7.x86_64

RHEL8.3:

[root@server ~]# rpm -qa kernel
kernel-4.18.0-240.el8.x86_64

升级内核:

[root@server ~]# rpm -ivh kernel-4.18.0-80.el8.x86_64.rpm

四、YUM介绍

Yellow dog Update Modified(yellow dog是Linux的一个发行版本)。
YUM是Fedora、RedHat、CentOS中的前端软件包管理器,使用Python编写。

1.YUM原理:

使用一个仓库管理所有应用程序,通过程序间关系计算出软件的依赖关系进行软件安装、升级、删除、查询等操作。
通过一个或多个配置文件来描述仓库的网络地址,通过http或ftp协议从仓库获得信息,下载相关软件包。

RHEL7
yum基于3.0.x版本

RHEL8
包管理由DNF (YUMv4)完成。

yum4基于DNF技术,yum4命令提供了与早期版本中使用的Yum v3的向后兼容性。yum命令只是到dnf的一个符号链接。

2.配置本地YUM源

配置文件/etc/yum.repos.d/*.repo该目录下所有以.repo结尾的文件都是yum的有效配置文件。
配置文件主要参数:
[rhel7]
仓库id。
name=Packages
仓库名称­­。
baseurl=file:///media
­­仓库地址 ,可以是本地目录也可以是网络上的路径file表示使用本地路径,http和ftp表示使用网络路径。
gpgcheck=0
是否校验仓库内软件包,0不校验,1校验,如果校验需要指明校验密钥。
enabled=1
是否启用该yum仓库,0不启用,1启用(只有一个仓库可以不用设置)。
priority=1
­­设置仓库优先级,数字越小越优。

RHEL7只有一个本地软件仓库。

[root@server ~]# vim /etc/yum.repos.d/rhel7.repo
[Packages]
name=Packages
baseurl=file:///media
gpgcheck=0
enabled=1

RHEL8有两个本地软件仓库。

[root@server ~]# vim /etc/yum.repos.d/rhel8.repo
[BaseOS]
name=BaseOS
baseurl=file:///media/BaseOS
gpgcheck=0
enable=1

[AppStream]
name=AppStream
baseurl=file:///media/AppStream
gpgcheck=0
enable=1
[root@server ~]# yum makecache		//生成软件仓库缓存
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

BaseOS                                                  94 MB/s | 2.3 MB     00:00    
AppStream                                               74 MB/s | 6.3 MB     00:00    
Last metadata expiration check: 0:00:01 ago on Thu 21 Jan 2021 08:39:18 AM CST.
Metadata cache created.
[root@server ~]# yum list			//查看仓库软件列表

3.配置网络YUM源

本地yum源可能有局限性,当本地的yum源无法满足软件安装需求的时候,可以选择网络yum源,前提是主机必须能访问外网。
阿里云官方镜像站https://developer.aliyun.com/mirror/
1.找到epel
在这里插入图片描述
2.点击复制命令粘贴到SecureCRT
在这里插入图片描述

[root@server ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Last metadata expiration check: 1:24:35 ago on Thu 21 Jan 2021 08:44:33 AM CST.
epel-release-latest-8.noarch.rpm                       111 kB/s |  22 kB     00:00    
Dependencies resolved.
=======================================================================================
 Package               Architecture    Version             Repository             Size
=======================================================================================
Installing:
 epel-release          noarch          8-10.el8            @commandline           22 k

Transaction Summary
=======================================================================================
Install  1 Package

Total size: 22 k
Installed size: 32 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                               1/1 
  Installing       : epel-release-8-10.el8.noarch                                  1/1 
  Running scriptlet: epel-release-8-10.el8.noarch                                  1/1 
  Verifying        : epel-release-8-10.el8.noarch                                  1/1 
Installed products updated.

Installed:
  epel-release-8-10.el8.noarch                                                         

Complete!
[root@server ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Extra Packages for Enterprise Linux Modular 8 - x86_64  19 kB/s | 537 kB     00:28    
Extra Packages for Enterprise Linux 8 - x86_64         174 kB/s | 8.8 MB     00:51    
Last metadata expiration check: 0:00:03 ago on Thu 21 Jan 2021 10:10:39 AM CST.
epel-release-latest-8.noarch.rpm                        42 kB/s |  22 kB     00:00    
Package epel-release-8-10.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!

还有RHEL7,RHEL6,RHEL5。
在这里插入图片描述

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

4.YUM代理

如果主机不方便访问外部网络,可以通过内部可上网的主机做代理。
proxy=https://www.XXXXX.com:8080 前面为代理地址或域名,后面为端口。
proxy_username=XXXXX 代理服务器的用户名。
proxy_password=XXXXX 代理服务器的密码。

5.YUM安装软件

yum -­y install PACKGE_NAME
-y 自动应答yes

[root@server ~]# yum install -y httpd
[root@server ~]# yum ­-y install sl

yum ­y groupinstall PACKGE_GROUP_NAME

[root@server ~]# yum ­-y groupinstall “KDE Desktop”

6.YUM查询

yum list 列出yum仓库中的软件列表。
yum list installed 列出已安装的。

[root@server ~]# yum list installed | wc -l
[root@server ~]# yum list updates			//列出可以升级的
[root@server ~]# yum grouplist				//列出包组

yum info PACKGE_NAME 查看软件包信息

[root@server ~]# yum info cowsay
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Last metadata expiration check: 2:24:00 ago on Thu 21 Jan 2021 11:56:26 AM CST.
Installed Packages			[该软件是已经安装好的]
Name         : cowsay		[软件的名称]
Version      : 3.04			[软件的源版本]
Release      : 16.el8		[发布的版本]
Architecture : noarch		[软件的编译架构]
Size         : 77 k			[软件的总大小]
Source       : cowsay-3.04-16.el8.src.rpm
Repository   : @System
From repo    : epel
Summary      : Configurable speaking/thinking cow
URL          : https://github.com/tnalpgge/rank-amateur-cowsay
License      : GPLv3+		[授权]
Description  : cowsay is a configurable talking cow, written in Perl.  It operates
             : much as the figlet program does, and it written in the same spirit
             : of silliness.
             : It generates ASCII pictures of a cow with a message. It can also
             : generate pictures of other animals.

7.YUM卸载软件

yum remove | erase PACKGE_NAME

[root@server ~]# yum -y remove sl

8.YUM升级软件

[root@server ~]# yum update 

9.YUM缓存

[root@server ~]# yum makecache			//生成缓存
[root@server ~]# yum clean all			//清空缓存

END

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值