十一.软件管理

一.使用RPM安装软件

1.RPM包简介

        Linux整个体系的关键不在于系统本身,而是在于可以基于linux系统去安装和配置的企业中的相关软件,数据以及应用程序,而在Linux中软件包的类型就像Linux发行版本一样丰富多样,目前比较流行的软件包格式有∶可以直接执行的rpm的二进制包,源码形式的tar.gz . tar.bz2、gzip与bzip2的源码包。

        源码包(source code)︰源代码包是没有经过编译的包,需要经过GCC、C++编译环境才能运行

        二进制包(binary code)︰无需编译,可以直接安装使用

        RPM软件包文件名由四个元素组成(在加上.rpm后缀) ︰ name-version-release-architectur

vsftpd-3.0.3-28.el8.x86_64.rpm

l              l             l          l

name version release  Arch

        name:是描述其内容的一个或多个次词语(coreutils)

        version:是原始软件的版本号(8.30)

        release︰是基于该版本的软件包的发行版本,由软件打包商设置,后者不一定是原始软件开发商(6.el8)

        Arch:是编译的软件包运行的处理器架构,noarch表示此软件包的内容不限定架构

2.安装与卸载rpm包

对于rpm软件包的安装,我们可以使用这样的方式来进行安装,但该命令默认为静默式安装,如果需要了解安装过程信息,则需要使用-v来显示详细的信息,-h 显示安装进度。

命令:rpm:安装rpm软件包

语法:rpm [选项] 软件包名称

选项:

-h         软件包安装的时候列出哈希标记(和-v一起使用效果更好)

-i          安装软件包

-v         显示详细信息

-e         清除(卸载)软件包

-u         升级软件(仅保留旧配置文件)安装

[root@localhost Packages]# find /mnt/ -name "vsftpd*"            #rpm安装必须知道文件在哪里
/mnt/AppStream/Packages/vsftpd-3.0.3-32.el8.x86_64.rpm
[root@localhost Packages]# cd /
[root@localhost /]# rpm -ivh  vsftpd-3.0.3-32.el8.x86_64.rpm        #不在此目录下,就下载不了
error: open of vsftpd-3.0.3-32.el8.x86_64.rpm failed: No such file or directory
[root@localhost Packages]# rpm -ivh  vsftpd-3.0.3-32.el8.x86_64.rpm        #也可以吧他路径写全,这样无论在哪个路径下面,就无所谓能不能下载了
warning: vsftpd-3.0.3-32.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:vsftpd-3.0.3-32.el8              ################################# [100%]
[root@localhost /]# rpm -e vsftpd        #卸载软件包

3.软件包信息查询

RPM命令工具包提供了强大的软件查询功能,格式可以进行大量的查询工作,查询有很多选项如:

-q           查询指定软件包是否已经安装,如果安装显示软件包详细信息,否则显示"“package * is not installed"

-qa         查询系统中已经安装的所有软件

-qi          查询指定软件包的详细信息

-ql          查询指定软件的安装路径与文件列表

-qc         查询指定软件的配置文件

-qf          查询指定文件属于那个包

[root@localhost /]# rpm -q vsftpd
package vsftpd is not installed
[root@localhost /]# rpm -ivh  /mnt/AppStream/Packages/vsftpd-3.0.3-32.el8.x86_64.rpm
warning: /mnt/AppStream/Packages/vsftpd-3.0.3-32.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:vsftpd-3.0.3-32.el8              ################################# [100%]

