程序包管理:

       内核功能:进程管理,内存管理,网络协议栈,驱动程序

       应用程序:

(1)包管理器:打包,包管理(安装、升级、卸载、查询及校检)

           种类主要分为两种:deb和rpm

          1:程序包的组成部分

                二进制程序:可执行的文件  文件在/bin /sbin /usr/bin /usr/sbin 

                  库文件:程序运行依赖于库文件,也可实现供其他程序调用等功能 ,文件通常在/lib64  /usr/lib64

                  配置文件:纯文本文件,定义程序的特性  文件通常在 /etc

                 帮助文件:man手册、info文件 等

          2:包管理器的功能:

                 制作程序包;安装程序包;卸载程序包;升级程序包;查询程序包;校检程序包(主要检测来源的合法性和完整性)

          3:rpm包

             命令格式:

                        源程序的命令格式:testapp-version.tar.gz

                            例:base-4.2.4.tar.gz

                         rpm包的命名格式:name-version-release.arch.rpm

                            例:  bash-4.2.4-1.el7.x86_64.rpm

                      注:其中version包含:主版本号major,次版本号minor,发行号release安装在哪种平台上面arch

             分包机制:

                    rpm包可以分为两类包:核心包和支包。一个程序可能很多功能,但是其中可能有不少功能使用不上,

                           例:核心包testapp-version支包:testapp-devel-version

                    其他功能:包和包之间存在依赖的关系;rpm数据库在/var/lib/rpm/中

       4:如何获取rpm包

               1:发行版提供的程序包

                   http://mirrors.163.com

               2:项目的官方站点

               3:搜索引擎

                    http://rpmfind.net

               4:EPEL      

                (CentOS识别光盘用的设备文件:/dev/cdrom)

[root@localhost mycdrom]# ls Packages | wc
   3205    3205  124269
[root@localhost mycdrom]#

 (2)rpm程序管理包的使用

         1:安装

              格式:rpm {-i|--install} [install-options] PACKAGE_FILE ... 

             常用选项:-ivh   安装并显示过程

                              --nodeps  忽略依赖关系安装  (可能导致程序无法使用)

                             --replacepkgs:重新安装程序包

         例:

[root@localhost ~]# ll /tmp/mycdrom/
总用量 558
-r--r--r--. 2 root root     14 8月   5 05:25 CentOS_BuildTag
dr-xr-xr-x. 3 root root   2048 8月   5 05:40 EFI
-r--r--r--. 2 root root    212 11月 27 2013 EULA
-r--r--r--. 2 root root  18009 11月 27 2013 GPL
dr-xr-xr-x. 3 root root   2048 8月   5 05:50 p_w_picpaths
dr-xr-xr-x. 2 root root   2048 8月   5 05:40 isolinux
dr-xr-xr-x. 2 root root 528384 8月   5 05:48 Packages
-r--r--r--. 2 root root   1354 7月  25 20:37 RELEASE-NOTES-en-US.html
dr-xr-xr-x. 2 root root   4096 8月   5 05:50 repodata
-r--r--r--. 2 root root   1706 11月 27 2013 RPM-GPG-KEY-CentOS-6
-r--r--r--. 2 root root   1730 11月 27 2013 RPM-GPG-KEY-CentOS-Debug-6
-r--r--r--. 2 root root   1730 11月 27 2013 RPM-GPG-KEY-CentOS-Security-6
-r--r--r--. 2 root root   1734 11月 27 2013 RPM-GPG-KEY-CentOS-Testing-6
-r--r--r--. 1 root root   3380 8月   5 05:50 TRANS.TBL
[root@localhost ~]# rpm -ivh zsh-4.3.11-4.el6.centos.x86_64.rpm
error: open of zsh-4.3.11-4.el6.centos.x86_64.rpm failed: 没有那个文件或目录
[root@localhost ~]# cd /tmp/mycdrom/Packages/
[root@localhost Packages]# rpm -ivh zsh-4.3.11-4.el6.centos.x86_64.rpm
Preparing...                ########################################### [100%]
   1:zsh                    ########################################### [100%]
