首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Linux安装及管理程序详述

Linux安装及管理程序详述

作者头像
用户8704835
修改于 2021-06-07 14:27:42
修改于 2021-06-07 14:27:42
1.1K0
举报
文章被收录于专栏:linux百科小宇宙linux百科小宇宙

一、RPM包管理工具

RPM Pachage Manager由Red Hat公司提出,被众多Linux发行版所采用。建立统一的数据库文件,详细记录软件包安装、卸载等变化信息,能够自动分析软件包依赖关系。RPM软件包一般命名格式如下:

1、查询已安装的RPM软件信息

查询已安装的RPM软件包语法格式如下:

应用举例:

[root@CentOS01 ~]# rpm -qa

Python2-pyasn1-modules-0.1.9-7.el7.noarch

mesa-libEGL-17.0.1-6.20170307.el7.x86_64

xcb-util-0.4.0-2.el7.x86_64

python-pyblock-0.53-6.el7.x86_64

sysstat-10.1.5-12.el7.x86_64

sos-3.4-6.el7.centos.noarch

xorg-x11-server-Xorg-1.19.3-11.el7.x86_64

libiscsi-1.9.0-7.el7.x86_64

sssd-ldap-1.15.2-50.el7.x86_64

postfix-2.10.1-6.el7.x86_64

…………

[root@centos01 ~]# rpm -q bash

bash-4.2.46-28.el7.x86_64

[root@centos01 ~]# rpm -qi bash

Name : bash

Version : 4.2.46

Release : 28.el7

Architecture: x86_64

Install Date: 2019年10月23日 星期三 22时29分35秒

Group : System Environment/Shells

Size : 3663637

License : GPLv3+

Signature : RSA/SHA256, 2017年08月10日 星期四 23时03分40秒, Key ID 24c6a8a7f4a80eb5

Source RPM : bash-4.2.46-28.el7.src.rpm

Build Date : 2017年08月03日 星期四 05时13分21秒

Build Host : c1bm.rdu2.centos.org

Relocations : (not relocatable)

Packager : CentOS BuildSystem

Vendor : CentOS

URL : http://www.gnu.org/software/bash

Summary : The GNU Bourne Again shell

Description :

The GNU Bourne Again shell (Bash) is a shell or command language

interpreter that is compatible with the Bourne shell (sh). Bash

incorporates useful features from the Korn shell (ksh) and the C shell

(csh). Most sh scripts can be run by bash without modification.

[root@centos01 ~]# rpm -qa | grep bash

bash-4.2.46-28.el7.x86_64

bash-completion-2.1-6.el7.noarch

[root@centos01 ~]# rpm -ql openssh

/etc/ssh

/etc/ssh/moduli

/usr/bin/ssh-keygen

/usr/libexec/openssh

/usr/libexec/openssh/ctr-cavstest

/usr/libexec/openssh/ssh-keysign

/usr/share/doc/openssh-7.4p1

/usr/share/doc/openssh-7.4p1/CREDITS

…………

2、查询文件或目录属于哪个RPM软件

语法格式如下:

应用举例:

[root@centos01 ~]# rpm -qf /usr/bin/vim

vim-enhanced-7.4.160-2.el7.x86_64

[root@centos01 ~]# rpm -qf /usr/libexec/openssh/

openssh-7.4p1-11.el7.x86_64

3、查询未安装的RPM包文件

查询未安装的RPM软件包语法格式如下:

应用举例:

[root@centos01 ~]# rpm -qpi /mnt/Packages/httpd-2.4.6

-67.el7.centos.x86_64.rpm

Name : httpd

Version : 2.4.6

Release : 67.el7.centos

Architecture: x86_64

Install Date: (not installed)

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

Vendor : CentOS

URL : http://httpd.apache.org/

Summary : Apache HTTP Serve

Description :

The Apache HTTP Server is a powerful, efficient, and extensible

web server.

[root@centos01 ~]# rpm -qpl /mnt/Packages/httpd-2.4.6

-67.el7.centos.x86_64.rpm

/etc/httpd

/etc/httpd/conf

/etc/httpd/conf.d

/etc/httpd/conf.d/README

/etc/httpd/conf.d/autoindex.conf

/etc/httpd/conf.d/userdir.conf

/etc/httpd/conf.d/welcome.conf

/etc/httpd/conf.modules.d

/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-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/httpd/logs

/etc/httpd/modules

/etc/httpd/run

…………

[root@centos01 ~]# rpm -qpc /mnt/Packages/httpd-2.4.6

-67.el7.centos.x86_64.rpm

/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-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

/etc/sysconfig/httpd

二、安装、升级和卸载RPM软件

安装、升级和卸载RPM软件的语法格式及常用选项如下:

1、安装RPM软件

[root@centos01 ~]# rpm -ivh /mnt/Packages/ntsysv-1.7.4

-1.el7.x86_64.rpm

警告:/mnt/Packages/ntsysv-1.7.4-1.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY

准备中... ################################# [100%]

软件包 ntsysv-1.7.4-1.el7.x86_64 已经安装

结尾加“--force”选项是强制安装所指定的rpm软件包。