[root@localhost /]# rpm -q vsftpd
vsftpd-3.0.3-32.el8.x86_64
[root@localhost /]# rpm -qa | wc -l
398
[root@localhost /]# rpm -qi vsftpd
Name        : vsftpd
Version     : 3.0.3
Release     : 32.el8
Architecture: x86_64
Install Date: Mon 18 Jul 2022 11:25:46 PM EDT
Group       : System Environment/Daemons
Size        : 351530
License     : GPLv2 with exceptions
Signature   : RSA/SHA256, Tue 17 Mar 2020 11:53:09 AM EDT, Key ID 199e2f91fd431d51
Source RPM  : vsftpd-3.0.3-32.el8.src.rpm
Build Date  : Tue 17 Mar 2020 10:46:09 AM EDT
Build Host  : x86-vm-07.build.eng.bos.redhat.com
Relocations : (not relocatable)
Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Vendor      : Red Hat, Inc.
URL         : https://security.appspot.com/vsftpd.html
Summary     : Very Secure Ftp Daemon
Description :
vsftpd is a Very Secure FTP daemon. It was written completely from
scratch.
[root@localhost /]# rpm -ql vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
/etc/vsftpd/vsftpd_conf_migrate.sh
/usr/lib/.build-id
/usr/lib/.build-id/b6
/usr/lib/.build-id/b6/c57c01489dd60292e3bd88c21dd8c2dd8d3e4f
/usr/lib/systemd/system-generators/vsftpd-generator
/usr/lib/systemd/system/vsftpd.service
/usr/lib/systemd/system/vsftpd.target
/usr/lib/systemd/system/vsftpd@.service
/usr/sbin/vsftpd
/usr/share/doc/vsftpd
/usr/share/doc/vsftpd/AUDIT
/usr/share/doc/vsftpd/BENCHMARKS
/usr/share/doc/vsftpd/BUGS
/usr/share/doc/vsftpd/COPYING
/usr/share/doc/vsftpd/Changelog
/usr/share/doc/vsftpd/EXAMPLE
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE/README
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE/vsftpd.conf
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE/vsftpd.xinetd
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE_NOINETD
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE_NOINETD/README
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE_NOINETD/vsftpd.conf
/usr/share/doc/vsftpd/EXAMPLE/PER_IP_CONFIG
/usr/share/doc/vsftpd/EXAMPLE/PER_IP_CONFIG/README
/usr/share/doc/vsftpd/EXAMPLE/PER_IP_CONFIG/hosts.allow
/usr/share/doc/vsftpd/EXAMPLE/README
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_HOSTS
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_HOSTS/README
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS/README
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS/logins.txt
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS/vsftpd.conf
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS/vsftpd.pam
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS_2
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS_2/README
/usr/share/doc/vsftpd/FAQ
/usr/share/doc/vsftpd/INSTALL
/usr/share/doc/vsftpd/LICENSE
/usr/share/doc/vsftpd/README
/usr/share/doc/vsftpd/README.security
/usr/share/doc/vsftpd/REWARD
/usr/share/doc/vsftpd/SECURITY
/usr/share/doc/vsftpd/SECURITY/DESIGN
/usr/share/doc/vsftpd/SECURITY/IMPLEMENTATION
/usr/share/doc/vsftpd/SECURITY/OVERVIEW
/usr/share/doc/vsftpd/SECURITY/TRUST
/usr/share/doc/vsftpd/SIZE
/usr/share/doc/vsftpd/SPEED
/usr/share/doc/vsftpd/TODO
/usr/share/doc/vsftpd/TUNING
/usr/share/doc/vsftpd/vsftpd.xinetd
/usr/share/man/man5/vsftpd.conf.5.gz
/usr/share/man/man8/vsftpd.8.gz
/var/ftp
/var/ftp/pub
[root@localhost /]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
[root@localhost /]# rpm -qf /etc/pam.d/vsftpd 
vsftpd-3.0.3-32.el8.x86_64

4.安全验证

RPM提供的验证功能可以随时追踪软件的状态,当软件被人篡改时,使用rpm -V命令就会提示该软件的哪些状态被修改,未篡改的软件使用该命令则无任何提示

[root@localhost /]# whereis vsftpd
vsftpd: /usr/sbin/vsftpd /etc/vsftpd /usr/share/man/man8/vsftpd.8.gz
[root@localhost /]# ll /usr/sbin/vsftpd 
-rwxr-xr-x. 1 root root 176952 Mar 17  2020 /usr/sbin/vsftpd

[root@localhost /]# rpm -V /usr/sbin/vsftpd 
package /usr/sbin/vsftpd is not installed
[root@localhost /]# rpm -V vsftpd         #这目前没有被篡改
[root@localhost /]# chown xiaohong. /usr/sbin/vsftpd 
[root@localhost /]# rpm -V vsftpd 
.....UG..    /usr/sbin/vsftpd

下面列出所有kennel出现的提示字符及含义

        a) 5          --MD5值已经改变

        b) s          --文件大小已经改变

        c) L          --链接文件源已经改变

        d) T          --文件最后修改时间已经改变

        e) D          --设备改变

        f) u         --用户发生改变

        g) G         --组发生改变

        h) M         --包括权限与类型在内的模式已经改变

        i) ?           --不可读的文件

