Linux安裝及管理程序精講

博文目錄node

1、RPM包管理工具python

2、安裝、升級和卸載RPM軟件linux

3、Linux應用程序基礎c++

4、源代碼編譯安裝web

1、RPM包管理工具

RPM Pachage Manager由Red Hat公司提出,被衆多Linux發行版所採用。創建統一的數據庫文件,詳細記錄軟件包安裝、卸載等變化信息,可以自動分析軟件包依賴關係。RPM軟件包通常命名格式以下:
Linux安裝及管理程序精講shell

一、查詢已安裝的RPM軟件信息

查詢已安裝的RPM軟件包語法格式以下:
Linux安裝及管理程序精講數據庫

應用舉例:apache

[root@centos01 ~]# rpm -qa  <!--查詢全部已安裝的rpm軟件信息-->
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軟件包-->
bash-4.2.46-28.el7.x86_64
[root@centos01 ~]# rpm -qi bash    <!--查詢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 <http://bugs.centos.org>
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 <!--查看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
…………<!--此處省略部份內容-->

二、查詢文件或目錄屬於哪一個RPM軟件

語法格式以下:
Linux安裝及管理程序精講vim

應用舉例:centos

[root@centos01 ~]# rpm -qf /usr/bin/vim   <!--查詢vim是由哪一個軟件包安裝的-->
vim-enhanced-7.4.160-2.el7.x86_64
[root@centos01 ~]# rpm -qf /usr/libexec/openssh/  <!--查看配置文件是哪一個程序使用-->
openssh-7.4p1-11.el7.x86_64

三、查詢未安裝的RPM包文件

查詢未安裝的RPM軟件包語法格式以下:
Linux安裝及管理程序精講

應用舉例:

[root@centos01 ~]# rpm -qpi /mnt/Packages/httpd-2.4.6
-67.el7.centos.x86_64.rpm    
            <!--查看httpd的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 <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@centos01 ~]# rpm -qpl /mnt/Packages/httpd-2.4.6
-67.el7.centos.x86_64.rpm    
          <!--查看httpd的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    
                <!--查看httpd安裝後的配置文件-->
/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

2、安裝、升級和卸載RPM軟件

安裝、升級和卸載RPM軟件的語法格式及經常使用選項以下:
Linux安裝及管理程序精講

一、安裝RPM軟件

[root@centos01 ~]# rpm -ivh /mnt/Packages/ntsysv-1.7.4
-1.el7.x86_64.rpm    <!--安裝ntsysv程序-->
警告:/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軟件包。

二、升級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 已經安裝

三、卸載RPM軟件

卸載rpm軟件包的語法格式及輔助選項以下:
Linux安裝及管理程序精講

應用舉例:

[root@centos01 ~]# rpm -e ntsysv    <!--卸載ntsysv程序-->
[root@centos01 ~]# rpm -ivh /mnt/Packages/system-config
-kickstart-2.9.6-1.el7.noarch.rpm --nodeps   
              <!--結合「--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%]

四、維護RPM數據庫

[root@centos01 ~]# rpm --initdb
<!--或者-->
[root@centos01 ~]# rpm --rebuilddb

五、導入驗證公鑰

[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    
              <!--再次安裝rpm包再也不顯示密鑰-->
準備中...                          ################################# [100%]
正在升級/安裝...
   1:dhcp-12:4.2.5-58.el7.centos      ################################# [100%]

六、解決軟件包依賴關係

Linux安裝及管理程序精講

3、Linux應用程序基礎

一、應用程序與系統命令的關係

1)文件位置

  • 系統命令:通常在/bin和/sbin目錄中,或爲Shell內部指令。

  • 應用程序:一般在/usr/bin和/usr/sbin目錄中。

2)主要用途

  • 系統命令:完成對系統的基本管理工做,例如IP配置工具。

  • 應用程序:完成相對獨立的其餘輔助任務,例如網頁瀏覽器。

3)適用環境

  • 系統命令:通常只在字符操做界面中運行。

  • 應用程序:根據實際須要,有些程序可在圖形界面中運行。

4)運行格式

  • 系統命令:通常包括命令字、命令選項和命令參數。

  • 應用程序:一般沒有固定的執行格式。

二、典型應用程序的目錄結構

Linux安裝及管理程序精講

三、常見的軟件包封裝類型

Linux安裝及管理程序精講

4、源代碼編譯安裝

一、源代碼編譯概述

1)使用源代碼安裝軟件的優勢

得到最新的軟件版本,及時修復bug;根據用戶須要,靈活定製軟件功能。

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  <!--查看是否安裝gcc和gcc-c++-->
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-->
make-3.82-23.el7.x86_64
automake-1.13.4-3.el7.noarch

四、編譯安裝過程

Linux安裝及管理程序精講

五、編譯安裝步驟

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

———————— 本文至此結束,感謝閱讀 ————————