安装及管理程序

安装及管理程序

1.Linux应用程序基础

应用程序与系统命令的关系

角色 系统命令 应用程序
文件位置 一般在/bin和/sbin目录中,或为内部命令 通常在/usr/bin和usr/sbin目录中
主要用途 完成对系统管理的基本工作,例如IP配置工具 完成相对独立的其他辅助任务,例如网页浏览器
适用环境 一般只在字符操作界面运行 根据实际需要,有些程序可在图形界面中运行
运行格式 一般包括命令字、命令选项和命令参数 通常没有固定的执行格式

典型应用程序的目录结构

普通执行程序文件:/usr/bing
服务器执行程序文件和管理程序文件:/usr/sbin
应用程序配置文件:/etc
日志文件:/var/log
应用程序参考文档文件:/usr/share/doc
应用程序手册页文件:/usr/local/share/man

常见的软件包封装类型

文件类型 保存目录
RPM软件包 扩展名为“.rpm”
d 扩展名为“.deb”
源代码软件包 一般“.tar.gz”、“tar.bz2”等格式的压缩包包含程序的原始代码
绿色免安装的软件包 软件包的扩展名不一,以TarBall格式的居多在压缩包内提供已编译好的执行程序文件解开压缩包后的文件即可直接使用

2.RPM包管理工具

Red-Hat Package Manager

由Red-Hat公司提出,被众多linux发行版所采用
建立统一的数据库文件
详细记录软件包安装、卸载等变化信息
自动分析软件包依赖关系

RPM软件包

软件素材参考:http://www.rpm.org
一般命令格式:bash-4.1.2-15.el6_4.x86_64.rpm
:bash- 4.1.2- 15.el6_4. x86_64 .rpm
软件名称 版本号 发布次数 cpu架构 扩展名

rpm命令的格式

rpm命令能够实现几乎所有对RPM软件包的管理功能
执行“man rpm”命令可以获得关于rpm命令的详细帮助信息

rpm命令功能

查询、验证rpm软件包的相关信息
安装、升级、卸载rpm软件包
维护rpm数据库信息等综合管理操作

查询rpm软件包信息

查询已安装的rpm软件包信息
格式:rpm -q[子选项] [软件名]
[root@localhost ~]# rpm -q httpd #已安装则下面会显示信息
httpd-2.4.6-67.el7.centos.x86_64
[root@localhost ~]# rpm -q ssh
未安装软件包 ssh