二.使用YUM安装软件

        YUM是Yellow dog Update Modified的简写形式,YUM是改进版的RPM软件管理器,YUM可以很好的解决RPM所面临的软件包依赖问题,大量的软件依赖会让RPM成为恐怖存在,YUM可以从很多源中搜索软件以及它们的依赖包,并自动安装相应的依赖软件,使用YUM安装软件时至少需要一个YUM源,YUM源就是存放很多RPM软件的文件夹,有三种方式分别是HTTP、FTP或者本地文件夹的方式访问YUM源。

1.设置YUM源

默认的YUM源定义文件存在/etc/yum.repos.d/目录下,用户可以自定义任意可以使用的YUM源,但文件名的扩展名必须是repo,文件格式如下:

选项           功能描述

[]                 []中填写YUM源唯一的ID,可以为任意字符串

name (可写可不写)         指定YUM源名称,可以为任意字符串

baseurl            指定YUM源的URL地址(可以是HTTP://、FTP://或本地路径(file://))

mirrorlist          指定镜像站点目录

enabled           是否激活该YUM源(O代表禁用、1代表激活、默认为激活)

gpgcheck        安装软件时是否检测签名(0代表禁用、1代表激活)

gpgkey           检测签名的密钥文件

[RHEL8-BaseOS]
name=RHEL8-BaseOS
baseurl=file:///media/cdrom/BaseOS
gpgcheck=0 (0禁用,1激活)

[RHEL8-Appstream]
name=RHEL8-Appstream
baseurl=file:///media/cdrom/AppStream
gpgcheck=0

1)基于ISO镜像设置本地yum源

        通常而言,YUM客户端使用前提是必须联外网,YUM安装软件时,检查repo配置文件查找相应的YUM源仓库,企业IDC机房很多服务器为了安全起见,是禁止服务器上外网的,所以不能使用默认的官网YUM源仓库。

前提条件:

1、将.iso镜像加载至虚以CD/DVD或者放入服务器CD/DVD光驱中

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
total 8

-rw-r--r--. 1 root root 358 May 31 04:19 redhat.repo
#查看光驱
[root@localhost yum.repos.d]# ll /dev/sr0
brw-rw----. 1 root cdrom 11, 0 Jul 18 21:04 /dev/sr0


[root@localhost yum.repos.d]# ll /
total 28
-r------w-.   1 root root    0 Jul 15 03:23 111
dr-x--x-wx.   2 root root    6 Jul 15 03:24 222
lrwxrwxrwx.   1 root root    7 Apr 23  2020 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 May 31 04:09 boot
drwxr-xr-x.  20 root root 3120 Jul 18 21:04 dev
drwxr-xr-x.  81 root root 8192 Jul 18 21:04 etc
-rw-r--r--.   1 root root   26 Jul 15 02:35 file1
drwxr-xr-x.   7 root root  100 Jul 14 23:23 home
lrwxrwxrwx.   1 root root    7 Apr 23  2020 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Apr 23  2020 lib64 -> usr/lib64
drwxr-xr-x.   3 root root   19 Jul 14 08:28 media
drwxr-xr-x.   3 root root   18 May 31 03:18 mnt            #系统自动提供的
drwxr-xr-x.   2 root root    6 Apr 23  2020 opt
dr-xr-xr-x. 206 root root    0 Jul 18 21:04 proc
dr-xr-x---.   6 root root 4096 Jul 15 02:24 root
drwxr-xr-x.  25 root root  720 Jul 18 21:04 run
lrwxrwxrwx.   1 root root    8 Apr 23  2020 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 Apr 23  2020 srv
dr-xr-xr-x.  13 root root    0 Jul 18 21:04 sys
drwxrwxrwx.   2 root root   26 Jul 14 23:37 test
drwxrwxrwt.  23 root root 4096 Jul 18 21:15 tmp
drwxr-xr-x.  12 root root  144 May 31 03:17 usr
drwxr-xr-x.  20 root root  278 May 31 04:09 var
#/mnt/hgfs是空的,是系统自动提供的挂载点
[root@localhost yum.repos.d]# ls /mnt/
hgfs
[root@localhost yum.repos.d]# ls /mnt/hgfs/
#挂载光盘
[root@localhost yum.repos.d]# mount /dev/sr0 /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@localhost yum.repos.d]# ls /mnt/
AppStream  extra_files.json  media.repo
BaseOS     GPL               RPM-GPG-KEY-redhat-beta
EFI        images            RPM-GPG-KEY-redhat-release
EULA       isolinux          TRANS.TBL
[root@localhost yum.repos.d]# cd /mnt/
[root@localhost mnt]# ll
total 48
dr-xr-xr-x. 4 root root  2048 Oct  9  2020 AppStream
dr-xr-xr-x. 4 root root  2048 Oct  9  2020 BaseOS
dr-xr-xr-x. 3 root root  2048 Oct  9  2020 EFI
-r--r--r--. 1 root root  8266 Oct  9  2020 EULA
-r--r--r--. 1 root root  1455 Oct  9  2020 extra_files.json
-r--r--r--. 1 root root 18092 Oct  9  2020 GPL
dr-xr-xr-x. 3 root root  2048 Oct  9  2020 images
dr-xr-xr-x. 2 root root  2048 Oct  9  2020 isolinux
-r--r--r--. 1 root root   103 Oct  9  2020 media.repo
-r--r--r--. 1 root root  1669 Oct  9  2020 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root  5134 Oct  9  2020 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root  1796 Oct  9  2020 TRANS.TBL

