软件包管理基础
RPMRedHat Package Manager (红帽软件包管理器)
 
现在的RPM工具功能非常强大,可以用它来安装、升级、卸载和查询软件,同时还有软件的
校验功能。
一、安装步骤 
1、  检查软件包的依赖关系(当RPM检查时发现所依赖的链接库或程序等不存在或不符合要求时,默认的做法是中止软件包安装)
2、  检查软件包的冲突(安装前执行软件包的检查,如果RPM发现有冲突则会中止安装,比windows好。Windows安装不会检查这些,只有安装过后才会显示有冲突或系统直接蓝屏等)
3、  执行安装前的脚本程序(建立相关目录,清理多余文件等,为安装做好准备工作)
4、  处理配置文件(它可以把原配置文件换个名字保存起来,后缀加上.rpmorig
5、  解压软件包并存放到相应位置(把软件包解压到系统的那个目录下方便我们查找与安装,并同时设置好文件的权限)
6、  执行安装后脚本程序(为软件正确的执行设定相关资源,如修改inetd.conf 、运行ldconfig可以以新的动态链接库生效)
7、  更新RPM数据库(安装后,RPM装所有安装的软件及相关信息记录到数据库中,方便以后的查询,校验,卸载)
8、  执行安装时触发脚本程序(安装时触发脚本,卸载前触发脚本,卸载后触发脚本,这三大功能大大扩展了RPM软件包的管理)
二、常用命令
 
[root@mxl Server]# rpm -ivh httpd-2.2.3-6.el5.i386.rpm
-I 安装  -V 显示安装信息  -h显示安装进度
[root@mxl /]# rpm -qa  httpd
httpd-2.2.3-6.el5
httpd-manual-2.2.3-6.el5
-qa列出所有安装在linux本机的软件套件  可以查看软件包是否已经安装
如:
[root@mxl Server]# rpm -ivh xrestop-0.2-6.2.2.i386.rpm
warning: xrestop-0.2-6.2.2.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing...                ########################################### [100%]
        package xrestop-0.2-6.2.2 is already installed    提示此软件包已安装,
 
[root@mxl Server]# rpm -qi httpd  显示软件包的头部信息
Name        : httpd                        Relocations: (not relocatable)
Version     : 2.2.3                             Vendor: Red Hat, Inc.
Release     : 6.el5                         Build Date: Wed 29 Nov 2006 07:35:03 PM CST
Install Date: Fri 13 Jun 2008 07:35:39 AM CST      Build Host: hs20-bc2-3.build.redhat.com
Group       : System Environment/Daemons    Source RPM: httpd-2.2.3-6.el5.src.rpm
Size        : 2889883                          License: Apache Software License
Signature   : DSA/SHA1, Wed 17 Jan 2007 11:36:54 PM CST, Key ID 5326810137017186
Packager    : Red Hat, Inc. <[url]http://bugzilla.redhat.com/bugzilla>[/url]
URL         : [url]http://httpd.apache.org/[/url]
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.
 
[root@mxl Server]# rpm -qlp httpd-2.2.3-6.el5.i386.rpm查看未安装软件包的信息
warning: httpd-2.2.3-6.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/proxy_ajp.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/httpd/logs
/etc/httpd/modules
/etc/httpd/run
/etc/logrotate.d/httpd
/etc/rc.d/init.d/httpd
/etc/sysconfig/httpd
/usr/bin/ab
[root@mxl Server]# rpm -ql httpd 显示已安装的软件包信息
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/proxy_ajp.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/httpd/logs
/etc/httpd/modules
/etc/httpd/run
/etc/logrotate.d/httpd
/etc/rc.d/init.d/httpd
/etc/sysconfig/httpd
/usr/bin/ab
/usr/bin/htdbm
[root@mxl /]# rpm -qd httpd 显示软件包的说明文档、可执行程序及数据库文件
/usr/share/doc/httpd-2.2.3/ABOUT_APACHE
/usr/share/doc/httpd-2.2.3/CHANGES
/usr/share/doc/httpd-2.2.3/LICENSE
/usr/share/doc/httpd-2.2.3/NOTICE
/usr/share/doc/httpd-2.2.3/README
/usr/share/doc/httpd-2.2.3/VERSIONING
/usr/share/doc/httpd-2.2.3/migration.css
/usr/share/doc/httpd-2.2.3/migration.html
/usr/share/man/man1/ab.1.gz
/usr/share/man/man1/htdbm.1.gz
/usr/share/man/man1/htdigest.1.gz
/usr/share/man/man1/htpasswd.1.gz
/usr/share/man/man1/logresolve.1.gz
/usr/share/man/man8/apachectl.8.gz
/usr/share/man/man8/htcacheclean.8.gz
/usr/share/man/man8/httpd.8.gz
/usr/share/man/man8/rotatelogs.8.gz
/usr/share/man/man8/suexec.8.gz
[root@mxl /]# rpm -qc httpd 显示软件包的配置文件
/etc/httpd/conf.d/proxy_ajp.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/rc.d/init.d/httpd
/etc/sysconfig/httpd
/var/www/error/HTTP_BAD_GATEWAY.html.var
/var/www/error/HTTP_BAD_REQUEST.html.var
/var/www/error/HTTP_FORBIDDEN.html.var
/var/www/error/HTTP_GONE.html.var
/var/www/error/HTTP_INTERNAL_SERVER_ERROR.html.var
/var/www/error/HTTP_LENGTH_REQUIRED.html.var
/var/www/error/HTTP_METHOD_NOT_ALLOWED.html.var
/var/www/error/HTTP_NOT_FOUND.html.var
/var/www/error/HTTP_NOT_IMPLEMENTED.html.var
/var/www/error/HTTP_PRECONDITION_FAILED.html.var
/var/www/error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
/var/www/error/HTTP_REQUEST_TIME_OUT.html.var
/var/www/error/HTTP_REQUEST_URI_TOO_LARGE.html.var
/var/www/error/HTTP_SERVICE_UNAVAILABLE.html.var
/var/www/error/HTTP_UNAUTHORIZED.html.var
/var/www/error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
/var/www/error/HTTP_VARIANT_ALSO_VARIES.html.var
/var/www/error/contact.html.var
/var/www/error/include/bottom.html
/var/www/error/include/spacer.html
/var/www/error/include/top.html
[root@mxl /]# rpm -qs httpd显示软件包文件状态
Normal 表示文件未被其它软件包修改过
Not installed 表明此文件未安装
Replaced  表示文件被其它软件包修改或替换过
Net shared 表明此文件处于共享状态
normal        /etc/httpd
normal        /etc/httpd/conf
normal        /etc/httpd/conf.d
normal        /etc/httpd/conf.d/README
normal        /etc/httpd/conf.d/proxy_ajp.conf
normal        /etc/httpd/conf.d/welcome.conf
normal        /etc/httpd/conf/httpd.conf
normal        /etc/httpd/conf/magic
normal        /etc/httpd/logs
normal        /etc/httpd/modules
normal        /etc/httpd/run
normal        /etc/logrotate.d/httpd
normal        /etc/rc.d/init.d/httpd
normal        /etc/sysconfig/httpd
normal        /usr/bin/ab
normal        /usr/bin/htdbm
normal        /usr/bin/htdigest
normal        /usr/bin/htpasswd
normal        /usr/bin/logresolve
normal        /usr/lib/httpd
normal        /usr/lib/httpd/modules
normal        /usr/lib/httpd/modules/mod_actions.so
normal        /usr/lib/httpd/modules/mod_alias.so
normal        /usr/lib/httpd/modules/mod_asis.so
normal        /usr/lib/httpd/modules/mod_auth_basic.so
normal        /usr/lib/httpd/modules/mod_auth_digest.so
normal        /usr/lib/httpd/modules/mod_authn_alias.so
normal        /usr/lib/httpd/modules/mod_authn_anon.so
normal        /usr/lib/httpd/modules/mod_authn_dbd.so
normal        /usr/lib/httpd/modules/mod_authn_dbm.so
 
[root@mxl /]# rpm -qR httpd 显示软件包的依赖关系
/bin/bash 
/bin/mktemp 
/bin/mv 
/bin/rm 
/bin/sh 
/bin/sh 
/bin/sh 
/bin/sh 
/bin/sh 
/etc/mime.types 
/sbin/chkconfig 
/usr/bin/find 
/usr/sbin/useradd 
/usr/share/magic.mime 
config(httpd) = 2.2.3-6.el5
gawk 
initscripts >= 8.36
libapr-1.so.0 
libaprutil-1.so.0 
libc.so.6 
libc.so.6(GLIBC_2.0) 
libc.so.6(GLIBC_2.1) 
libc.so.6(GLIBC_2.1.3) 
libc.so.6(GLIBC_2.2) 
libc.so.6(GLIBC_2.3) 
libc.so.6(GLIBC_2.3.4) 
libc.so.6(GLIBC_2.4) 
libcrypt.so.1 
libcrypt.so.1(GLIBC_2.0) 
libcrypto.so.6 
libdb-4.3.so 
libdl.so.2 
libexpat.so.0 
liblber-2.3.so.0 
libldap-2.3.so.0 
libm.so.6 
libm.so.6(GLIBC_2.0) 
libpcre.so.0 
libpthread.so.0 
libpthread.so.0(GLIBC_2.0) 
libselinux.so.1 
libssl.so.6 
libz.so.1 
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(VersionedDependencies) <= 3.0.3-1
rtld(GNU_HASH) 
sh-utils 
textutils 
[root@mxl /]# rpm -q -g Applications/Archiving查看应用/档案里有那些软件包 (注意大小写)
zip-2.31-1.2.2
pax-3.4-1.2.2
rmt-0.4b41-2.fc6
cpio-2.6-20
cdrecord-2.01-10
unzip-5.52-2.2.1
dump-0.4b41-2.fc6
tar-1.15.1-23.el5
file-roller-2.16.0-2.fc6
star-1.5a75-1
[root@mxl home]# rpm -e httpd 卸载我们以RPM格式安装的包
[root@mxl home]# rpm -qa httpd
[root@mxl home]#
从源码安装软件
源码就是软件的源代码没有进行编译的软件,源码安装一般需要以下几个步骤:
(1)       获取源代码可以使用wget命令进行下载
(2)       解压源代码,使用tar 命令
(3)       配置编译文件选项,命令格式./configure –prefix=要安装的路径
(4)       编译,使用make命令对软件进行编译
(5)       安装,使用make install进行安装
首先对tar的参数进行说明
-z gzip对存档解压
-jbzip2对存档解压
-x解压存档文件
-v详细显示处理的文件
-f指定存档文件或设备
说明一点如下载的是zip我们可以使用unzip命令进行解压
具体配置如下:
 
[root@mxl home]# tar -zxvf httpd-2.2.8.tar.gz
[root@mxl home]# ll
total 6060
drw-r-----  2 root  root     4096 Jun 13 00:36 aaa
drwxr-xr-x  2 root  root     4096 Jun 13 00:45 abc
----rwx---  1 root  root       93 Jun 12 18:19 a.txt
-rwxr-----  1 root  root        0 Jun 12 22:51 b.txt
-rw-r--r--  1 root  root        0 Jun 13 00:46 ccc
-rwxr-----  1 root  root        0 Jun 12 22:49 c.txt
-rw-r--r--  1 root  root       93 Jun 12 18:18 dir
drwxr-xr-x 11   501 games    4096 Jan 11 00:54 httpd-2.2.8  解压后的目录文件
-rw-r--r--  1 root  root  6125771 Jun 13 09:25 httpd-2.2.8.tar.gz
drwx------  3 nkmxl nkmxl    4096 Jun 12 16:58 nkmxl
 
[root@mxl home]# cd httpd-2.2.8
[root@mxl httpd-2.2.8]#
[root@mxl httpd-2.2.8]# ./configure --prefix=/etc/apache
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
 
Configuring Apache Portable Runtime library ...
 
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
[root@mxl httpd-2.2.8]#make 对软件进行编译
make[2]: Leaving directory `/home/httpd-2.2.8/server'
make[1]: Leaving directory `/home/httpd-2.2.8/server'
Making all in modules
make[1]: Entering directory `/home/httpd-2.2.8/modules'
Making all in aaa
make[2]: Entering directory `/home/httpd-2.2.8/modules/aaa'
make[3]: Entering directory `/home/httpd-2.2.8/modules/aaa'
 
[root@mxl httpd-2.2.8]# make install 进行安装
[root@mxl etc]# cd apache  查看下面安装成功
[root@mxl apache]# ls
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
下面是查看某些程序使用了那些库文件
库文件又分为:静态、动态、共享函数库
如:[root@mxl /]# ldd /bin/ls
        linux-gate.so.1 =>  (0x009b3000)
        librt.so.1 => /lib/i686/nosegneg/librt.so.1 (0x428f7000)
        libacl.so.1 => /lib/libacl.so.1 (0x42a79000)
        libselinux.so.1 => /lib/libselinux.so.1 (0x42a1b000)
        libc.so.6 => /lib/i686/nosegneg/libc.so.6 (0x423cc000)
        libpthread.so.0 => /lib/i686/nosegneg/libpthread.so.0 (0x4253d000)
        /lib/ld-linux.so.2 (0x423aa000)
        libattr.so.1 => /lib/libattr.so.1 (0x42a72000)
        libdl.so.2 => /lib/libdl.so.2 (0x42537000)
        libsepol.so.1 => /lib/libsepol.so.1 (0x429d3000)
对文件或目录进行压缩
[root@mxl home]# tar -cf abc.tar a.txt对一个文件进行压缩
[root@mxl home]# ls
abc.tar  a.txt  dir1  dir2  mxl
[root@mxl home]# tar -tf abc.tar
a.       txt
[root@mxl home]# ll
total 28
-rw-r--r-- 1 root root   20 Nov 14 22:02 a.txt
drwxr-xr-x 2 root root 4096 Nov 14 21:47 dir1
-rw-r--r-- 1 root root    0 Nov 14 21:51 dir2
drwx------ 3 mxl  mxl  4096 Nov 13 22:58 mxl
 
[root@mxl home]# tar -cf ccc.tar.gz a.txt dir1 mxl dir2  /home下的这些文件目录进行压缩
[root@mxl home]# ll
total 68
-rw-r--r-- 1 root root    20 Nov 14 22:02 a.txt
-rw-r--r-- 1 root root 20480 Nov 15 02:57 ccc.tar.gz
-rw-r--r-- 1 root root 10240 Nov 15 02:57 ddd.tar.gz
drwxr-xr-x 2 root root  4096 Nov 14 21:47 dir1
-rw-r--r-- 1 root root     0 Nov 14 21:51 dir2
drwx------ 3 mxl  mxl   4096 Nov 13 22:58 mxl
[root@mxl home]# tar -tf ccc.tar.gz 查看刚压缩的内容
a.txt
dir1/
mxl/
mxl/.kde/
mxl/.kde/Autostart/
mxl/.kde/Autostart/.directory
mxl/.bash_logout
mxl/.bashrc
mxl/.zshrc
mxl/.emacs
mxl/.bash_profile
dir2