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.www58058.com/18068

(0)
nice_neo_linuxnice_neo_linux
上一篇 2016-06-22
下一篇 2016-06-22

相關推薦

  • Javascript 裝載和執行

    一兩個月前在淘寶內網里看到一個優化Javascript代碼的競賽,發現有不少的人對Javascript的執行和裝載的基礎并不懂,所以,從那天起我就想寫一篇文章,但一直耽擱了。自上篇《瀏覽器渲染原理簡介》,正好也可以承前啟后。 首先,我想說一下Javascript的裝載和執行。通常來說,瀏覽器對于Javascript的運行有兩大特性:1)載入后馬上執行,2)執…

    Linux干貨 2016-07-10
  • Centos 系列bind搭建DNS服務加固

        在centos系列版本上運用bind搭建dns服務教程已經有很多,先感謝前人做出的貢獻,引用兩篇博文,講解的非常詳細。 地址是: 主dns搭建:http://blog.csdn.net/reblue520/article/details/52537014 從dns搭建:http://blog.csdn.net/reblue520/…

    Linux干貨 2017-04-16
  • Java中的CopyOnWrite容器

    Copy-On-Write簡稱COW,是一種用于程序設計中的優化策略。其基本思路是,從一開始大家都在共享同一個內容,當某個人想要修改這個內容的時候,才會真正把內容Copy出去形成一個新的內容然后再改,這是一種延時懶惰策略。從JDK1.5開始Java并發包里提供了兩個使用CopyOnWrite機制實現的并發容器,它們是CopyOnWriteArrayList和…

    Linux干貨 2016-08-15
  • 訪問控制列表ACL使用說明

    一、什么是ACL ACL(Access Control List)可靈活地,更細粒度地定義訪問文件或目錄的權限。 二、為什么使用ACL Linux上文件系統的文件系統權限管理的對象分為三類:owner,group,other。這種分類非常簡單,如果我希望有一個用戶擁有不同于這三類對象的權限,或者再定義一個用戶組的權限,傳統的權限管理就不能實現,而ACL可以很…

    Linux干貨 2016-08-08
  • Linux文本處理工具之grep

    簡介     grep:Global search regular expression and print out the line.     grep是一種文本搜索處理工具,根據用戶指定的文本模式或搜索條件對目標文件進行逐行搜索,并顯示能匹配到的行。   …

    Linux干貨 2015-05-12
  • 系統自動化安裝的實現及SELINUX的設置

    系統的自動化安裝     anaconda:系統安裝程序         tui:基于圖形庫curses的文本窗口         gui:圖形窗口     裝載根文件系統,并啟動…

    Linux干貨 2016-09-16
欧美性久久久久