构建本地YUM光盘源,其原理是通过查找光盘中的软件包,实现YUM安装,配置步骤:

[root@localhost ~]# mkdir -p /mnt
 //创建挂载路径
[root@localhost ~]# mount /dev/cdrom /mnt/
     or      mount /dev/sr0 /mnt  //挂载系统镜像到指定目录
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ll
total 48
dr-xr-xr-x. 4 root root  2048 Oct  9  2020 AppStream
dr-xr-xr-x. 4 root root  2048 Oct  9  2020 BaseOS
dr-xr-xr-x. 3 root root  2048 Oct  9  2020 EFI
-r--r--r--. 1 root root  8266 Oct  9  2020 EULA
-r--r--r--. 1 root root  1455 Oct  9  2020 extra_files.json
-r--r--r--. 1 root root 18092 Oct  9  2020 GPL
dr-xr-xr-x. 3 root root  2048 Oct  9  2020 images
dr-xr-xr-x. 2 root root  2048 Oct  9  2020 isolinux
-r--r--r--. 1 root root   103 Oct  9  2020 media.repo
-r--r--r--. 1 root root  1669 Oct  9  2020 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root  5134 Oct  9  2020 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root  1796 Oct  9  2020 TRANS.TBL
[root@localhost mnt]# cd /etc/yum.repos.d/            #配置YUM源
[root@localhost yum.repos.d]# vi name.repo
        #(名字自定义,但结尾的文件名必须是.repo)
'''
[RHEL8-BaseOS]
name=RHEL8-BaseOS
baseurl=file:///mnt/BaseOS        #这个怎么查呢?在后面,保存退出之后,到路径之下
gpgcheck=0             #(0禁用,1激活)

[RHEL8-AppStream]
name=RHEL8-Appstream
baseurl=file:///mnt/AppStream        #方法同上
gpgcheck=0
'''

#怎么查?这么查:
[root@localhost yum.repos.d]# cd /mnt/BaseOS/

[root@localhost BaseOS]# pwd
/mnt/BaseOS
[root@localhost yum.repos.d]# cat name.repo 
[root@localhost yum.repos.d]# yum clean all         //清除缓存

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.

0 files removed
[root@localhost yum.repos.d]# 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.

RHEL8-BaseOS               69 MB/s | 2.3 MB     00:00    
RHEL8-Appstream            79 MB/s | 6.3 MB     00:00    
Last metadata expiration check: 0:00:01 ago on Mon 18 Jul 2022 10:13:35 PM EDT.
Metadata cache created.
[root@localhost yum.repos.d]# yum 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.

repo id                      repo name
RHEL8-Appstream              RHEL8-Appstream
RHEL8-BaseOS                 RHEL8-BaseOS

yum是def的一个软连接,所以Yum和def都可以使用

def -y install   软件包名
def -y remove    软件包名
def -y update    软件包名

2)基于网络设置yum源

[root@localhost ~]# cd /etc/yum.repos.d/

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo 

[root@localhost yum.repos.d]# mv name.repo name.repo.bak
[root@localhost yum.repos.d]# yum 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.

repo id      repo name
AppStream    CentOS-8 - AppStream - mirrors.aliyun.com
base         CentOS-8 - Base - mirrors.aliyun.com
extras       CentOS-8 - Extras - mirrors.aliyun.com
[root@localhost yum.repos.d]# yum insatll -y vim
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.