[root@localhost Packages]#
[root@localhost Packages]# rpm -ivh --test zsh-4.3.11-4.el6.centos.x86_64.rpm --replacepkgs
Preparing...                ########################################### [100%]
[root@localhost Packages]#

     2:升级

        格式:

       rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...

                如果有旧版程序包,则升级之;如果没有则安装之

              rpm {-F|--freshen} [install-options] PACKAGE_FILE ...

         如果有旧版程序包,则升级之,如果没有则不安装

                         命令选项:

                                 --nodeps  忽略依赖关系

                                 --oldpackage  降级

                                --force  强力升级

       3:卸载

                  rpm {-e|--erase} [--allmatches] [--nodeps] [--noscripts]

                      [--notriggers] [--test] PACKAGE_NAME ...

                     (卸载时,程序所依赖的程序会一同被卸载)

root@localhost ~]# rpm -q zsh
zsh-4.3.11-4.el6.centos.x86_64
[root@localhost ~]# rpm -e zsh-4.3.11-4.el6.centos.x86_64

[root@localhost ~]# 
[root@localhost ~]# rpm -q zsh
package zsh is not installed
[root@localhost ~]#


       4:查询

                   rpm {-q|--query} [select-options] [query-options]

                   命令选项:

                          -qa:查询本机所安装的所有程序包

                         -qf 【where】查询此处文件由哪个程序包安装生成

                         -qc:查询程序包安装成为的配置文件

                         -qd:查询程序包安装完成生产的文档

                          -ql:查询程序包安装所有文件的列表

                          -q --scripts:查询程序包相关的脚本:

                  preinstall: 安装前脚本

                  postinstall:安装后脚本

                  preuninstall: 卸载前脚本

                  postuninstall: 卸载后脚本

                          -p: 查询针对是未安装的程序包文件;

