Linux下软件包安装(rpm,yum)

Linux下软件包安装(rpm,yum,源代码)

1)    Rpm包管理安装

2)    Yum包程序管理器

3)    本地Yum仓库建制

=======================================

1)    Rpm包管理安装

    a、RPM包的管理用途

        1、可以安装,删除,升级和管理安装软件

        2、检查安装包的依赖关系

        3、管理RPM包安装的文件(二进制程序,帮助文件,配置文件)

        4、校验来源合法性和软件包完整性

        5、RPM以数据库方式存储RPM包安装信息(RPM包数据库位置:/var/lib/rpm)

    [root@ns1 ~]# ll /var/lib/rpm/                            #当如下数据库出现问题很多RPM包查询命令会出现问题
    total 29968
    -rw-r--r--. 1 root root  1536000 Jun  6 00:47 Basenames    
    -rw-r--r--. 1 root root    12288 Jun  5 12:00 Conflictname
    -rw-r--r--  1 root root    24576 Jun  6 00:47 __db.001
    -rw-r--r--  1 root root   229376 Jun  6 00:47 __db.002
    -rw-r--r--  1 root root  1318912 Jun  6 00:47 __db.003
    -rw-r--r--  1 root root   753664 Jun  6 00:47 __db.004
    -rw-r--r--. 1 root root   323584 Jun  6 00:47 Dirnames
    -rw-r--r--. 1 root root  2490368 Jun  6 00:47 Filedigests
    -rw-r--r--. 1 root root    12288 Jun  6 00:47 Group
    -rw-r--r--. 1 root root    12288 Jun  6 00:47 Installtid
    -rw-r--r--. 1 root root    24576 Jun  6 00:47 Name
    -rw-r--r--. 1 root root    12288 Jun  6 00:47 Obsoletename
    -rw-r--r--. 1 root root 23293952 Jun  6 00:47 Packages
    -rw-r--r--. 1 root root  1343488 Jun  6 00:47 Providename
    -rw-r--r--. 1 root root   614400 Jun  6 00:47 Provideversion
    -rw-r--r--. 1 root root    12288 Feb 21 21:05 Pubkeys
    -rw-r--r--. 1 root root   196608 Jun  6 00:47 Requirename
    -rw-r--r--. 1 root root    94208 Jun  6 00:47 Requireversion
    -rw-r--r--. 1 root root    45056 Jun  6 00:47 Sha1header
    -rw-r--r--. 1 root root    24576 Jun  6 00:47 Sigmd5
    -rw-r--r--. 1 root root    12288 Jun  4 08:39 Triggername
    [root@ns1 ~]# 
    Database options:
      --initdb                         initialize database        #    RPM包数据库初始化
      --rebuilddb                      rebuild database inverted lists from installed package headers        #RPM包数据库重建

    b、RPM包简单使用

        1、查询单个软件包:

[root@ns1 ~]# rpm -q httpd
httpd-2.2.15-45.el6.centos.x86_64
[root@ns1 ~]#

        2、查询所有软件包

[root@ns1 ~]# rpm -qa | grep httpd        #显示太多通过管道送给grep过滤
httpd-2.2.15-45.el6.centos.x86_64
httpd-tools-2.2.15-45.el6.centos.x86_64
[root@ns1 ~]#

        3、查询安装包简要信息

[root@ns1 ~]# rpm -qi httpd
Name        : httpd                        Relocations: (not relocatable)
Version     : 2.2.15                            Vendor: CentOS
Release     : 45.el6.centos                 Build Date: Fri 24 Jul 2015 07:53:33 PM CST
Install Date: Sun 21 Feb 2016 09:13:02 PM CST      Build Host: c6b9.bsys.dev.centos.org
Group       : System Environment/Daemons    Source RPM: httpd-2.2.15-45.el6.centos.src.rpm
Size        : 3090869                          License: ASL 2.0
Signature   : RSA/SHA1, Sat 25 Jul 2015 04:42:58 AM CST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.
[root@ns1 ~]#

        4、查询安装包安装的文件目录

[root@ns1 ~]# rpm -ql httpd | grep "^/etc"
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/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/htcacheclean
/etc/rc.d/init.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd
[root@ns1 ~]#

        5、查询某一个文件是由那个安装程序所创建