No such command: insatll. Please use /usr/bin/yum --help
It could be a YUM plugin command, try: "yum install 'dnf-command(insatll)'"
[root@localhost yum.repos.d]# yum install -y vim
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.

CentOS-8 - Base - mirrors 975 kB/s | 4.6 MB     00:04    
CentOS-8 - Extras - mirro  26 kB/s |  10 kB     00:00    
CentOS-8 - AppStream - mi 673 kB/s | 8.4 MB     00:12    
Dependencies resolved.
==========================================================
 Package        Arch   Version            Repo       Size
==========================================================
Installing:
 vim-enhanced   x86_64 2:8.0.1763-16.el8  AppStream 1.4 M
Installing dependencies:
 gpm-libs       x86_64 1.20.7-17.el8      AppStream  39 k
 vim-common     x86_64 2:8.0.1763-16.el8  AppStream 6.3 M
 vim-filesystem noarch 2:8.0.1763-16.el8  AppStream  49 k

Transaction Summary
==========================================================
Install  4 Packages
[root@localhost yum.repos.d]# ll
total 12
-rw-r--r--. 1 root root 2600 Feb 10 21:14 CentOS-Base.repo
-rw-r--r--. 1 root root  156 Jul 18 22:46 name.repo.bak
-rw-r--r--. 1 root root  358 May 31 04:19 redhat.repo
[root@localhost yum.repos.d]# mv name.repo.bak name.repo

2.YUM命令

yum︰交互式,基于RPM的包管理工具

语法:yum [选项] [指令] [软件包]

选项:

-y 执行非交互安装,假定安装过程中出现的所有提示回答为yes

指令:

install                 使用yum源安装软件包

update               使用yum源升级软件包

makecache        建立yum缓存信息

check-update         检查yum源中所有可用的升级

remove              卸载软件包

list                     有可用的软件包

info                   查看软件包信息

clean all           清空所有的缓存信息

groupinstall         使用yum源安装组包

grouplist         列出系统中已经安装的以及yum源中所有可用的组包

groupremove         卸载组包

search         根据关键词杳找软件

localinstall         通过本地rpm文件安装软件

history         查看历史记录

provides         查看命令的源包名

[root@localhost /]# ifconfig
-bash: ifconfig: command not found

[root@localhost /]# yum search ifconfig
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: 0:01:57 ago on Mon 18 Jul 2022 10:46:21 PM EDT.
No matches found.
[root@localhost /]# yum provides ifconfig
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: 0:00:42 ago on Mon 18 Jul 2022 10:46:21 PM EDT.
net-tools-2.0-0.52.20160912git.el8.x86_64 : Basic
     ...: networking tools
Repo        : RHEL8-BaseOS
Matched from:
Filename    : /usr/sbin/ifconfig

[root@localhost /]# yum insatll net-tools
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.

No such command: insatll. Please use /usr/bin/yum --help
It could be a YUM plugin command, try: "yum install 'dnf-command(insatll)'"
[root@localhost /]# yum install net-tools
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: 0:01:10 ago on Mon 18 Jul 2022 10:46:21 PM EDT.
Dependencies resolved.
==========================================================
 Package
       Arch   Version                  Repository    Size
==========================================================
Installing:
 net-tools
       x86_64 2.0-0.52.20160912git.el8 RHEL8-BaseOS 322 k

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

Total size: 322 k
Installed size: 942 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                  1/1 
  Installing       : net-tools-2.0-0.52.20160912git   1/1 
  Running scriptlet: net-tools-2.0-0.52.20160912git   1/1 
  Verifying        : net-tools-2.0-0.52.20160912git   1/1 
Installed products updated.

Installed:
  net-tools-2.0-0.52.20160912git.el8.x86_64               

Complete!
[root@localhost /]# yum provides rz
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: 0:03:18 ago on Mon 18 Jul 2022 10:46:21 PM EDT.
lrzsz-0.12.20-43.el8.x86_64 : The lrz and lsz modem
                            : communications programs
Repo        : RHEL8-BaseOS
Matched from:
Filename    : /usr/bin/rz

[root@localhost /]# rz            #调用本地文件
-bash: rz: command not found
[root@localhost /]# yum install -y lrzsz
[root@localhost /]# sz            #上传虚拟机文件