2、升级RPM软件

[root@centos01 ~]# rpm -U /mnt/Packages/ntsysv-1.7.4-1.el7.x86_64.rpm

警告:/mnt/Packages/ntsysv-1.7.4-1.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY

软件包 ntsysv-1.7.4-1.el7.x86_64 已经安装

3、卸载RPM软件

卸载rpm软件包的语法格式及辅助选项如下:

应用举例:

[root@centos01 ~]# rpm -e ntsysv

[root@centos01 ~]# rpm -ivh /mnt/Packages/system-config

-kickstart-2.9.6-1.el7.noarch.rpm --nodeps

警告:/mnt/Packages/system-config-kickstart-2.9.6-1.el7.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY

准备中... ################################# [100%]

正在升级/安装...

1:system-config-kickstart-2.9.6-1.e################################# [100%]

4、维护RPM数据库

[root@centos01 ~]# rpm --initdb

[root@centos01 ~]# rpm --rebuilddb

5、导入验证公钥

[root@centos01 ~]# cd /mnt/

[root@centos01 mnt]# ls

CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7

EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL

[root@centos01 mnt]# rpm --import ./RPM-GPG-KEY-CentOS-7

[root@centos01 ~]# rpm -ivh /mnt/Packages/dhcp-4.2.5

-58.el7.centos.x86_64.rpm

准备中... ################################# [100%]

正在升级/安装...

1:dhcp-12:4.2.5-58.el7.centos ################################# [100%]

6、解决软件包依赖关系

三、Linux应用程序基础

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

1)文件位置

系统命令:一般在/bin和/sbin目录中,或为Shell内部指令。

应用程序:通常在/usr/bin和/usr/sbin目录中。

2)主要用途

系统命令:完成对系统的基本管理工作,例如IP配置工具。

应用程序:完成相对独立的其他辅助任务,例如网页浏览器。

3)适用环境

系统命令:一般只在字符操作界面中运行。

应用程序:根据实际需要,有些程序可在图形界面中运行。

4)运行格式

系统命令:一般包括命令字、命令选项和命令参数。

应用程序:通常没有固定的执行格式。

2、典型应用程序的目录结构

3、常见的软件包封装类型

四、源代码编译安装

1、源代码编译概述

1)使用源代码安装软件的优点

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

2)应用源代码编译安装场合举例

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

2、编译安装源代码包

1)Tarball包

.tar.gz和.tar.bz2格式居多。软件素材参考:http://sourceforge.net

2)完整性校验

计算MD5校验和,并与官方提供的值相比较��判断是否一致。如下:

[root@centos01 ~]# md5sum /mnt/Packages/tomcat-7.0.76-2.el7.noarch.rpm

3c901508f0651c5c3207f999fbf395ed /mnt/Packages/tomcat-7.0.76-2.el7.noarch.rpm

3)确认源代码编译环境

需要安装支持C/C++程序语言的编译器,如下所示:

[root@centos01 ~]# rpm -qa | grep gcc

libgcc-4.8.5-16.el7.x86_64

gcc-c++-4.8.5-16.el7.x86_64

gcc-4.8.5-16.el7.x86_64

gcc-gfortran-4.8.5-16.el7.x86_64

[root@centos01 ~]# rpm -qa | grep make

make-3.82-23.el7.x86_64

automake-1.13.4-3.el7.noarch

4、编译安装过程

5、编译安装步骤

1)tar解包

通常情况下习惯性将软件包释放到/usr/src/目录,解包后的源代码文件位置/usr/src/软件名-版本号/。应用举例:

[root@centos01 ~]# tar zxvf /mnt/httpd-2.2.17.tar.gz -C /usr/src/

2)./configure配置

使用源码目录中的configure脚本;执行“./configure --help”可查看帮助;典型的配置选项:--prefix=软件安装目录。应用举例:

[root@centos01 ~]# cd /usr/src/httpd-2.2.17/

[root@centos01 httpd-2.2.17]# ./configure --prefix=/usr/local/httpd

不指定任何配置选项,则采用默认值。

3)编译

[root@centos01 httpd-2.2.17]# make

4)安装

[root@centos01 httpd-2.2.17]#make install

注意:编译和安装可以一起执行,中间结合&&即可一次性执行两条命令。

5)优化程序目录

[root@centos01 ~]# ln -s /usr/local/httpd/bin/* /usr/local/bin/

6)创建系统服务,添加执行权限

[root@centos01 ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

[root@centos01 ~]# chmod +x /etc/init.d/httpd

7)修改系统服务

[root@centos01 ~]# vim /etc/init.d/httpd

#!/bin/sh

#chkconfig:35 80 20

............

8)添加为系统服务,设置开机自动启动

[root@centos01 ~]# chkconfig --add httpd

[root@centos01 ~]# chkconfig --level 35 httpd on

9)启动apache服务

[root@centos01 ~]# systemctl start httpd

10)监听apache服务的端口号

[root@centos01 ~]# netstat -anptu | grep 80

tcp6 0 0 :::80 :::* LISTEN 53115/httpd

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档