Linux下的软件管理(Redhat 8)

本文详细介绍了Linux Redhat 8系统下,如何管理软件,特别是使用rpm命令和yum仓库来解决软件依赖关系。内容涵盖rpm包分析、yum仓库搭建目的与步骤、yum命令的使用,以及第三方软件仓库的创建和共享软件仓库的测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.软件安装包格式类型

安装包格式类型适用的系统
rpmlinux(suse centos redhat)
debub deb
tar绿色软件
源码编译

二.rpm包名称分析

[dhcp]-[4.2.5-68].[el7_5.1].[x86_64].[rpm]

rpm包名称说明
dhcp软件名称
4.2.5-68软件版本
el7_5.1软件授权
x86_64软件多少位
rpm软件后缀表示软件包是rpm类型的

在管理rpm软件包时用rpm命令

三.rpm命令

1.rpm管理命令

命令含义
rpm -ivh安装
rpm -v显示过程
rpm -hhash 检测查看软件中的hash值是否有改变
rpm -iinstall 安装
rpm -e卸载
rpm -q查看
rpm -a所有
rpm -qa查看所有安装过的软件
rpm -l列出安装然后在系统中生成的文件
rpm -p操作对象为软件包
rpm --scripts查看软件在安装或卸载时在系统中执行的脚本
rpm --force强制安装
rpm -nodeps忽略软件依赖性安装
rpm -K检测软件是否是原版软件

2.设定实验环境

1.建立系统安装镜像挂载点

mkdir /software

2.在虚拟机光驱中添加系统匹配镜像
3.挂载镜像到/software

mount /dev/cdrom /software    ##适用于虚拟机光驱中有镜像
mount /iso/rhel-server-7.3-x86_64-dvd.iso /software  ##适用于虚拟机中有镜像文件

4.ls /software/

[root@rhel7 ~]# ls /software/
addons            GPL       media.repo               RPM-GPG-KEY-redhat-release
EFI               images    Packages                 TRANS.TBL
EULA              isolinux  repodata
extra_files.json  LiveOS    RPM-GPG-KEY-redhat-beta

3.软件包如何拆解

rpm2cpio dhcp-4.2.5-68.el7_5.1.x86_64.rpm | cpio -id

四.yum软件仓库

1.软件仓库搭建的目的

rpm不能自动解决软件依赖关系
yum仓库可以解决此问题
上层软件管理工具,最重要的功能是可以解决软件的倚赖关系
yum能够投入使用的前提是必须要有yum源,以及配置源的指向文件

2.搭建软件仓库的步骤

1.得到与当前系统匹配的系统安装镜像文件
2.建立系统安装镜像挂载点:

mkdir /softwaresource

3.挂载镜像到镜像挂载点:

mount /iso/rhel-server-7.3-x86_64-dvd.iso /softwaresource
mount /dev/cdrom /softwaresource

4.配置系统访问软件路径(yum仓库指向文件)

cd /etc/yum.repos.d/
rm -fr *

在rhel7中

vim yum.repo
[rhel7] 						#仓库名称
name=westos rhel7 source 		#仓库描述
baseurl=file:///softwaresource 	#资源路径
gpgcheck=0|1 					#软件包授权检测开关
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release #软件包授权码
enabled=1 						#仓库启用开关

在rhel8中

vim yum.repo
[rhel8AppStream] 			#仓库名称
name=rhel8 source AppStream #仓库描述
baseurl=file:///softwaresource/AppStream #资源路径
gpgcheck=0|1 				#软件包授权检测开关
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release #软件包授权码
enabled=1					 #仓库启用开关

[rhel8BaseOS] 				#仓库名称
name=rhel7 source BaseOS 	#仓库描述
baseurl=file:///softwaresource/BaseOS #资源路径
gpgcheck=0|1 				#软件包授权检测开关
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release#软件包授权码
enabled=1 					#仓库启用开关

5.清空yum缓存识别新文件案内容
rhel7:

yum clean all

rhel8

dnf clean all

企业8中依然可以使用yum,yum其实是dnf的一个软链接

[root@rhel8_clone ~]# ls -l /bin/yum
lrwxrwxrwx. 1 root root 5 Feb 14  2019 /bin/yum -> dnf-36.查看软件仓库

rhel7:

[root@rhel7 yum.repos.d]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
rhel7                                                    | 4.3 kB     00:00     
(1/2): rhel7/group_gz                                      | 146 kB   00:00     
(2/2): rhel7/primary_db                                    | 4.2 MB   00:00     
repo id                           repo name                               status
rhel7                             rhel7 source                            5,152
repolist: 5,152

rhel8:

[root@rhel8_clone yum.repos.d]# dnf repolist
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.
rhel8 source AppStream                           30 MB/s | 5.3 MB     00:00    
rhel8 source BaseOS                              24 MB/s | 2.2 MB     00:00    
repo id                         repo name                                 status
rhel8AppSream                   rhel8 source AppStream                    4,672
rhel8BaseOS                     rhel8 source BaseOS                       1,658

五.yum命令

命令说明
yum install安装
yum remove卸载
yum reinstall重新安装
yum list installedavailable
yum update更新
yum repolist列出仓库信息
yum history查看yum历史
yum info查看软件包信息
yum clean all清除yum缓存
yum search根据软件信息搜索
yum whatprovides根据软件包含文件搜索
yum groups install组安装
yum groups remove组卸载
yum groups info组信息
[root@rhel7 ~]# yum history 		##查看yum历史
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     5 | root <root>              | 2020-02-19 00:08 | Reinstall      |    1   
     4 | root <root>              | 2020-02-19 00:08 | Install        |    1   
     3 | root <root>              | 2020-02-19 00:07 | Erase          |    1   
     2 | root <root>              | 2020-02-19 00:07 | Install        |    5  <
     1 | System <unset>           | 2020-02-12 07:41 | Install        | 1390 > 
history list
[root@rhel7 ~]# yum history info 5  ##查看yum历史第五条软件包信息
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Transaction ID : 5
Begin time     : Wed Feb 19 00:08:38 2020
Begin rpmdb    : 1396:a9b8b73d9e0589bef582f07fa390fd53cc057e08
End time       :            00:08:39 2020 (1 seconds)
End rpmdb      : 1396:a9b8b73d9e0589bef582f07fa390fd53cc057e08
User           : root <root>
Return-Code    : Success
Command Line   : reinstall httpd -y
Transaction performed with:
    Installed     rpm-4.11.3-35.el7.x86_64                  @anaconda/7.6
    Installed     subscription-manager-1.21.10-2.el7.x86_64 @anaconda/7.6
    Installed     yum-3.4.3-161.el7.noarch                  @anaconda/7.6
Packages Altered:
    Reinstall httpd-2.4.6-88.el7.x86_64 @rhel7
history info

六.第三方软件仓库

我们以第三方画图软件kolourpaint为例:
1.把所有rpm结尾的软件包存放到一个目录/software中

[root@rhel7 software]# ls
kolourpaint-4.10.5-4.el7.x86_64.rpm  kolourpaint-libs-4.10.5-4.el7.x86_64.rpm

2.createrepo -v /software ##生成软件数据库存放软件属性
在这里插入图片描述
3.修改yum仓库指向文件

vim /etc/yum.repos.d/yum.repo
[software]
name=software
baseurl=file:///software
gpgcheck=0

4.yum clean all
5.安装kolourpaint软件

yum install kolourpaint -y

画图软件kolourpaint安装成功
在这里插入图片描述

七.共享软件安仓库

1.软件仓库支持的访问方式

访问方式说明
file://本地文件
ftp://文本传输协议
http://超文本传输协议
nfs网络文件系统

2.搭建共享软件仓库的方式

1.在含有软件资源的主机中安装共享软件

yum install vsftpd -y
systemctl start vsftpd
systemctl enable vsftpd

2.关闭selinux和firewalld
关闭selinux:

[root@rhel7 ~]# getenforce 
Enforcing			 ##selinux开启
关闭selinux:
vim /etc/sysconfig/selinux
7 SELINUX=disabled
reboot

关闭firewalld:

systemctl stop firewalld
systemctl disable firewalld

3.建立共享目录

mkdir /var/ftp/rhel7.6 /var/ftp/software

4.在共享目录中存放软件资源
把所有第三方软件放入/var/ftp/software并执行

createrepo -v   /var/ftp/software

挂载系统安装镜像资源到/var/ftp/rhel7.6

mount /dev/cdrom /var/ftp/rhel7.6 ##使用此命令挂载为临时挂载

永久挂载系统安装景象资源到/var/ftp/rhel7.6

vim /etc/rc.d/rc.local
mount /dev/cdrom /var/ftp/rhel7.6
chmod +x /etc/rc.d/rc.local

3.测试:

在rhel7_node2:
firefox ftp://192.168.1.103/software ##显示资源
在这里插入图片描述
firefox ftp://192.168.1.103/rhel7.6 ##显示资源
在这里插入图片描述

vim /etc/yum.repos.d/westos.repo
[rhel7.6]
name=rhel7.6
baseurl=ftp://192.168.1.103/rhel7.6
gpgcheck=0
[software]
name=software
baseurl=ftp://192.168.103/software
gpgcheck=0

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值