常用选项:
-qa:(查询所有已安装的软件信息)
-qi:(显示详细信息)
-ql:(显示所有文件列表)
-qf:(查询属主)
-qc:(配置文件)
-qd:(帮助文档)
```bash
[root@localhost ~]# rpm -qi httpd   #显示详细信息
Name        : httpd
Version     : 2.4.6
Release     : 67.el7.centos
Architecture: x86_64
Install Date: 2022年02月19日 星期六 15时59分18秒
Group       : System Environment/Daemons
Size        : 9823661
License     : ASL 2.0
Signature   : RSA/SHA256, 2017年08月11日 星期五 00时40分32秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : httpd-2.4.6-67.el7.centos.src.rpm
Build Date  : 2017年08月04日 星期五 11时21分07秒
Build Host  : c1bm.rdu2.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.

查询未安装的rpm软件包文件中的信息
rmp -qp[子选项] RPM包文件
常用选项:
-qpi:(显示详细信息)
-qpl:(显示所有文件列表)
-qpc:(配置文件)
-qpd:(帮助文档)

3.安装、卸载RPM软件

安装rpm软件

rpm [选项] RPM包文件
常用选项:
-i :安装一个新的rpm软件包
-U:升级某个软件包,若未安装过则进行安装
-F:升级某个软件包,若未安装过则直接结束 已安装则升级

[root@localhost mnt]# cd /mnt/Packages
#切换到/mnt/Packages目录下
[root@localhost Packages]# rpm -ivh httpd
错误:打开 httpd 失败: 没有那个文件或目录
[root@localhost Packages]# rpm -ivh httpd-2.4.6-67.el7.centos.x86_64.rpm
#安装httpd软件包(这里要注意httpd要写全称和rpm后缀名否则安装不了)
准备中...                          ################################# [100%]
正在升级/安装...
   1:httpd-2.4.6-67.el7.centos        ################################# [100%]

卸载指定的rpm软件

rpm -e 软件名

[root@localhost ~]# rpm -e httpd    #删除软件
[root@localhost ~]# rpm -q httpd    #这里可以看出以删除
未安装软件包 httpd
``
### 辅助选项
--force(强制安装某个软件包)
--nodeps(在安装或升级、卸载一个软件包是,不检查与其他包的依赖关系)
-h(在安装或升级过程中已#号显示读条)
-v(显示安装过程的详细信息)
## 4.yum安装
yum是一个基于rpm包构造的软件更新机制,能够自动解决软件包之间的依赖关系。

mount:挂载,你的包在你的光驱里并没有放在系统中,光盘的包只有先挂载在光盘到我的系统才能建立连接

什么是挂载:将硬件,比如光盘、光驱等,挂载在目录上使用,变成文件

unmount:解挂载,跟着硬件设备走,不在挂载的文件下

注意:写yum仓库的位置必须要在/etc/yum.repos.d这个位置写
### 配置本地源仓库
```bash
[root@localhost ~]# mount /dev/sr0 /mnt              #将硬件设备挂载到mnt目录下
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# df -h             #查看挂载信息
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda2        10G  4.8G  3.6G   58% /
devtmpfs        1.2G     0  1.2G    0% /dev
tmpfs           1.2G     0  1.2G    0% /dev/shm
tmpfs           1.2G  9.1M  1.2G    1% /run
tmpfs           1.2G     0  1.2G    0% /sys/fs/cgroup
/dev/sda1      1014M  180M  835M   18% /boot
tmpfs           230M  4.0K  230M    1% /run/user/42
tmpfs           230M   24K  230M    1% /run/user/0
/dev/sr0        4.3G  4.3G     0  100% /mnt           #这里可看到/mnt全部被占用
[root@localhost ~]# cd /etc/yum.repos.d          #切换到/yum.repos.d目录下
[root@localhost yum.repos.d
#进入yum目录移走系统原有yum(下面Base为默认yum,一个目录下不可能有两个默认源所以得移走或删除)
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@localhost yum.repos.d]#mkdir bak         #新建一个目录
[root@localhost yum.repos.d]#mv *.repo bak       #移动以.repo的文件到bak目录下
[root@localhost yum.repos.d]#l             s#这里可以看到已经移走了
bak
[root@localhost yum.repos.d]#vim 000.repo          #新建本地yum仓库
[000]#             仓库的名字(这里可以随便定义一个名字)
name=000         #描述(随便写自己记得就行)
baseurl=file:///mnt       #指定URL访问路径    
gpgcheck=0         #不检查密钥(这里你要写=1那么就是要检查密钥)
enabled=1          #这个仓库自动开启(你要写=0的话就是不开启)
[root@localhost yum.repos.d]#yum clean all && yum makecache      #清除缓存
已加载插件:fastestmirror, langpacks
正在清理软件源: 000
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
已加载插件:fastestmirror, langpacks
000                                                       | 3.6 kB  00:00:00     
(1/4): 000/group_gz                                       | 156 kB  00:00:00     
(2/4): 000/primary_db                                     | 3.1 MB  00:00:00     
(3/4): 000/filelists_db                                   | 3.1 MB  00:00:00     
(4/4): 000/other_db                                       | 1.2 MB  00:00:00     
Determining fastest mirrors
元数据缓存已建立
[root@localhost yum.repos.d]#yum install httpd -y       #安装httpd自动确认所有询问
已加载插件:fastestmirror, langpacks

5.源代码编译安装

使用源代码编译安装软件的优点

获得最新的软件版本,及时修复bug
根据用户需要,灵活定制软件功能

应用场景举例

安装较新版本的应用程序时
当前安装的程序无法满足需要时
需要为应用程序添加新功能时

编译安装过程


下载源代码安装包地址http://httpd.apache.org/

[root@localhost ~]# rpm -qi httpd   #可以在这条命令下查看官网地址
Name        : httpd
Version     : 2.4.6
Release     : 67.el7.centos
Architecture: x86_64
Install Date: 2022年02月19日 星期六 15时59分18秒
Group       : System Environment/Daemons
Size        : 9823661
License     : ASL 2.0
Signature   : RSA/SHA256, 2017年08月11日 星期五 00时40分32秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : httpd-2.4.6-67.el7.centos.src.rpm
Build Date  : 2017年08月04日 星期五 11时21分07秒
Build Host  : c1bm.rdu2.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.
[root@localhost ~]# wget https://dlcdn.apache.org//httpd/httpd-2.4.52.tar.bz2#下载软件包
--2022-02-20 15:22:00--  https://dlcdn.apache.org//httpd/httpd-2.4.52.tar.bz2
正在解析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... 已连接。
错误: 无法验证 dlcdn.apache.org 的由 “/C=US/O=Let's Encrypt/CN=R3” 颁发的证书:
  颁发的证书已经过期。