[root@localhost ~]# rpm -qa | wc -l
244
[root@localhost ~]# rpm -qc bash
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc
[root@localhost ~]# rpm -qd bash
/usr/share/doc/bash-4.1.2/COPYING
/usr/share/info/bash.info.gz
/usr/share/man/man1/..1.gz
/usr/share/man/man1/:.1.gz
/usr/share/man/man1/[.1.gz
/usr/share/man/man1/alias.1.gz
/usr/share/man/man1/bash.1.gz
/usr/share/man/man1/bashbug.1.gz
/usr/share/man/man1/bg.1.gz
/usr/share/man/man1/bind.1.gz
/usr/share/man/man1/break.1.gz
/usr/share/man/man1/builtin.1.gz
/usr/share/man/man1/builtins.1.gz
/usr/share/man/man1/caller.1.gz
/usr/share/man/man1/cd.1.gz
/usr/share/man/man1/command.1.gz
/usr/share/man/man1/compgen.1.gz
/usr/share/man/man1/complete.1.gz
/usr/share/man/man1/compopt.1.gz
/usr/share/man/man1/continue.1.gz
/usr/share/man/man1/declare.1.gz
/usr/share/man/man1/dirs.1.gz
/usr/share/man/man1/disown.1.gz
/usr/share/man/man1/enable.1.gz
/usr/share/man/man1/eval.1.gz
/usr/share/man/man1/exec.1.gz
/usr/share/man/man1/exit.1.gz
/usr/share/man/man1/export.1.gz
/usr/share/man/man1/fc.1.gz
/usr/share/man/man1/fg.1.gz
/usr/share/man/man1/getopts.1.gz
/usr/share/man/man1/hash.1.gz
/usr/share/man/man1/help.1.gz
/usr/share/man/man1/history.1.gz
/usr/share/man/man1/jobs.1.gz
/usr/share/man/man1/let.1.gz
/usr/share/man/man1/local.1.gz
/usr/share/man/man1/logout.1.gz
/usr/share/man/man1/mapfile.1.gz
/usr/share/man/man1/popd.1.gz
/usr/share/man/man1/pushd.1.gz
/usr/share/man/man1/read.1.gz
/usr/share/man/man1/readonly.1.gz
/usr/share/man/man1/return.1.gz
/usr/share/man/man1/set.1.gz
/usr/share/man/man1/sh.1.gz
/usr/share/man/man1/shift.1.gz
/usr/share/man/man1/shopt.1.gz
/usr/share/man/man1/source.1.gz
/usr/share/man/man1/suspend.1.gz
/usr/share/man/man1/times.1.gz
/usr/share/man/man1/trap.1.gz
/usr/share/man/man1/type.1.gz
/usr/share/man/man1/typeset.1.gz
/usr/share/man/man1/ulimit.1.gz
/usr/share/man/man1/umask.1.gz
/usr/share/man/man1/unalias.1.gz
/usr/share/man/man1/unset.1.gz
/usr/share/man/man1/wait.1.gz
[root@localhost ~]# rpm -qi bash
Name        : bash                         Relocations: (not relocatable)
Version     : 4.1.2                             Vendor: CentOS
Release     : 33.el6                        Build Date: 2015年07月24日 星期五 02时58分07秒
Install Date: 2015年08月20日 星期四 17时29分50秒      Build Host: c6b8.bsys.dev.centos.org
Group       : System Environment/Shells     Source RPM: bash-4.1.2-33.el6.src.rpm
Size        : 3142151                          License: GPLv3+
Signature   : RSA/SHA1, 2015年07月25日 星期六 04时37分16秒, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
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@localhost ~]#


       5:校验

                 rpm {-V|--verify} [select-options] [verify-options]         

            M Mode differs (includes permissions and file type)

        5 digest (formerly MD5 sum) differs

        D Device major/minor number mismatch

        L readLink(2) path mismatch

        U User ownership differs

        G Group ownership differs

        T mTime differs

        P caPabilities differ

      6:检验包来源的合法性和完整性

                包的完整性:单向加密

                包的合法性:非对称加密

                    导入密钥:rpm --import /PATH/TO/KEY_FILE

    校验:rpm -K /PATH/TO/RPM_FILE

  (3)程序包的前段管理器:yum

         1 :文件服务器,通过yum所支持的文件共享机制,将个rpm包通过文件服务共享

               文件服务器: ftp://hostname/PATH/TO/REPO

      http://hostname/PATH/TO/REPO

       file:///PATH/TO/REPO

               repository:仓库

        2:yum程序的配置文件

                /etc/yum.conf

              定义全局配置,对所有仓库适用的配置

               /etc/yum.repos.d/*.repo

              一个文件通常用于一个或一组功能相近相关的仓库

              定义一个仓库指向

                   【repo_ID】

                    name=仓库所描述的信息

                    baseurl=仓库的访问路径

                    enabled=1|0

                    gpgcheck=1|0    

            gpgkey=公钥文件

             cost=定义仓库的开销(作用次序)


[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
总用量 24
-rw-r--r--. 1 root root 1991 8月   4 00:13 CentOS-Base.repo
-rw-r--r--. 1 root root  647 8月   4 00:13 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  289 8月   4 00:13 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 8月   4 00:13 CentOS-Media.repo
-rw-r--r--. 1 root root 6259 8月   4 00:13 CentOS-Vault.repo

[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
        file:///media/cdrom/
        file:///media/cdrecorder/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


              定义仓库可使用变量:

                       $releasever:引用当前系统的主版本号

                       $basearch:当前系统的基本架构

                                      i386, i486, i586, i686: i386

                      例:http://mirrors.magedu.com/CentOS/$releasever/os/$basearch                                                                                                                                                 

                     

      3: yum命令的使用

              格式:  yum [options] [command] [package ...]

                   安装:install

                   卸载:remove

                   升级:update

                   查询:info  ;  search keyword  ;list all   ;provides where   查询指定文件由哪个安装包安装

                   重新安装:reinstall

                   降级:downgrade

                   清理缓存:clean all

                   生成缓存:makecache

                  包组管理:

                            grouplist 列出所有的包组

                            groupinfo  显示包组信息

                            groupinstall  安装指定包组

                             groupmove 卸载包组 

[root@localhost yum.repos.d]# yum install zsh
已加载插件:fastestmirror
设置安装进程
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.pubyun.com
 * updates: mirrors.aliyun.com
解决依赖关系
--> 执行事务检查
---> Package zsh.x86_64 0:4.3.11-4.el6.centos will be 安装
--> 完成依赖关系计算

依赖关系解决

===================================================================================================
 软件包            架构                 版本                              仓库                大小
===================================================================================================
正在安装:
 zsh               x86_64               4.3.11-4.el6.centos               base               2.2 M

事务概要
===================================================================================================
Install       1 Package(s)

总下载量:2.2 M
Installed size: 5.0 M
确定吗?[y/N]:y
下载软件包:
zsh-4.3.11-4.el6.centos.x86_64.rpm                                          | 2.2 MB     00:02     
运行 rpm_check_debug 
执行事务测试
事务测试成功
执行事务
  正在安装   : zsh-4.3.11-4.el6.centos.x86_64                                                  1/1 
  Verifying  : zsh-4.3.11-4.el6.centos.x86_64                                                  1/1 

已安装:
  zsh.x86_64 0:4.3.11-4.el6.centos                                                                 

完毕!
[root@localhost yum.repos.d]# yum list zsh*
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.yun-idc.com
 * updates: mirrors.aliyun.com
已安装的软件包
zsh.x86_64                                   4.3.11-4.el6.centos                              @base
可安装的软件包
zsh-html.x86_64                              4.3.11-4.el6.centos                              base 
[root@localhost yum.repos.d]#


        光盘当做本地仓库

     

[root@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.pubyun.com
 * updates: mirrors.aliyun.com
仓库标识                                  仓库名称                                            状态
base                                      CentOS-6 - Base                                     6,575
extras                                    CentOS-6 - Extras                                      35
updates                                   CentOS-6 - Updates                                    298
repolist: 6,908
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.backup
[root@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
repolist: 0
[root@localhost yum.repos.d]# ll /tmp/mycdrom/
总用量 558
-r--r--r--. 2 root root     14 8月   5 05:25 CentOS_BuildTag
dr-xr-xr-x. 3 root root   2048 8月   5 05:40 EFI
-r--r--r--. 2 root root    212 11月 27 2013 EULA
-r--r--r--. 2 root root  18009 11月 27 2013 GPL
dr-xr-xr-x. 3 root root   2048 8月   5 05:50 p_w_picpaths
dr-xr-xr-x. 2 root root   2048 8月   5 05:40 isolinux
dr-xr-xr-x. 2 root root 528384 8月   5 05:48 Packages
-r--r--r--. 2 root root   1354 7月  25 20:37 RELEASE-NOTES-en-US.html
dr-xr-xr-x. 2 root root   4096 8月   5 05:50 repodata
-r--r--r--. 2 root root   1706 11月 27 2013 RPM-GPG-KEY-CentOS-6
-r--r--r--. 2 root root   1730 11月 27 2013 RPM-GPG-KEY-CentOS-Debug-6
-r--r--r--. 2 root root   1730 11月 27 2013 RPM-GPG-KEY-CentOS-Security-6
-r--r--r--. 2 root root   1734 11月 27 2013 RPM-GPG-KEY-CentOS-Testing-6
-r--r--r--. 1 root root   3380 8月   5 05:50 TRANS.TBL
[root@localhost yum.repos.d]# vim
[root@localhost yum.repos.d]# vim local-iso-repo