[root@ns1 ~]# rpm -qf `which ss`        #ss程序就是由iproute这个程序包安装的
iproute-2.6.32-45.el6.x86_64
[root@ns1 ~]#

        6、查询包安装之后生成的帮助文档

[root@ns1 ~]# rpm -qd httpd

        7、查询包安装之后生成的配置文件

[root@ns1 ~]# rpm -qc httpd

        8、查询包安装的脚本

[root@ns1 ~]# rpm -q --scripts httpd
    #安装脚本分类
    #preinstall:安装前脚本
    #postinstall:安装后脚本
    #preuninstall:卸载前脚本
    #posttrans:卸载后脚本

        9、查询包未安装之前的信息

[root@ns1 ~]# rpm -qpl httpd-2.2.15-45.el6.centos.x86_64.rpm        #在RPM包未安装之前,可以参考已安装RPM包的查询命令,加入p参数,查看RPM包相同信息
[root@ns1 ~]# rpm -qpi httpd-2.2.15-45.el6.centos.x86_64.rpm

        10、RPM包升级

 rpm -U    :升级或安装    #常用组合    rpm -Uvh
 rpm -F    :升级        #常用组合    rpm -Fvh
 --nodeps    #忽略包的依赖关系
 --force        #强行安装

        11、RPM包安装

    rpm -i    #常用组合    rpm -ivh

        12、RPM包卸载

    rpm -e    #卸载RPM包

2)    Yum包程序管理器(Yellowdog Update Modifier)

        Yum是一个非常便捷的程序包管理器,解决包的依赖关系,工作方式通过文件服务器共享RPM包,并且对RPM包建立数据库方式管理,是基于C/S架构,客户端只需要简单配置,即可链接到YUM仓库服务,安装升级卸载RPM程序包。

        1、repository:(YUM仓库)

                a、包含RPM程序包

                b、解决依赖关系

                c、程序包安装后所能够生成文件列表等元数据信息

                d、RPM包组

                e、支持:ftp,http,file,nfs等协议

        2、yum客户端

                a、通过配置文件指定各个可用的YUM仓库

                b、缓存YUM仓库里的元数据信息到本地,并分析元数据,检查可能包含的依赖关系

                c、执行具体操作(安装,升级,卸载,查询等)

        3、yum客户端使用

check          Check for problems in the rpmdb
check-update   Check for available package updates
clean          Remove cached data    #清空缓存信息
deplist        List a package's dependencies
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade      downgrade a package
erase          Remove a package or packages from your system    #卸载安装包
groupinfo      Display details about a package group    #查看包组信息
groupinstall   Install the packages in a group on your system    #安装包组
grouplist      List available package groups    #查看包组列表信息
groupremove    Remove the packages in a group from your system    #卸载包组
help           Display a helpful usage message
history        Display, or use, the transaction history
info           Display details about a package or group of packages    #查看包或者包组的信息
install        Install a package or packages on your system    #安装包
list           List a package or groups of packages    #列出YUM仓库包列表
load-transaction load a saved transaction from filename    
makecache      Generate the metadata cache        #重新生成元数据缓存(去YUM服务器更新)
provides       Find what package provides the given value
reinstall      reinstall a package    #重新安装程序
repolist       Display the configured software repositories    #列出可用的YUM仓库源
resolvedep     Determine which package provides the given dependency
search         Search package details for the given string    #搜索YUM仓库特定的包
shell          Run an interactive yum shell
update         Update a package or packages on your system    #更新包或这包组
upgrade        Update packages taking obsoletes into account
version        Display a version for the machine and/or available repos.
========选项========
Options:
  -h, --help            show this help message and exit
  -t, --tolerant        be tolerant of errors
  -C, --cacheonly       run entirely from system cache, don't update cache
  -c [config file], --config=[config file]
                        config file location
  -R [minutes], --randomwait=[minutes]
                        maximum command wait time
  -d [debug level], --debuglevel=[debug level]
                        debugging output level
  --showduplicates      show duplicates, in repos, in list/search commands
  -e [error level], --errorlevel=[error level]
                        error output level
  --rpmverbosity=[debug level name]
                        debugging output level for rpm
  -q, --quiet           quiet operation
  -v, --verbose         verbose operation
  -y, --assumeyes       answer yes for all questions
  --assumeno            answer no for all questions
  --version             show Yum version and exit
  --installroot=[path]  set install root
  --enablerepo=[repo]   enable one or more repositories (wildcards allowed)
  --disablerepo=[repo]  disable one or more repositories (wildcards allowed)
  -x [package], --exclude=[package]
                        exclude package(s) by name or glob
  --disableexcludes=[repo]
                        disable exclude from main, for a repo or for
                        everything
  --obsoletes           enable obsoletes processing during updates
  --noplugins           disable Yum plugins
  --nogpgcheck          disable gpg signature checking
  --disableplugin=[plugin]
                        disable plugins by name
  --enableplugin=[plugin]
                        enable plugins by name
  --skip-broken         skip packages with depsolving problems
  --color=COLOR         control whether color is used
  --releasever=RELEASEVER
                        set value of $releasever in yum config and repo files
  --downloadonly        don't update, just download
  --downloaddir=DLDIR   specifies an alternate directory to store packages
  --setopt=SETOPTS      set arbitrary config and repo options

        4、yum客户端配置文件

