linux程序包管理

linux程序包管理:

         API:applicationprogramming interface

                   posix:protable os

                   程序源代码-->预处理-->编译-->汇编-->链接

                            静态编译:

                            共享编译:.so

         ABI:applicationbinary interface

                   windows与linux不兼容

                   库级别的虚拟化:

                            linux:wine

                            windows:cywin

                            系统级开发

                                     c

                                     c++

                            应用级开发

                                     java

                                     python

                                     php

                            二进制应用程序的组成部分:

                                     二进制文件、库文件、配置文件、帮助文件

                            程序包管理器:

                                     debian:deb,dpt

                                     redhat:rpm

                                               rpm:redhatpackage manager

                                                        rpmis package manager

                            Gentoo

                            Archlinux

         源代码:name-version.tar.gz

                   version:major.minor.release

         rmp包命名方式:

                   name-verison-aech.rpm

                            version:major.minor.release

                            arch:release.arch

                                     zlib.1.2.7-13.e17.i86.rpm

                            常见的arch:

                                     x86:i386,i486,i586,i686

                                     x86_64:x64,x86_64,amd64

                                     powerpc:ppc

                                     跟平台无关:noarch

         testapp:拆包

                   testapp-version-arch.rpm:主包

                   testapp-devel-version-arch.rpm:支包

                   testapp-testing-version-arch.rpm

                   包之间存在依赖关系

                            x,y,z

                   yum:rpm包管理器的前端工具

                   apt-get:deb包管理器前端工具

                   zipper:suse上的rpm前端管理工具

                   dnf:fefora 22+rpm包管理器前端管理工具

                   查看二进制程序所依赖的库文件:

                            ldd/path/to/binary_file

                   管理及查看本机装载的库文件:

                            ldconfig

                            /sbin/ldconfig–p:显示本机已经缓存的所有可用库文件及文件路径映射关系

缓存文件:/etc/ls.so.cache

                   程序包管理:

    功能:将编译好的应用程序的各组成文件打包成一个或几个程序包文件,从而方便快捷的实现程序包的安装、卸载、查询、升     级、校验等工作

        1. 程序的组成清单(每个包独有)

            文件名单

            安装或卸载时运行的脚本

        2. 数据库(共有)

            程序包名称及版本

            依赖关系

            功能说明

            安装生成的个文件的文件路径及校验信息

管理程序包的方式:

                   使用包管理器:rpm

                  使用前端管理工具:yum,dnf

         获取程序包的途径:

            (1)系统发版的光盘或官方的服务器

                centos镜像:

                    http://mirrors.aliyun.com

                    http://mirrors.sihu.com

                    http://mirrors.163.com

            (2)项目官方站点

            (3)第三方组织

                    fedora-epel

                                     搜索引擎:

                                     http://pkgs.org

                                     http://rpmfind.net

                                     http://rpm.pbone.net

            (4)自己制作

                    来源合法性:

                程序包的完整性:

 

                centos系统上rpm命令管理程序包:

                    安装、卸载、升级、查询、校验、数据库维护

                    安装:

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

                           -v:verbose

                           -vv:

                           -h:以#显示程序包管理执行进度,每个#表示2%的进度       

                         rpm –ivh 程序包

                            [install -option]

                                --test:测试安装,但不真正执行安装过程,dryrun模式

                                --nodeps:忽略依赖关系

                                --replacepkgs:重新安装

                                --nosignature:不检查来源合法性

                                --noscripts:不执行程序包脚本片段

                             %pre:安装前脚本:--nopre

                             %post:安装后脚本  --nopost

                             %preun:卸载前脚本  --nopreun

                             %postun:卸载后脚本  --nopostun

升级:      

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

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

         upgrage:安装有旧版程序包,则升级,如果不存在旧版程序包,则安装

         freshen:安装有旧版程序包,则升级,如果不存在旧版程序包,则不执行任何操作

         rpm –Uvh package_file

         rpm –Fvh package_file

         --oldpackage:降级

         --force:强制升级

         注意:(1)不要对内核做升级操作,linux支持多内核版本共存,因此,对直接安装新              版本内核

         (2)如果原程序包的配置文件安装后曾被修改,新版本的提供的同一个配置文件并                不会直接覆盖老版本的配置               文件,而把新版本的文件重命名(filename.rpmnew)后保             留

            查询:

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

                    [select-option]

                 -a:所有包

                 -f:查看指定的文件由那个程序包生成

                 --whatprovidesCAPABILITY:查询指定的CAPABILITY由哪个包所提供。

                --whatrequires CAPABILITY:查询指定的CAPABILITY被哪个包所依赖

                   [query-option]

                            --changelog:查询rpm包的changlog

                            -c:查询程序的配置文件

                            -d:查询程序的文档

                            -i:information

                            -l:查看指定的程序包安装后生成的所有文件

                            -scripts:程序包自带的脚本片段

                            -R:查询指定的程序包所以来的CAPABILITY

                --provides:列出指定程序包所提供的CAPABILITY

                 用法:

                   -qi package,-qf file,-qc package,-ql package,-qd package

                   -qpi package_file,-qpl package_file,…

    卸载:

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

       gers] [--test]PACKAGE_NAME ...

    校验:

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

                   S file Sizediffers

       M Mode differs(includes permissions and file type)

       5 digest (formerly MD5sum) differs

       D Device major/minornumber mismatch

       L readLink(2) pathmismatch

       U User ownershipdiffers

       G Group ownershipdiffers

       T mTime differs

       P caPabilities differ

