第八章:軟件包的安裝與管理
1.Linux常見軟件包格式
RPM:Redhat PackageManagement
紅帽包管理。Redhat Linux專用的軟件包格式,擴展名爲.rpm
DEB:Debian Linux專用的軟件包格式,擴展名爲.deb
APT:Advanced packagetool,高級包工具
Ubuntu Linux專用軟件包格式,基於Internet互聯網的APT軟件源,擴展名爲.apt
Source code packet源碼包
軟件包的源碼文件包,在所有Unix/Linux下通用。
擴展名一般爲壓縮格式.tar .tar.gz .tar.bz2
2.RPM軟件包管理
現在,幾乎所有的linux發行版都支持rpm包的安裝。(suse,debian甚至AIX的小型機)
對於windows來說,包是後綴爲.exe類的軟件包,代碼是開發人員已經編譯好的,看不到源代碼!在linux下是裝不了.exe軟件包的,因爲兩者的架構不同,windows下的應用程序在linux下不可用!
linux下的rpm包也是被編譯過的二進制文件,也是看不到源代碼;可是Linux更多的軟件是用源碼包安裝!因爲linux開源的意義使得我們可以很容易的獲取到軟件的源代碼,而windows下安裝包幾乎是看不到源代碼的!
2.1.RPM軟件包的組成
Package-version-release.arch.rpm
例:掛載虛擬機鏡像,提取rpm包詳細解釋
[root@freeit ~]# mount /dev/cdrom /mnt/ mount: /dev/sr0 is write-protected, mounting read-only [root@freeit ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/rhel-root 61410000 3049788 58360212 5% / devtmpfs 496084 0 496084 0% /dev tmpfs 505392 0 505392 0% /dev/shm tmpfs 505392 7112 498280 2% /run tmpfs 505392 0 505392 0% /sys/fs/cgroup /dev/sda1 201388 106044 95344 53% /boot /dev/sr0 4138442 4138442 0 100% /mnt [root@freeit ~]# cp /mnt/Packages/vsftpd-3.0.2-9.el7.x86_64.rpm /tmp/ [root@freeit ~]# cd /tmp/ [root@freeit tmp]# ll total 168 -r--r--r--. 1 root root 169476 May 6 10:36 vsftpd-3.0.2-9.el7.x86_64.rpm |
說明:
Vsftpd:包名
3.0.2 :主版本號
9.el7 :次版本號
x86_64:使用架構,只能安裝在X86_64位架構的系統中
.rpm :包擴展名
2.2.RPM軟件包類別
zlib-devel-1.2.3-29.el6.i686.rpm
//支持32位操作系統
zlib-devel-1.2.3-29.el6.x86_64.rpm
//支持64位操作系統
yum-plugin-versionlock-1.1.30-14.el6.noarch.rpm
//此軟件不受架構的限制!
2.3.RPM軟件包的查詢
語法:
rpm {-q |--query} [select-options ] [verify-options] PACKAGE FILE |
說明:
{-q |--query}:表明執行軟件包查詢
select-options:指定本次查詢的對象
verify-options:指定本次查詢要獲得的信息
PACKAGE FILE:要查詢的軟件包
RPM軟件包查詢命令
rpm –qa | grep [packet_name]
//查詢系統上已安裝過的RPM包。加[grep]爲過濾查詢指定的包
---------------------------------------------查詢所有RPM包---------------------------------------------------- [root@freeit tmp]# rpm -qa libXxf86misc-1.0.3-7.1.el7.x86_64 perl-HTTP-Tiny-0.033-3.el7.noarch baobab-3.8.2-4.el7.x86_64 ldns-1.6.16-7.el7.x86_64 xkeyboard-config-2.9-4.el7.noarch sox-14.4.1-6.el7.x86_64 perl-threads-1.87-4.el7.x86_64 gnome-system-log-3.8.1-5.el7.x86_64 iproute-3.10.0-13.el7.x86_64 libreport-filesystem-2.1.11-9.el7.x86_64 xorg-x11-xinit-1.3.2-13.el7.x86_64 ……………………………. //此命令會列出所有Linux中的rpm包 -----------------------------------------------查詢指定的rpm包------------------------------------------------ [root@freeit tmp]# rpm -qa |grep gnome-system-log-3.8.1-5.el7.x86_64 gnome-system-log-3.8.1-5.el7.x86_64 |
rpm –qi
//查詢安裝的RPM軟件包的詳細信息
[root@freeit tmp]# rpm -qi vsftpd-3.0.2-9.el7.x86_64.rpm package vsftpd-3.0.2-9.el7.x86_64.rpm is not installed |
rpm –ql
//查詢rpm軟件包安裝到系統的路徑信息(安裝了那些文件)
--------------------------------------------以autofs爲例查詢安裝了那些文件----------------------------- [root@freeit tmp]# rpm -ql autofs /etc/auto.master /etc/auto.master.d /etc/auto.misc /etc/auto.net /etc/auto.smb /etc/autofs_ldap_auth.conf /etc/sysconfig/autofs /usr/lib/systemd/system/autofs.service ………………… |
rpm –qf
//查詢哪個文件屬於哪個軟件包
例:查詢/usr/bin屬於那個軟件包
[root@freeit tmp]# rpm -qf /usr/bin/ filesystem-3.2-18.el7.x86_64 |
rpm –qpi
//查詢安裝或沒有安裝的軟件包的詳細信息
例:查詢vsftpd軟件包的詳細信息
[root@freeit tmp]# rpm -qpi vsftpd-3.0.2-9.el7.x86_64.rpm warning: vsftpd-3.0.2-9.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Name : vsftpd Version : 3.0.2 Release : 9.el7 Architecture: x86_64 Install Date: (not installed) Group : System Environment/Daemons Size : 351462 License : GPLv2 with exceptions Signature : RSA/SHA256, Thu 03 Apr 2014 05:54:58 AM CST, Key ID 199e2f91fd431d51 Source RPM : vsftpd-3.0.2-9.el7.src.rpm Build Date : Fri 07 Mar 2014 05:58:22 PM CST Build Host : x86-025.build.eng.bos.redhat.com Relocations : (not relocatable) Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> Vendor : Red Hat, Inc. URL : https://security.appspot.com/vsftpd.html Summary : Very Secure Ftp Daemon Description : vsftpd is a Very Secure FTP daemon. It was written completely from scratch. |
注:
rpm的查詢是基於本地數據庫的,所以查詢速度快。
2.4.RPM軟件包的卸載
語法:
rpm {-e|--erase} [erase-options] PACKAGE FILE |
說明:
-e|--erase:表明執行軟件包卸載
erase-options:卸載選項
PACKAGE FILE:要卸載的軟件包名
命令:
rpm –e [packet_name]
例:刪除autofs軟件包
[root@freeit tmp]# rpm -e autofs [root@freeit tmp]# rpm -q autofs package autofs is not installed |
2.5.RPM包的安裝、升級
安裝語法:
rpm {-I |--install} [ install-options ] PACKAGE FILE |
說明:
{-I |--install}:表明執行軟件包安裝
[ install-options ]:安裝選項
PACKAGE FILE:要安裝的軟件包名
常用參數:
-i:安裝
-v:顯示安裝過程
-h:列出安裝標記
-p:顯示安裝進度
-f:忽略任何錯誤
-U:升級安裝
其他參數:
--replacepkgs:在原來的基礎上修補安裝,不覆蓋原來修改過的
--force:強制安裝
--oldpackage:安裝舊的版本
--nodeps:不檢查依賴關係
升級語法:
rpm {-U|--upgrade} [ install-options ] PACKAGE FILE |
說明:
-U|--upgrade:表明執行軟件包升級
install-options:升級選項,基本與安裝選項相同
PACKAGE FILE:要升級的軟件包名
參數:
-F:如果軟件已安裝則升級,如果沒有安裝則不安裝
-U:如果安裝則升級,如果沒安裝則安裝
2.5.1.一般rpm軟件包的安裝
例:安裝vsftpd軟件包
----------------------------------------------普通安裝------------------------------------------------------------------ [root@freeit tmp]# rpm -ivh vsftpd-3.0.2-9.el7.x86_64.rpm warning: vsftpd-3.0.2-9.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating / installing... 1:vsftpd-3.0.2-9.el7 ################################# [100%] -----------------------------------------------強制安裝--------------------------------------------------------------- [root@freeit tmp]# rpm -ivh vsftpd-3.0.2-9.el7.x86_64.rpm --force warning: vsftpd-3.0.2-9.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating / installing... 1:vsftpd-3.0.2-9.el7 ################################# [100%] ---------------------------------------------修補安裝----------------------------------------------------------------- [root@freeit tmp]# rpm -ivh vsftpd-3.0.2-9.el7.x86_64.rpm --replacepkgs warning: vsftpd-3.0.2-9.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating / installing... 1:vsftpd-3.0.2-9.el7 ################################# [100%] //此安裝不會覆蓋原來修改過的 |
2.5.2.依賴性安裝
例:安裝httpd軟件包
[root@freeit tmp]# cp /mnt/Packages/httpd-2.4.6-17.el7.x86_64.rpm . //把鏡像中的httpd包提取出來 [root@freeit tmp]# ls httpd-2.4.6-17.el7.x86_64.rpm vsftpd-3.0.2-9.el7.x86_64.rpm [root@freeit tmp]# rpm -ivh httpd-2.4.6-17.el7.x86_64.rpm warning: httpd-2.4.6-17.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY error: Failed dependencies: /etc/mime.types is needed by httpd-2.4.6-17.el7.x86_64 httpd-tools = 2.4.6-17.el7 is needed by httpd-2.4.6-17.el7.x86_64 libapr-1.so.0()(64bit) is needed by httpd-2.4.6-17.el7.x86_64 libaprutil-1.so.0()(64bit) is needed by httpd-2.4.6-17.el7.x86_64 |
如上,安裝httpd軟件包時,提示需要安裝其他包,這就是依賴關係。存在依賴關係的包不安裝,則此包不能安裝。
但是,可以不考慮依賴關係安裝
[root@freeit tmp]# rpm -ivh httpd-2.4.6-17.el7.x86_64.rpm --nodeps warning: httpd-2.4.6-17.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating / installing... 1:httpd-2.4.6-17.el7 ################################# [100%] -------------------------------------------------重啓服務--------------------------------------------------------- [root@freeit tmp]# systemctl restart httpd.service Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details. |
如上:不考慮依賴關係安裝,雖然安裝成功,但是服務卻起不來。所以,這種安裝不可取。
注:
對於—nodeps的安裝,有的服務適用,但大多數服務不適用,請酌情處理。
3.YUM軟件倉庫
3.1.簡介
YUM(Yellow dog Updater Modified),是由DukeUniversity所發起的計劃,目的就是爲了解決RPM依賴性關係的問題,方便使用者進行軟件安裝、升級等工作。
YUM只是爲了解決RPM的依賴性關係,而不是一種其他的軟件安裝模式,其本質還是使用RPM包安裝方式。
YUM的最大優點是解決了軟件包的依賴性關係。
3.2.YUM命令
yum install [rpm-packet-name]
//安裝軟件包
yum –y insttall [rpm-packet-name]
//不提示直接安裝
yum –y remove [rpm-packet-name]
//卸載
yum list all |grep [rpm-packet-name]
//查找
yum search [rpm-packet-name]
//搜索某軟件包的詳細信息
yum list [rpm-packet-name]
//查看看某個軟件包是否安裝
yum list all
//列出所有已安裝的包。可以測試yum倉庫是否有問題
yum info [rpm-packet-name]
//搜索某軟件包的詳細信息
yum provides 或 yumwhatprovides
//搜索某個文件屬於哪一個軟件包
yum clean dbcache |all或yum cleanall
//清除所有YUM 倉庫緩存。緩存在/var/cache/yum
yum update
//加入到RHN,尋求更新
yum groupinstall [paskagegroup]
//安裝軟件包組
例:安裝kde桌面&中文支持
yum groupinstall “KDE Desktop” yum groupinstall “Chinese Support” |
yum grouplist
//查看軟件包組
yum localinstall [rpm-packet-name]
//首先嚐試從yum倉庫裏查看是否有匹配的包(主要用於安裝第三方軟件,當gpg簽名不正確或缺乏依賴關係的時候,可以加-- nogpgcheck參數跳過安裝)
3.3.YUM倉庫配置
默認的配置文件在/etc/yum.repo.d下創建一個以.repo爲後綴的文件。
在RHEL7之前的系統中,系統缺省有一個yum倉庫的配置,但在RHEL7系統中,缺省是沒有的,也就是說要手動創建yum倉庫---私有yum倉庫。
下面手動創建一個私有YUM倉庫
[root@freeit yum.repos.d]# pwd /etc/yum.repos.d [root@freeit yum.repos.d]# vim server.repo [base] name=Red Hat Enterprise Linux 6.4 baseurl=file:///mnt enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release |
說明:
/etc/yum.repo.d/server.repo從第一行到最後一行的意思爲:
① 倉庫名,不能與其他的倉庫名衝突,也不能使用特殊符號,如空格;
② 只是對倉庫做描述,寫什麼都可以;
③ 指定對應安裝源的路徑;
④ 類似開關,1打開,0關閉,默認刪掉也是1;
⑤ 也是類似開關,設置0爲不檢查,設置1要檢查包的完整性,此時從⑥的公鑰去檢查;
⑥ 公鑰的鑰匙;
注:
可以指定多個倉庫,但是多個yum倉庫中任何一個yum倉庫配置的有問題,軟件包是安裝不了的。
3.4.YUM查詢、搜索&安裝&卸載
例1:查詢httpd屬於那個軟件包並安裝httpd服務
--------------------------------------------查詢http包屬於哪個安裝包------------------------------------- [root@freeit yum.repos.d]# yum provides httpd Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. httpd-2.4.6-17.el7.x86_64 : Apache HTTP Server Repo : base
[root@freeit yum.repos.d]# yum search httpd //此查詢類似模糊查詢,沒有provides查詢更精確 Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. ================================= N/S matched: httpd ================================= httpd.x86_64 : Apache HTTP Server httpd-devel.x86_64 : Development interfaces for the Apache HTTP server httpd-manual.noarch : Documentation for the Apache HTTP server httpd-tools.x86_64 : Tools for use with the Apache HTTP Server libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications mod_dav_svn.x86_64 : Apache httpd module for Subversion server
Name and summary matches only, use "search all" for everything. ---------------------------------------------安裝httpd服務-------------------------------------------------------- [root@freeit yum.repos.d]# yum -y install httpd-2.4.6-17.el7.x86_64 Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.6-17.el7 will be installed --> Processing Dependency: httpd-tools = 2.4.6-17.el7 for package: httpd-2.4.6-17.el7.x86_64 --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.x86_64 --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64 --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64 --> Running transaction check ---> Package apr.x86_64 0:1.4.8-3.el7 will be installed ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed ---> Package httpd-tools.x86_64 0:2.4.6-17.el7 will be installed ---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed --> Finished Dependency Resolution //依賴性關係的軟件包 Dependencies Resolved
====================================================================================== Package Arch Version Repository Size ====================================================================================== Installing: httpd x86_64 2.4.6-17.el7 base 1.2 M Installing for dependencies: apr x86_64 1.4.8-3.el7 base 103 k apr-util x86_64 1.5.2-6.el7 base 92 k httpd-tools x86_64 2.4.6-17.el7 base 77 k mailcap noarch 2.1.41-2.el7 base 31 k
Transaction Summary ====================================================================================== Install 1 Package (+4 Dependent packages)
Total download size: 1.5 M Installed size: 4.3 M Downloading packages: -------------------------------------------------------------------------------------- Total 26 MB/s | 1.5 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : apr-1.4.8-3.el7.x86_64 1/5 Installing : apr-util-1.5.2-6.el7.x86_64 2/5 Installing : httpd-tools-2.4.6-17.el7.x86_64 3/5 Installing : mailcap-2.1.41-2.el7.noarch 4/5 Installing : httpd-2.4.6-17.el7.x86_64 5/5 Verifying : mailcap-2.1.41-2.el7.noarch 1/5 Verifying : httpd-tools-2.4.6-17.el7.x86_64 2/5 Verifying : apr-1.4.8-3.el7.x86_64 3/5 Verifying : apr-util-1.5.2-6.el7.x86_64 4/5 Verifying : httpd-2.4.6-17.el7.x86_64 5/5
Installed: httpd.x86_64 0:2.4.6-17.el7
Dependency Installed: apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-17.el7 mailcap.noarch 0:2.1.41-2.el7
Complete! |
如上:使用yum安裝httpd時,免去了依賴性關係的麻煩,一次性裝好。
例2:卸載httpd服務
[root@freeit yum.repos.d]# yum -y remove httpd.x86_64 Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.6-17.el7 will be erased --> Finished Dependency Resolution
Dependencies Resolved
====================================================================================== Package Arch Version Repository Size ====================================================================================== Removing: httpd x86_64 2.4.6-17.el7 installed 3.7 M
Transaction Summary ====================================================================================== Remove 1 Package
Installed size: 3.7 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Erasing : httpd-2.4.6-17.el7.x86_64 1/1 Verifying : httpd-2.4.6-17.el7.x86_64 1/1
Removed: httpd.x86_64 0:2.4.6-17.el7
Complete! |
注:
此處卸載httpd服務,如果使用【rpm –e】卸載,由於存在諸多依賴性關係,會提示【error: Failed dependencies】,不能卸載。這也就體現了yum的優勢。
4.源碼包安裝
4.1.壓縮文件種類
源碼包壓縮文件的擴展名一般爲.tar .tar.gz .tar.bz2,常見的爲後兩種
.tar.gz
壓縮命令:
例1:把/etc/passwd複製到/tmp下,並壓縮爲以.tar.gz結尾的文件
tar zcf passwd passwd.tar.gz [root@freeit tmp]# ls fuse-2.7.4 httpd-2.4.6-17.el7.x86_64.rpm passwd.tar.gz fuse-2.7.4.tar.gz passwd vsftpd-3.0.2-9.el7.x86_64.rpm |
解壓命令:
例2:解壓這個文件fuse-2.7.4.tar.gz
[root@freeit tmp]# tar -zxvf fuse-2.7.4.tar.gz fuse-2.7.4/ fuse-2.7.4/doc/ fuse-2.7.4/doc/how-fuse-works fuse-2.7.4/doc/kernel.txt ………………… |
.tar.bz2
壓縮命令:
例:把passwd壓縮爲.tar.bz2結尾的文件
[root@freeit tmp]# tar -cjvf passwd.tar.bz2 passwd passwd [root@freeit tmp]# ls fuse-2.7.4 passwd vsftpd-3.0.2-9.el7.x86_64.rpm fuse-2.7.4.tar.gz passwd.tar.bz2 httpd-2.4.6-17.el7.x86_64.rpm vmware-root |
解壓命令:
例:把/tmp下的wine-1.1.33.tar.bz2解壓
[root@freeit tmp]# tar -jxvf wine-1.1.33.tar.bz2 [root@freeit tmp]# ls fuse-2.7.4 passwd vsftpd-3.0.2-9.el7.x86_64.rpm fuse-2.7.4.tar.gz passwd.tar.bz2 wine-1.1.33 httpd-2.4.6-17.el7.x86_64.rpm vmware-root wine-1.1.33.tar.bz2 |
4.2.源碼包安裝
就以fuse-2.7.4爲例,前面實驗我們已經加壓好了,現在進文件開始安裝
[root@freeit tmp]# cd fuse-2.7.4/ [root@freeit fuse-2.7.4]# pwd /tmp/fuse-2.7.4 [root@freeit fuse-2.7.4]# ls aclocal.m4 config.sub doc INSTALL Makefile.in util AUTHORS configure example install-sh missing ChangeLog configure.in FAQ kernel mkinstalldirs compile COPYING Filesystems lib NEWS config.guess COPYING.LIB fuse.pc.in ltmain.sh README config.rpath depcomp include Makefile.am README.NFS ------------------------------------------------------查看庫文件---------------------------------------------------- [root@freeit fuse-2.7.4]# ls lib/ fuse.c fuse_lowlevel.c fuse_signals.c modules ulockmgr.c fuse_i.h fuse_misc.h fuse_versionscript mount_bsd.c fuse_kern_chan.c fuse_mt.c helper.c mount.c fuse_loop.c fuse_opt.c Makefile.am mount_util.c fuse_loop_mt.c fuse_session.c Makefile.in mount_util.h //c語言文件 -----------------------------------------------------查看README文件--------------------------------------------- [root@freeit fuse-2.7.4]# less README General Information ===================
FUSE (Filesystem in Userspace) is a simple interface for userspace programs to export a virtual filesystem to the Linux kernel. FUSE also aims to provide a secure method for non privileged users to create and mount their own filesystem implementations.
You can download the source code releases from
http://sourceforge.net/projects/fuse
or alternatively you can use CVS to get the very latest development version:
cvs -d :pserver:[email protected]:/cvsroot/fuse co fuse
Dependencies ============
Linux kernel version 2.6.X where X >= 9.
Alternatively a kernel module from FUSE release 2.5.* can be used with this release, which supports kernels >= 2.4.21.
Installation ============
./configure make make install modprobe fuse
You may also need to add '/usr/local/lib' to '/etc/ld.so.conf' and/or run ldconfig.
Linux kernels 2.6.14 or later contain FUSE support out of the box. If FUSE support is detected, the kernel module in this package will not be compiled. It is possible to override this with the README |
如上:此文件告訴了我們怎麼安裝此源碼包
[root@freeit fuse-2.7.4]# ./configure [root@freeit fuse-2.7.4]# make //編譯文件 [root@freeit fuse-2.7.4]# make install //開始真正安裝文件 [root@freeit fuse-2.7.4]# modeprobe fuse //加載模塊 |
安裝成功。