[root@case1 ~]# vi /etc/yum.conf
[main]        #主配置段
cachedir=/var/cache/yum/$basearch/$releasever    #缓存目录,两个宏:$basearch表示基本平台架构,$releaserver表示发型版本
keepcache=0        #是否保存通过YUM安装的软件包    0:表示不保存,1:表示保存,在缓存目录可以找到我们通过YUM安装的包
debuglevel=2
logfile=/var/log/yum.log    #日志保存位置
exactarch=1
obsoletes=1
gpgcheck=1        #pgp密钥检查
plugins=1        #YUM插件
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=19&ref=http://bugs.centos.org/bug_report_pag
e.php?category=yumdistroverpkg=centos-release
[root@case1 ~]# vi /etc/yum.repos.d/local.repo        #实验环境,自己搭建本地YUM源
[CentOS-Intranet]            #YUM仓库名字,在使用yum repolist可以看到的仓库名字,不能与其他YUM仓库源名字相同
name=Centos-Server-192.168.3.10-Base    #描述信息,随便写
baseurl=http://192.168.3.10/Packages/        #yum仓库链接,这里采用的是http方式,如果是file,格式应该是file:///media/Packages/,看见repodata目录就是仓库的位置
enabled=1        #是否启用,1表示开始,0表示关闭
gpgchechk=0    #检查包的合法性,1表示开启,0表示关闭
cost=1000    #开销值,我这里优先级设置是本地最优先,默认值1000,第二是epel源,第三是Centos网络源,越小越优先

[epel]    #网络EPEL源
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6        #公钥存放的路径,可以是本地,也可以是远端服务器
cost=2000

[CentOS-Internet]    #Centos官方站点源
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1
cost=3000

3)    本地Yum仓库建制

        我们安装Centos Linux系统,通常是采用最小化安装(安装的软件包非常小,200多个RPM包),我们本地做实验,经常要安装各类工具,编译环境,经常需要安装卸载程序包,网络太慢,所以自建一个YUM仓库非常有必要。

        采用Centos 6.7版本安装,CentOS-6.7-x86_64-bin-DVD1.iso,CentOS-6.7-x86_64-bin-DVD2.iso,通常DVD2存放的的软件,我们需要这个版本的所有ISO里面的软件

        下载地址:

        http://vault.centos.org/

        http://mirrors.163.com/

        http://mirrors.sohu.com/

        安装环境:

[root@ns1 ~]# rpm -q httpd            #本机已经安装http,查看,  如果没有可以通过挂载光盘安装
httpd-2.2.15-45.el6.centos.x86_64
[root@ns1 ~]# service httpd status        #检查httpd运行状态
httpd (pid  1592) is running...
[root@ns1 ~]# service iptables status    #检查关闭防火墙
iptables: Firewall is not running.
[root@ns1 ~]# getenforce            #检查关闭selinux
Disabled
[root@ns1 ~]#

        准备RPM

