一、RPM包管理工具
RPM Pachage Manager由Red Hat公司提出,被眾多Linux發(fā)行版所采用。建立統(tǒng)一的數(shù)據(jù)庫文件,詳細記錄軟件包安裝、卸載等變化信息,能夠自動分析軟件包依賴關(guān)系。RPM軟件包一般命名格式如下:
1、查詢已安裝的RPM軟件信息
查詢已安裝的RPM軟件包語法格式如下:
應(yīng)用舉例:
[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 …………<!--此處省略部分內(nèi)容--> [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在系統(tǒng)中安裝的所有目錄--> /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 …………<!--此處省略部分內(nèi)容-->
2、查詢文件或目錄屬于哪個RPM軟件
語法格式如下:
應(yīng)用舉例:
[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軟件包語法格式如下:
應(yīng)用舉例:
[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 ………… <!--此處省略部分內(nèi)容--> [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 準(zhǔn)備中... ################################# [100%] 軟件包 ntsysv-1.7.4-1.el7.x86_64 已經(jīng)安裝
結(jié)尾加“–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 已經(jīng)安裝
3、卸載RPM軟件
卸載rpm軟件包的語法格式及輔助選項如下:
應(yīng)用舉例:
[root@centos01 ~]# rpm -e ntsysv <!--卸載ntsysv程序--> [root@centos01 ~]# rpm -ivh /mnt/Packages/system-config -kickstart-2.9.6-1.el7.noarch.rpm --nodeps <!--結(jié)合“--nodeps”選項忽略依賴關(guān)系--> 警告:/mnt/Packages/system-config-kickstart-2.9.6-1.el7.noarch.rpm: 頭V3 RSA/SHA256 Signature, 密鑰 ID f4a80eb5: NOKEY 準(zhǔn)備中... ################################# [100%] 正在升級/安裝... 1:system-config-kickstart-2.9.6-1.e################################# [100%]
4、維護RPM數(shù)據(jù)庫
[root@centos01 ~]# rpm --initdb <!--或者--> [root@centos01 ~]# rpm --rebuilddb
5、導(dǎo)入驗證公鑰
[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 <!--導(dǎo)入驗證公鑰--> [root@centos01 ~]# rpm -ivh /mnt/Packages/dhcp-4.2.5 -58.el7.centos.x86_64.rpm <!--再次安裝rpm包不再顯示密鑰--> 準(zhǔn)備中... ################################# [100%] 正在升級/安裝... 1:dhcp-12:4.2.5-58.el7.centos ################################# [100%]
6、解決軟件包依賴關(guān)系
三、Linux應(yīng)用程序基礎(chǔ)
1、應(yīng)用程序與系統(tǒng)命令的關(guān)系
1)文件位置
-
系統(tǒng)命令:一般在/bin和/sbin目錄中,或為Shell內(nèi)部指令。
- 應(yīng)用程序:通常在/usr/bin和/usr/sbin目錄中。
2)主要用途
-
系統(tǒng)命令:完成對系統(tǒng)的基本管理工作,例如IP配置工具。
- 應(yīng)用程序:完成相對獨立的其他輔助任務(wù),例如網(wǎng)頁瀏覽器。
3)適用環(huán)境
-
系統(tǒng)命令:一般只在字符操作界面中運行。
- 應(yīng)用程序:根據(jù)實際需要,有些程序可在圖形界面中運行。
4)運行格式
-
系統(tǒng)命令:一般包括命令字、命令選項和命令參數(shù)。
- 應(yīng)用程序:通常沒有固定的執(zhí)行格式。
2、典型應(yīng)用程序的目錄結(jié)構(gòu)
3、常見的軟件包封裝類型
四、源代碼編譯安裝
1、源代碼編譯概述
1)使用源代碼安裝軟件的優(yōu)點
獲得最新的軟件版本,及時修復(fù)bug;根據(jù)用戶需要,靈活定制軟件功能。
2)應(yīng)用源代碼編譯安裝場合舉例
安裝較新版本的應(yīng)用程序時使用;當(dāng)前安裝的程序無法滿足需要時使用;需要為應(yīng)用程序添加新的功能時使用等等。
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)確認源代碼編譯環(huán)境
需要安裝支持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解包
通常情況下習(xí)慣性將軟件包釋放到/usr/src/目錄,解包后的源代碼文件位置/usr/src/軟件名-版本號/。應(yīng)用舉例:
[root@centos01 ~]# tar zxvf /mnt/httpd-2.2.17.tar.gz -C /usr/src/
2)./configure配置
使用源碼目錄中的configure腳本;執(zhí)行“./configure –help”可查看幫助;典型的配置選項:–prefix=軟件安裝目錄。應(yīng)用舉例:
[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
注意:編譯和安裝可以一起執(zhí)行,中間結(jié)合&&即可一次性執(zhí)行兩條命令。
5)優(yōu)化程序目錄
[root@centos01 ~]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
6)創(chuàng)建系統(tǒng)服務(wù),添加執(zhí)行權(quán)限
[root@centos01 ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd [root@centos01 ~]# chmod +x /etc/init.d/httpd
7)修改系統(tǒng)服務(wù)
[root@centos01 ~]# vim /etc/init.d/httpd #!/bin/sh #chkconfig:35 80 20 ............<!--此處省略部分內(nèi)容-->
8)添加為系統(tǒng)服務(wù),設(shè)置開機自動啟動
[root@centos01 ~]# chkconfig --add httpd [root@centos01 ~]# chkconfig --level 35 httpd on
9)啟動apache服務(wù)
[root@centos01 ~]# systemctl start httpd
10)監(jiān)聽apache服務(wù)的端口號
[root@centos01 ~]# netstat -anptu | grep 80 tcp6 0 0 :::80 :::* LISTEN 53115/httpd