第八章:软件包的安装与管理
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. 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 //加载模块 |
安装成功。