码迷,mamicode.com
首页 > 系统相关 > 详细

Linux运维练习--程序员包管理rpm与yum

时间:2015-09-15 14:59:50      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:rpm/yum

程序包管理:

包管理器:作用是打包以及包管理(安装、升级、卸载、查询及校验)

                 对于不同linux发行版本有不同的包管理器,主要有

                 deb:debian

                 rpm:redhat package Manager,rpm成为事实上包管理器的标准

                程序包的组成部分:

                          二进制程序:通常存放在以下文件,/bin, /sbin,/ /usr/bin, /usr/sbin,
                          库文件:通常存放在以下文件,/lib64, /usr/lib64(64位系统)
                          配置文件:/etc
                          帮助文件:manual, info,

                 包管理器:提供在操作系统中安装,升级,卸载需要的软件的方法,并提供对系统中所有

                                     软件状态信息的查询

                 rpm包:

                            打包工具:rpmbuild:specs文件

                            分包机制:根据功能分包:

                                                如:test-Version.tar.gz

                                                    核心包:test-Version

                                                        支包:testapp-devel-Version

                                                   Version:主版本号.此版本号.发行号

                 rpm包的命名机制:
                                   name-VERSION-RELEASE.ARCH.rpm

                                   RELEASE.ARCH: rpm release和适用的平台和架构,如

                                   bash-4.2.4-1.el7.x86_64.rpm表示适用于redhat enterprise linux 7 64位系统

                 rpm数据库:对于redhat和CentOS一般在:/var/lib/rpm,如图(CentOS 64bit):

               技术分享

                获取rpm包的途径:1、发行版提供的程序包(光盘)

                                                    挂载光盘文件,包文件在Packages下面
                                              2、Fedora-EPEL
                                              3、项目的官方站点
                                              4、搜索引擎
                                                         http://rpmfind.net
                                                         http://rpm.pbone.net
                                                         http://pkgs.org

 

              rpm命令实现程序包管理:
                       安装:
                                rpm {-i|--install} [install-options] PACKAGE_FILE ...
                                        -i:     -v:显示详细过程, -h:”#“号显示安装进度

                               技术分享

                                          -q 查看某程序包是否安装

                                每个rpm包都提供一个或多个capabilities

                                --nodeps:忽略依赖关系安装
                                --replacepkgs:重装程序包

                      升级:
                               rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...
                               rpm {-F|--freshen} [install-options] PACKAGE_FILE ... 

                               -Uvh: 如果有旧版程序包,则升级之;如果没有,则安装之;
                               -Fvh: 如果有旧版程序包,则升级之;如果没有,则不安装;

                               --nodeps
                               --oldpackage:降级;
                               --force:强制升级,不管依赖于老程序包的程序             

                      卸载:
        rpm {-e|--erase} [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ... 

                      如果有程序依赖于被卸载程序,则卸载会有警告,--nodeps也可忽略依赖

                      查询:
                               rpm {-q|--query} [select-options] [query-options]

                               查询选项:                                            

                                     -qa: 查询本机已经安装的所有程序包;
                                    -qf: /PATH/TO/SOMEFILE: 查询此处的文件由哪个程序包安装生成;

                                    -qc: 查询指定程序包安装生成的配置文件
                                    -qd: 查询指定的程序包安装生成的文档
                                     -qi: 查询指定的程序包的相关信息;
                                     -ql: 查询程序包安装生成的所有文件的列表;
                                     -q:--scripts:查询程序包相关的脚本:                                   

                                              preinstall: 安装前脚本
                                               postinstall:安装后脚本
                                               preuninstall: 卸载前脚本
                                                 postuninstall: 卸载后脚本

                                     -p: 查询针对是未安装的程序包文件;查询本地存在而没有安

                                         装的rpm包信息              

                               技术分享

                     校验:
                               rpm {-V|--verify} [select-options] [verify-options]
                                                 S file Size differs
                                         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


                  包校验:
                        来源合法性验正:非对称加密
                             完整性验正:单向加密

                             导入密钥:rpm --import /PATH/TO/KEY_FILE
                              校验:rpm -K /PATH/TO/RPM_FILE,文件校验后就不会存在来源警告信息

 技术分享

YUM:Yellowdog Updater Modified(RPM包的前端管理工具)

                yum外在仓库的元数据(包括仓库程序包的数量、程序包名以及依赖关系等)下载到本地缓存

            然后,在安装某个程序包是,在本地缓存即可查询包所在的位置和依赖关系,下载最新版本和依

            赖包到本地缓存进行安装。本地会定期将本地缓存的仓库元数据与外在仓库的元数据进行校验码

            比对,如果发现外在仓库校验码更新,则更新本地仓库元数据

     yum repositories:
                    文件服务器(常见用法):
                                                         ftp://hostname/PATH/TO/REPO
                                                         http://hostname/PATH/TO/REPO
                                                         file:///PATH/TO/REPO

      yum程序的配置文件:
                     /etc/yum.conf: 定义全局配置:对所有仓库都适用的配置
                     /etc/yum.repos.d/*.repo:通常用于一个或一组功能相近或相关的仓库,如base仓库 

                       定义一个仓库指向:
                              [REPO_ID]  
                              name=
                              baseurl=    //如有多个URL则随机选择一个,但是必须保证每个仓库的元数据一致,建议只用一个URL
                     # mirrorlist=SCHEME://HOSTNAME/PATH/TO/MIRROR_LIST_FILE
                     enabled={1|0}  //1表示启用
                     gpgcheck={1|0} //1表示需要进行gpgcheck
                    gpgkey= 
                    cost=   //当有多个仓库时需要选择最优的仓库,仓库的开销,数值越低优先级越高

              技术分享

             定义仓库指向可用变量:
                           $releasever: 引用当前系统的主版本号;
                             $basearch: 当前系统的基本架构;
                                               i386, i486, i586, i686: i386

     

        yum命令:
               yum [options] [command] [package ...]
               安装:install

               本地安装:localinstall,也可自动解决依赖问题
               卸载:remove
               升级:update
               查询: info

        技术分享

            search KEYWORD
            list all|installed|availiable,列出所有的|已经安装的|可以获得的包,支持通配符
            provides /PATH/TO/SOMEFILE: 查询指定文件由哪个包安装生成

技术分享 

          重新安装:reinstall
          降级:downgrade
         清理缓存:clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]

                          如仓库元数据,rpm
           生动生成缓存:makecache

           包组:
                         grouplist
                         groupinfo "GRP_NAME"
                         groupinstall "GRP_NAME"
                         groupremove "GRP_NAME"

                仓库:
                        repolist [all|enabled|disabled]
                        repoinfo [all|enabled|disabled]
       如何使用光盘当做本地仓库:
                挂载光盘至某目录
                定义仓库,使用file:///指明其访问路径;

                如:将本地光盘当做默认yum源,更改cost值为100,base-repo cost 默认为1000

技术分享

技术分享

               创建本地仓库:自己根据需求创建仓库,但是需要自己解决依赖关系
                       yum install createrepo

                       createrepo /PATH/TO/RPMFILES/

                              

 

 

 

                          

                                                                               

本文出自 “^狐狸尾巴$” 博客,请务必保留此出处http://nikanke.blog.51cto.com/986378/1694838

Linux运维练习--程序员包管理rpm与yum

标签:rpm/yum

原文地址:http://nikanke.blog.51cto.com/986378/1694838

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!