[root@ns1 ~]#mkdir /var/www/html/Packages        #rpm包安装httpd的默认工作目录
[root@ns1 ~]# mount /dev/cdrom /media/            #挂载光盘文件
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@ns1 ~]# cp /media/Packages/* /var/www/html/Packages/        #拷贝光盘文件中的RPM包到HTTP工作目录下的Packages目录下

        安装createrepo

[root@ns1 ~]# rpm -q createrepo    #检查安装createrepo程序,用于生成YUM仓库元数据信息
createrepo-0.9.9-22.el6.noarch
[root@ns1 ~]#

        生成YUM仓库元数据

        准备comps.xml文件,comps.xml文件是程序包组元数据文件,我们需要利用光盘中自带的comps.xml文件,生成我们本地comps.xml文件

[root@ns1 ~]# createrepo -o /var/www/html/Packages/ -g /media/repodata/4df092633ebecaeebdd78359a11a3c13f619f22605322e15e5e307beebd8e641-c6-x86_64-comps.xml /var/www/html/Packages/Spawning worker 0 with 6575 pkgs
                            #-o指定生成的元数据信息存放位置,-g指定包组元数据信息(这个文件是ISO光盘镜像中,是原先存放ISO中包组元数据信息),最后一个目录则是指定RPM包目录,根据此目录下的RPM生成各类元数据信息
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete    #YUM仓库元数据信息生成完成
[root@ns1 ~]#

        YUM客户端测试

[root@case1 ~]# yum repolist    #识别到各个YUM仓库源,可以正常安装RPM包组软件和RPM包软件
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * epel: ftp.cuhk.edu.hk
 * CentOS-Internet: ftp.sjtu.edu.cn
repo id                                             repo name                                                                          status
CentOS-Intranet                                     Centos-Server-192.168.3.10-Base                                                     6,575
epel                                                Extra Packages for Enterprise Linux 6 - x86_64                                     12,125
CentOS-Internet                                     CentOS-6 - Base                                                                     6,696
repolist: 25,396
[root@case1 ~]#

原创文章,作者:nice_neo_linux,如若转载,请注明出处:http://www.178linux.com/18068

(0)
上一篇 2016-06-22 15:48
下一篇 2016-06-22 15:49

相关推荐

  • DNS

    这里都以我本机的实验为例 正向解析:就是从主机名到IP的解析过程 先在工作目录/var/named/创建一个区域数据文件 以zcylinux.io域为例:vim/var/named/zcylinux.io.zone $TTL  600     #设置全局变量TTL的值为600s zcylinux.io.&nb…

    Linux干货 2017-05-30
  • 第二周博客作业

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 文件管理类命令:cp,mv,rm 常用的使用方法: cp命令: 单源复制: cp [OPTION]…[-T] SOURCE DEST 多源复制: cp [OPTION]… SOURCE …DIRECTORY cp [OPTION]… …

    Linux干货 2017-02-06
  • 第十一周作业

    第十一周作业 1、详细描述一次加密通讯的过程,结合图示最佳 第一阶段:ClientHello: 支持的协议版本,比如tls 1.2; 客户端生成一个随机数,稍后用户生成“会话密钥” 支持的加密算法,比如AES、3DES、RSA; 支持的压缩算法; 第二阶段:ServerHello 确认使用的加密通信协议版本,比如tls 1.2; 服务器端生成一个随机数,稍后…

    2017-10-29
  • 2016.08.04学习笔记

    文本管理工具     1.cat:查看文件,读取键盘输入         -A:查看文件所有信息         -n:显示行数   &nb…

    Linux干货 2016-08-08
  • linux 基础命令(四)

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限。 [root@localhost home]# cp -r /etc/skel/ /home/tuser1 [root@localhost home]# c…

    Linux干货 2016-10-16
  • bash脚本编程之算术运算和文件查找

    算数运算在每个编程语言里面是最基本的功能,在bash里面也是.相对于其他编程语言来说在bash里面不能直接以变量加上变量的形式来表现;比如我们先声明两个变量num1和num2然后再做运算。 num1=2 num2=3 echo "$num1+$num2" 2+3 这里我们显示的结果直接为2+3只是做了变量的替换,而不是做两个变量…

    Linux干货 2016-12-23