要以不安全的方式连接至 dlcdn.apache.org,使用“--no-check-certificate”。#可能是证书的原因要使用这条命令
[root@localhost ~]#  wget https://dlcdn.apache.org//httpd/httpd-2.4.52.tar.bz2 --no-check-certificate
--2022-02-20 15:23:44--  https://dlcdn.apache.org//httpd/httpd-2.4.52.tar.bz2
正在解析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... 已连接。
警告: 无法验证 dlcdn.apache.org 的由 “/C=US/O=Let's Encrypt/CN=R3” 颁发的证书:
  颁发的证书已经过期。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:7439184 (7.1M) [application/x-bzip2]
正在保存至: “httpd-2.4.52.tar.bz2”
21% [=======>                                ] 1,564,672   6.15KB/s 剩余 9m 56s 
2022-02-20 15:37:28 (8.82 KB/s) - 已保存 “httpd-2.4.52.tar.bz2” [7439184/7439184])
``
```bash
[root@localhost ~]#tar xvf httpd-2.4.52.tar.bz2 -C /data    #将文件解压到/data目录下
[root@localhost ~]# ls /data
httpd-2.4.52  log.txt.bak.bak  passwd1  t.gzip.tar
[root@localhost ~]# cd /data/httpd-2.4.52/切换到这个文件下
[root@localhost httpd-2.4.52]# ls#这里可以看出下面有一个执行脚本configure
ABOUT_APACHE     CHANGES          httpd.mak       Makefile.in       ROADMAP
acinclude.m4     changes-entries  httpd.spec      Makefile.win      server
Apache-apr2.dsw  CMakeLists.txt   include         modules           srclib
Apache.dsw       config.layout    INSTALL         NOTICE            support
apache_probes.d  configure        InstallBin.dsp  NWGNUmakefile     test
ap.d             configure.in     LAYOUT          os                VERSIONING
build            docs             libhttpd.dep    README
BuildAll.dsp     emacs-style      libhttpd.dsp    README.CHANGES
BuildBin.dsp     httpd.dep        libhttpd.mak    README.cmake
buildconf        httpd.dsp        LICENSE         README.platforms
[root@localhost httpd-2.4.52]# ./configure --prefix=/usr/local/apache      #安装配置文件
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.
#报错显示arp,所以要先安装arp
[root@localhost httpd-2.4.52]# yum install apr* -y   #安装arp
[root@localhost httpd-2.4.52]#  ./configure --prefix=/usr/local/apache#再次安装配置文件
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to "  -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
configure: 
configure: Configuring Apache Portable Runtime Utility library...
configure: 
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... -std=gnu11
checking how to run the C preprocessor... gcc -E
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
#报错显示pcre-config,所以要先安装pcre-config
[root@localhost httpd-2.4.52]# yum install pcre* -y#安装以pcre开头所有文件
[root@localhost httpd-2.4.52]# ./configure --prefix=/usr/local/apache#再次安装则安装成功
    Server Version: 2.4.52
    Install prefix: /usr/local/apache
    C compiler:     gcc -std=gnu11
    CFLAGS:           -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
[root@localhost httpd-2.4.52]#make#编译
[root@localhost httpd-2.4.52]#make install#复制二进制文件到系统,配置应用环境
[root@localhost bin]# cd /usr/local/apache/
[root@localhost apache]# ls
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
[root@localhost apache]# cd bin/
[root@localhost bin]# ls
ab         checkgid   envvars-std   htdbm     httpd       rotatelogs
apachectl#这是需要执行的文件  dbmmanage  fcgistarter   htdigest  httxt2dbm
apxs       envvars    htcacheclean  htpasswd  logresolve
[root@localhost bin]# pwd#显示路径
/usr/local/apache/bin
[root@localhost bin]# /usr/local/apache/bin/apachectl #通过绝对路径来执行
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 bin]# ss -ntap |grep httpd
LISTEN     0      128         :::80                      :::*                   users:(("httpd",pid=71950,fd=4),("httpd",pid=71949,fd=4),("httpd",pid=71948,fd=4),("httpd",pid=71947,fd=4))
[root@localhost bin]# systemctl stop firewalld#关闭防火墙
[root@localhost bin]# setenforce 0#关闭

此时在浏览器中输入自己虚拟机的IP地址即可查看httpd服务的页面

总结

1.典型应用程序目录结构
2.常见的软件包封装类型
3.使用rpm命令查询RPM软件信息的常用选项
4.使用rpm命令安装、升级、卸载RPM软件包的常用选项
5.从源代码包安装应用程序的基本过程包括解包、配置、编译、安装这四个步骤。

posted @ 2022-02-19 20:19  GENGBO  阅读(246)  评论(0编辑  收藏  举报