三.源码安装软件

        软件的源代码是软件的原始数据,任何人都可以通过源代码查看该软件的设计架构与实现方法,但软件源代码不可以在计算机中直接运行安装,我们需要通过配置软件功能,然后将软件源代码通过编译转换为计算机可以识别的机器语言,最后才可以执行安装操作,不同于RPM或其他二进制软件包的安装方式,通过源码编译安装的软件,使得安装者可以根据自己的需要定制自己的软件,这是实际工作中所需要的关键因素。

通过源码安装软件具体步骤如下:

        1)我们所获得的软件源码一般都会被打包并压缩,常见的格式有.tar.gz或者.tar.b22格式,此时,我们需要使用前面所学习的tar命令将压缩包解压,具体参数自己回顾之前所学习的压缩及解压相关内容

        2)运行configure脚本,通过特定的选项修改软件设置与功能,该脚本一般可以用来指定安装路径,开启关闭软件的特定功能等,脚本选项可以通过阅读安装说明或者.Jconfigure --help查看软件支持的功能选项,而有些软件没有提供configure脚本,则可以直接执行mack编译步骤。

        3)运行make命令将软件源代码编译为计算机可以直拉

几器语言,由于需要相应的编译软件才可以将源代码编译为机器语言,所以在执行configure脚本时就会检查对应的开发工具是否

常用的开发工具有: gcc、python、perl、make、automake等,

如果没有安装则提示error错误。

        4)通过make install根据配置阶段指定的路径和功能将软件以特定的方式安装到指定位置

实例:从网络上下载Apache软件作为演示案例,Apache是当今最流行的Web服务器软件,由于Apache需要依赖arp库等软件,所以我们连同相关依赖包一起安装。