包来源合法性验证及完整性验证:

         完整性验证

         公钥加密:对称加密:加密、解密使用同一秘钥

         非对称加密:秘钥时成对的,

                   public key:公钥

                   secret key:私钥

                   导入所需要的公钥:

                            rpm –import/path/from/gpg-pubkey-file

                            centos 7发行版光盘提供的秘钥文件:RPM-GPG-KEY-CENTOS-7

         数据库重建:

                   rpm {--initdb | --rebuilddb}

                            initdb:初始化

                                     如果事先不存在数据库,则新建之,否则,不执行任何操作

                            rebuilddb:重建

                                     无论当前是否存在,直接重新创建数据库        

linux程序包管理(2)

         centos:yum,dnf

         URL:ftp://172.16.0.1/pub/

         YUM:yellow dog,yellowdogupdate modifier

         yumrespository:yum repo

                  存储了众多rpm包,以及包的相关的元数据文件(放置在特定目录下,repodata):

                   文件服务器:

                            ftp://

                            http://

                            nfs://

                            file:///

         yum客户端:

                   配置文件:

                            /etc/yum.conf:为所有仓库提供公共配置

                            /etc/yum.repos..d/*.repo:为仓库的指向提供配置

                   仓库的定义:

                   [respositoryID]

                   name=somename for this respository

                   baseurl=url://path/to/respository/

                   enabled={1|0}

                   gpgcheck={1|0}

                   gpgkey=URL

                   enablegroups={1|0}

                   failovermethod={roundrobin|priority}

                            默认为:roundrobin,意为随机值

                   cost=

                            默认值为1000

yum命令的用法:

         yum[options] [command] [package ...]

         * install package1 [package2] [...]

        * update [package1] [package2] [...]

        * update-to [package1] [package2] [...]

        * update-minimal [package1] [package2][...]

        * check-update

        * upgrade [package1] [package2] [...]

        * upgrade-to [package1] [package2][...]

        * distribution-synchronization[package1] [package2] [...]

        * remove | erase package1 [package2][...]

        * autoremove [package1] [...]

        * list [...]

        * info [...]

        * provides | whatprovides feature1[feature2] [...]

        * clean [ packages | metadata |expire-cache | rpmdb | plugins | all ]

        * makecache [fast]

        * groups [...]

        * search string1 [string2] [...]

        * shell [filename]

        * resolvedep dep1 [dep2] [...]

           (maintained for legacy reasons only- use repoquery or yum provides)

        * localinstall rpmfile1 [rpmfile2][...]

           (maintained for legacy reasons only- use install)

        * localupdate rpmfile1 [rpmfile2] [...]

           (maintained for legacy reasons only- use update)

        * reinstall package1 [package2] [...]

        * downgrade package1 [package2] [...]

        * deplist package1 [package2] [...]

        * repolist [all|enabled|disabled]

        * repoinfo [all|enabled|disabled]

         *  repository-packages     

      stall|remove-or-distribution-synchronization> [package2] [...]

         * version [ all | installed | available | group-* | nogroups* | grouplist|

       groupinfo ]

            *      history      [info|list|packages-list|packages-info|summary|addon-

       info|redo|undo|rollback|new|sync|stats]

        * load-transaction [txfile]

         * updateinfo  [summary  |  list| info | remove-pkgs-ts | exclude-updates |

       exclude-all | check-running-kernel]

        * fssnapshot [summary | list |have-space | create | delete]

        * fs [filters | refilter |refilter-cleanup | du]

        * check

        * help [command]

 

         显示仓库列表:

                   repolist [all|enabled|disabled]

         显示程序包:

                   list

                            # yum list [all |glob_exp1] [glob_exp2] [...]

                            #yum list available [glob_exp1] [...]

                                …

         安装程序包:

                   install packages

                   reinstallpackages:重新安装

         升级程序包:

                   update packages

         查看程序包:

                   info […]

         查看指定的特性(可以是某文件)是由哪个程序包所提供:

                   provides | whatprovidesfeature1 [feature2] […]
                   yum provides /bin/ls

        

                   清理本地缓存:

                            yum clean packages

                            …

                   构建缓存:

                            makecache

                   搜索:

                            search string1[string2] […]

                            以指定的关键字搜索程序包名及summary信息:

                  查看指定包所依赖的capabilities

                            deplist package1[package2] […]

                   查看yum事务历史:

                            yum history

                            history [info|list|pacages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]

                   安装及升级本地程序包:

                   包组管理的相关命令:

                            yum grouplist

                            groupinstall group1[group2] […]

                            groupupdate group1[group2] […]

                            grouplist [hidden][groupwildcare] […]

                            groupremove group1[group2] […]

                            groupinfo group1 […]

                           

         如何使用光盘当做本地yum仓库:

        (1)      挂载光盘至某目录,例如/media/cdrom

                #mount –r –t iso9660/dev/cdrom /media/cdrom

        (2)      创建配置文件

                [centos7]

                name=

                baseurl=

                gpgcheck=

                enabled=

         yum的命令行选项:

                 --nogpgcheck:禁止进行gpgcheck

                 -y:自动回答为yes

                 -q:静默模式

                 --disablerepo=repoidglob,临时禁止此处指定的repo

                 --enablerepo=repoidglog:临时启用此处指定的repo

                 --noplugins:禁用插件

         yum的repo配置文件中的可用的变量:

                  $releaserver:当前os的发行版的主版本号

                  $arch:平台

                  $baserch:基础平台

                  $YUM0-$YUM9

                  http://mirrors.mage.com/centos/$releaserver/$baserch

 

                           

 


你可能感兴趣的:(linux)