首頁 > 軟體

Linux安裝及管理程式詳述

2020-06-16 16:28:38

一、RPM包管理工具

RPM Pachage Manager由Red Hat公司提出,被眾多Linux發行版所採用。建立統一的資料庫檔案,詳細記錄軟體包安裝、解除安裝等變化資訊,能夠自動分析軟體包依賴關係。RPM軟體包一般命名格式如下:

1、查詢已安裝的RPM軟體資訊

查詢已安裝的RPM軟體包語法格式如下:

應用舉例:

[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
…………<!--此處省略部分內容-->

2、查詢檔案或目錄屬於哪個RPM軟體

語法格式如下:

應用舉例:

[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

3、查詢未安裝的RPM包檔案

查詢未安裝的RPM軟體包語法格式如下:

應用舉例:

[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

二、安裝、升級和解除安裝RPM軟體

安裝、升級和解除安裝RPM軟體的語法格式及常用選項如下:

1、安裝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軟體包。

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    <!--解除安裝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%]

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    
              <!--再次安裝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  <!--檢視是否安裝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

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         

IT145.com E-mail:sddin#qq.com