#安装需要的编辑环境
[root@localhost ~]# yum -y install gcc pcre pcre-devel libtool cmake
#需要下载三个源码包
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.bz2
[root@localhost ~]# wget https://archive.apache.org/dist/apr/apr-1.5.0.tar.gz
[root@localhost ~]# wget https://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
[root@localhost ~]# ll
total 12312
drw-------. 2 root root      31 Jul 14 22:00  111file
drwxr-xr-x. 2 root wyy        6 Jul 14 07:23  123
-rw-------. 1 root root    1563 May 31 03:22  anaconda-ks.cfg
-rw-r--r--. 1 root root 1016391 Nov 16  2013  apr-1.5.0.tar.gz
-rw-r--r--. 1 root root  874044 Sep 20  2014  apr-util-1.5.4.tar.gz
-rw-r--r--. 1 root root       0 Jul 14 21:59  dir1
-rw-r--r--. 1 root root       0 Jul 14 21:59  file1
-rw-r--r--. 1 root root       0 Jun 21 02:16  file2
-rw-r--r--. 2 root root      10 Jun 21 02:02  filebak
-rw-r--r--. 2 root root      10 Jun 21 02:02  filebak1
-rw-r--r--. 1 root root 7434530 Jun  8 04:42  httpd-2.4.54.tar.bz2
drwxrwxrwx. 2 root root       6 Jul 14 23:06  test
-rw-r--r--. 1 root root       0 Jul 15 02:24  test1
-rw-r--r--. 1 root root  447041 Jul 12 01:41 'WPSͼƬƴͼ(2).png'
-rw-r--r--. 1 root root 2809450 Jul 12 01:21  wyy.tar.bz2
#解压http源码包
[root@localhost ~]# tar -xzvf apr-1.5.0.tar.gz 
[root@localhost ~]# tar -xzvf apr-util-1.5.4.tar.gz 
[root@localhost ~]# tar -xjvf httpd-2.4.54.tar.bz2         #如果报错了,去安装bzip2包
[root@localhost ~]# ll
total 12324
drw-------.  2 root  root       31 Jul 14 22:00  111file
drwxr-xr-x.  2 root  wyy         6 Jul 14 07:23  123
-rw-------.  1 root  root     1563 May 31 03:22  anaconda-ks.cfg
drwxr-xr-x. 27 rhcsa rhcsa    4096 Nov 13  2013  apr-1.5.0
-rw-r--r--.  1 root  root  1016391 Nov 16  2013  apr-1.5.0.tar.gz
drwxr-xr-x. 19 rhcsa rhcsa    4096 Sep 16  2014  apr-util-1.5.4
-rw-r--r--.  1 root  root   874044 Sep 20  2014  apr-util-1.5.4.tar.gz
-rw-r--r--.  1 root  root        0 Jul 14 21:59  dir1
-rw-r--r--.  1 root  root        0 Jul 14 21:59  file1
-rw-r--r--.  1 root  root        0 Jun 21 02:16  file2
-rw-r--r--.  2 root  root       10 Jun 21 02:02  filebak
-rw-r--r--.  2 root  root       10 Jun 21 02:02  filebak1
drwxr-xr-x. 12   504 games    4096 Jun  6 10:22  httpd-2.4.54
-rw-r--r--.  1 root  root  7434530 Jun  8 04:42  httpd-2.4.54.tar.bz2
drwxrwxrwx.  2 root  root        6 Jul 14 23:06  test
-rw-r--r--.  1 root  root        0 Jul 15 02:24  test1
-rw-r--r--.  1 root  root   447041 Jul 12 01:41 'WPSͼƬƴͼ(2).png'
-rw-r--r--.  1 root  root  2809450 Jul 12 01:21  wyy.tar.bz2
#编译文件
[root@localhost ~]# cd apr-1.5.0
[root@localhost apr-1.5.0]# ll
total 1388
-rw-r--r--. 1 rhcsa rhcsa   6903 Jun 20  2008 apr-config.in
-rw-r--r--. 1 rhcsa rhcsa  53992 Nov  6  2013 apr.dep
-rw-r--r--. 1 rhcsa rhcsa  22900 Nov  5  2013 apr.dsp
-rw-r--r--. 1 rhcsa rhcsa   1777 Oct 18  2007 apr.dsw
-rw-r--r--. 1 rhcsa rhcsa  53430 Nov  6  2013 apr.mak
-rw-r--r--. 1 rhcsa rhcsa    313 Apr  6  2005 apr.pc.in
-rw-r--r--. 1 rhcsa rhcsa   2553 Nov 13  2013 apr.spec
drwxr-xr-x. 6 rhcsa rhcsa     59 Nov 13  2013 atomic
drwxr-xr-x. 4 rhcsa rhcsa   4096 Nov 13  2013 build
-rw-r--r--. 1 rhcsa rhcsa    634 Oct  9  2013 build.conf
-rwxr-xr-x. 1 rhcsa rhcsa   4402 May 20  2011 buildconf
-rw-r--r--. 1 rhcsa rhcsa  66962 Nov 13  2013 build-outputs.mk
-rw-r--r--. 1 rhcsa rhcsa   3862 Nov 13  2013 CHANGES
-rw-r--r--. 1 rhcsa rhcsa  13587 Oct 12  2013 CMakeLists.txt
-rw-r--r--. 1 rhcsa rhcsa   7340 Nov 24  2004 config.layout
-rwxr-xr-x. 1 rhcsa rhcsa 829676 Nov 13  2013 configure            #开发者写好的脚本文件
-rw-r--r--. 1 rhcsa rhcsa  81202 Nov 13  2013 configure.in
drwxr-xr-x. 2 rhcsa rhcsa    177 Nov 13  2013 docs
drwxr-xr-x. 9 rhcsa rhcsa     93 Nov 13  2013 dso
-rw-r--r--. 1 rhcsa rhcsa    488 Nov 24  2004 emacs-mode
drwxr-xr-x. 2 rhcsa rhcsa     26 Nov 13  2013 encoding
drwxr-xr-x. 6 rhcsa rhcsa     57 Nov 13  2013 file_io
drwxr-xr-x. 2 rhcsa rhcsa     27 Nov 13  2013 helpers
drwxr-xr-x. 4 rhcsa rhcsa   4096 Nov 13  2013 include
-rw-r--r--. 1 rhcsa rhcsa  54119 Nov  6  2013 libapr.dep
-rw-r--r--. 1 rhcsa rhcsa  28005 Nov  5  2013 libapr.dsp
-rw-r--r--. 1 rhcsa rhcsa  60316 Nov  6  2013 libapr.mak
-rw-r--r--. 1 rhcsa rhcsa   2027 May 26  2013 libapr.rc
-rw-r--r--. 1 rhcsa rhcsa  17979 Oct 21  2013 LICENSE
drwxr-xr-x. 7 rhcsa rhcsa     69 Nov 13  2013 locks
-rw-r--r--. 1 rhcsa rhcsa   4699 Oct 29  2013 Makefile.in
-rw-r--r--. 1 rhcsa rhcsa   4873 Oct  3  2013 Makefile.win
drwxr-xr-x. 3 rhcsa rhcsa     18 Nov 13  2013 memory
drwxr-xr-x. 5 rhcsa rhcsa     46 Nov 13  2013 misc
drwxr-xr-x. 4 rhcsa rhcsa     31 Nov 13  2013 mmap
drwxr-xr-x. 6 rhcsa rhcsa     54 Nov 13  2013 network_io
-rw-r--r--. 1 rhcsa rhcsa    522 Jan  3  2011 NOTICE
-rw-r--r--. 1 rhcsa rhcsa   8754 Mar 18  2011 NWGNUmakefile
drwxr-xr-x. 2 rhcsa rhcsa     27 Nov 13  2013 passwd
drwxr-xr-x. 4 rhcsa rhcsa     29 Nov 13  2013 poll
drwxr-xr-x. 3 rhcsa rhcsa     18 Nov 13  2013 random
-rw-r--r--. 1 rhcsa rhcsa   5633 Mar  1  2010 README
-rw-r--r--. 1 rhcsa rhcsa   4377 Oct 10  2013 README.cmake
drwxr-xr-x. 6 rhcsa rhcsa     54 Nov 13  2013 shmem
drwxr-xr-x. 2 rhcsa rhcsa    134 Nov 13  2013 strings
drwxr-xr-x. 3 rhcsa rhcsa     18 Nov 13  2013 support
drwxr-xr-x. 2 rhcsa rhcsa     66 Nov 13  2013 tables
drwxr-xr-x. 4 rhcsa rhcsa   4096 Nov 13  2013 test
drwxr-xr-x. 7 rhcsa rhcsa     69 Nov 13  2013 threadproc
drwxr-xr-x. 4 rhcsa rhcsa     31 Nov 13  2013 time
drwxr-xr-x. 2 rhcsa rhcsa     29 Nov 13  2013 tools
drwxr-xr-x. 5 rhcsa rhcsa     46 Nov 13  2013 user

