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)

RPM使用: 安装包下载: 本地软件包: [root@df_rhel ~]# mount /dev/sr0 /media/ [root@df_rhel ~]# cd /media/Packages/ [root@df_rhel Packages]# ls | wc -l 5100

网络软件包: http://rpmfind.net/

wget http://rpmfind.net/linux/fedora-secondary/releases/30/Everything/s390x/os/Packages/c/cowsay-3.04-12.fc30.noarch.rpm

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

查询 #rpm -q PACKGE_NAME 查询包是否安装 -qa 查询所有已安装的包 [root@df_rhel ~]# rpm -qa cowsay cowsay-3.04-12.fc30.noarch [root@df_rhel ~]# rpm -qa telnet telnet-0.17-64.el7.x86_64

-qi 查询指定包的说明信息 (已安装的包) [root@df_rhel ~]# rpm -qi cowsay Name : cowsay Version : 3.04 Release : 12.fc30 Architecture: noarch Install Date: Sat 18 May 2019 11:34:15 AM EDT Group : Unspecified Size : 78106 License : GPLv3+ Signature : RSA/SHA256, Thu 07 Feb 2019 12:39:22 AM EST, Key ID ef3c111fcfc659b9 Source RPM : cowsay-3.04-12.fc30.src.rpm ........

-ql 查询指定包安装后生成的文件列表 [root@df_rhel ~]# rpm -ql telnet /usr/bin/telnet /usr/share/doc/telnet-0.17 /usr/share/doc/telnet-0.17/README /usr/share/man/man1/telnet.1.gz

-qc 查询指定包安装后的配置文件 [root@df_rhel ~]# rpm -qc httpd

-qd 查询指定包安装后的帮助文件 [root@df_rhel ~]# 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 /path/file 查询指定的文件是由哪个包安装产生的 [root@df_rhel ~]# rpm -qf /usr/share/doc/cowsay/ChangeLog cowsay-3.04-12.fc30.noarch

-qpi 查询未安装包的信息 [root@df_rhel ~]# rpm -qpi cowsay-3.04-12.fc30.noarch.rpm

-qpl 查询未安装包在安装后生成的文件列表 [root@df_rhel ~]# rpm -qpl cowsay-3.04-12.fc30.noarch.rpm

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

升级 #rpm -Uvh 如果有旧版版则升级,否则安装 #rpm -Fvh 如果有旧版本则升级,否则退出 [root@df_rhel ~]# rpm -qa telnet [root@df_rhel ~]# rpm -Fvh telnet-0.17-64.el7.x86_64.rpm warning: telnet-0.17-64.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY [root@df_rhel ~]# rpm -Uvh telnet-0.17-64.el7.x86_64.rpm warning: telnet-0.17-64.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:telnet-1:0.17-64.el7 ################################# [100%]

卸载 #rpm -e PACKGE_NAME
[root@df_rhel ~]# rpm -e telnet [root@df_rhel ~]# rpm -qa telnet

重建rpm数据库 #rpm --rebuilddb 重建数据库 #rpm --initdb 初始化数据库,没有则建立

如何查看当前系统版本及升级系统版本 RHEL7.5: [root@df_rhel ~]# uname -a Linux df_rhel 3.10.0-862.el7.x86_64 #1 SMP Wed Mar 21 18:14:51 EDT 2018 x86_64 x86_64 x86_64 GNU/Linux

RHEL8.0: [root@myth_8 ~]# uname -a Linux myth_8.0 4.18.0-80.el8.x86_64 #1 SMP Wed Mar 13 12:02:46 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

RHEL7.5: [root@df_rhel ~]# more /etc/os-release NAME="Red Hat Enterprise Linux Server" VERSION="7.5 (Maipo)" ID="rhel" ID_LIKE="fedora" VARIANT="Server" VARIANT_ID="server" VERSION_ID="7.5" PRETTY_NAME="Red Hat Enterprise Linux Server 7.5 (Maipo)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:redhat:enterprise_linux:7.5: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.5 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux" REDHAT_SUPPORT_PRODUCT_VERSION="7.5"

RHEL8.0: [root@myth_8 ~]# cat /etc/os-release NAME="Red Hat Enterprise Linux" VERSION="8.0 (Ootpa)" ID="rhel" ID_LIKE="fedora" VERSION_ID="8.0" PLATFORM_ID="platform:el8" PRETTY_NAME="Red Hat Enterprise Linux 8.0 (Ootpa)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:redhat:enterprise_linux:8.0: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.0 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux" REDHAT_SUPPORT_PRODUCT_VERSION="8.0"

RHEL7.5: [root@df_rhel ~]# rpm -qa kernel kernel-3.10.0-862.el7.x86_64

RHEL8.0: [root@myth_8 ~]# rpm -qa kernel kernel-4.18.0-80.el8.x86_64

升级内核: [root@df_rhel ~]# rpm -ivh kernel-4.18.0-80.el8.x86_64.rpm

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

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

YUM基本操作: 配置本地YUM源 配置文件 /etc/yum.repos.d/*.repo ,该目录下所有以.repo结尾的文件都是yum的有效配置文件
配置文件主要参数: [rhel7]
--仓库id name=qm
--仓库名称 baseurl=file:///media
--仓库地址 ,可以是本地目录也可以是网络上的路径file表示使用本地路径,http和ftp表示使用网络路径 gpgcheck=0
--是否校验仓库内软件包,0不校验,1校验,如果校验需要指明校验密钥 enabled=1
--是否启用该yum仓库,0不启用,1启用

priority=1 (只有一个仓库可以不用设置) --设置仓库优先级,数字越小越优

#yum list 查看仓库软件列表

#yum makecache 生成软件仓库缓存

配置网络yum源: 本地yum源可能有局限性,当本地的yum源无法满足软件安装需求的时候,可以选择网络yum源,前提是主机必须能访问外网 https://opsx.alibaba.com/

[root@df_rhel ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

[root@df_rhel ~]# cat /etc/yum.repos.d/epel.repo

yum代理: 如果主机不方便访问外部网络,可以通过内部可上网的主机做代理 proxy=https://www.ahdifu.com:8080 前面为代理地址或域名,后面为端口

proxy_username=myth 代理服务器的用户名

proxy_password=ahdifu.com 代理服务器的密码

YUM使用: yum安装软件 #yum -y install PACKGE_NAME ---y 自动应答yes [root@df_rhel ~]# yum -y install sl

#yum -y groupinstall PACKGE_GROUP_NAME [root@df_rhel ~]# yum -y groupinstall “KDE Desktop”

yum查询 #yum list 列出yum仓库中的软件列表 #yum list installed 列出已安装的 [root@df_rhel ~]# yum list installed | wc -l

#yum list updates 列出可以升级的

#yum grouplist 列出包组

#yum info PACKGE_NAME 查看软件包信息 [root@df_rhel ~]# yum info cowsay 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. Installed Packages [该软件是已经安装好的] Name : cowsay [软件的名称] Arch : noarch [软件的编译架构] Version : 3.04 [软件的源版本] Release : 12.fc30 [发布的版本] Size : 76 k [软件的总大小] Repo : installed Summary : Configurable speaking/thinking cow URL : https://github.com/tnalpgge/rank-amateur-cowsay License : GPLv3+ [授权] .......

yum卸载软件 #yum remove | erase PACKGE_NAME [root@df_rhel ~]# yum -y remove sl

yum升级软件 #yum update

YUM缓存 生成缓存 #yum makecache 清空缓存 #yum clean all