[root@localhost apr-1.5.0]# ./configure && make && make install
         #&&表示连续执行命令,按顺序执行
[root@localhost apr-1.5.0]# cd ../apr-util-1.5.4
[root@localhost apr-util-1.5.4]# ./configure --with-apr=/usr/local/apr/        #指定apr软件包位置

[root@localhost apr-util-1.5.4]# make && make install
[root@localhost apr-util-1.5.4]# cd ../httpd-2.4.54
[root@localhost httpd-2.4.54]# ./configure 
[root@localhost httpd-2.4.54]# make && make install
[root@localhost httpd-2.4.54]# find / -name "httpd*"
[root@localhost ~]# /usr/local/apache2/bin/httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

[root@localhost ~]# ps uax | grep httpd            #可以看到httpd服务启动起来了
root       25869  0.0  0.3  86908  4400 ?        Ss   01:57   0:00 /usr/local/apache2/bin/httpd
daemon     25870  0.1  0.9 862580 10988 ?        Sl   01:57   0:00 /usr/local/apache2/bin/httpd
daemon     25871  0.0  0.6 862580  6912 ?        Sl   01:57   0:00 /usr/local/apache2/bin/httpd
daemon     25872  0.1  0.9 862580 10992 ?        Sl   01:57   0:00 /usr/local/apache2/bin/httpd
root       25959  0.0  0.0  12112  1052 pts/0    R+   01:58   0:00 grep --color=auto httpd
[root@localhost ~]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1026/sshd           
tcp6       0      0 :::80                   :::*                    LISTEN      25869/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      1026/sshd      
#访问需要停止防火墙
[root@localhost httpd-2.4.54]# systemctl stop firewalld 
[root@localhost httpd-2.4.54]# setenforce 0        #设置关闭状态
[root@localhost ~]# getenforce            #查看状态
Permissive

通过以上的步骤安装完成之后打开浏览器访问http://IP就会出现http的测试页面

[root@localhost ~]# cd /usr/local/apache2
[root@localhost apache2]# cd htdocs/
[root@localhost htdocs]# ll
total 4
-rw-r--r--. 1 504 games 45 Jun 11  2007 index.html
[root@localhost htdocs]# cat index.html 
<html><body><h1>It works!</h1></body></html>
[root@localhost htdocs]# vim index.html 
[root@localhost htdocs]# cat index.html 
<html><body><h1>It works!asdgsssfdh</h1></body></html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值