linux 程序包管理之yum

                                   

                                    YUM


yum:Yellowdog Updater modified。

    它是redhat和centos系統中shell軟件包的一種前端管理器。它所管理的軟件包爲.rpm格式。它跟rpm相比,最大的好處就是解決了rpm程序安裝的依賴關係,簡化程序安裝的過程。在一個能上網的環境下,可以直接安裝我們想要的程序包,那是相當不錯的。它的工作過程主要是通過用戶指定的路徑去某個指定的站點搜索自己想要的rpm包程序來安裝和維護(站點包括:file(本地)、ftp、http、nfs、其他互聯網站點)


yum的優點:

  1. 解決rpm包安裝時的依賴性;

  2. 方便添加、刪除、更新rpm包;

  3. 可以同時批量安裝rpm程序包;

  4. 更加方便程序安裝後的維護;


yum服務的兩種配置文件:主要是配合yum這個程序更好的工作,方便用戶管理它。

1、/etc/yum.conf

主要針對yum服務的,具體內容如下:

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=19&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release


[man]:主配置段,主要起標識作用;

cachedir:緩存目錄。從站點上下載的程序包爲了加速訪問,需要指定一個本地緩存的地方;

keepcache:是否保存安裝後的包和首部的緩存。默認爲1,0代表否;

debuglevel:調試輸出等級,1-10個級別,默認爲2;

logfile:記錄yum的日誌文件;

exactarch:表示在升級程序的時候,符合硬件平臺才升級,默認爲1;

obsoletes:升級程序後,安裝的包會被刪除,默認爲1;

gpgcheck:安裝rpm程序包時,是否開啓gpg檢測,默認爲0不檢測,1爲檢測;

plugins:yum插件是否可用,默認爲0,不可用;

installonly_limit:限制內核數量上限的,一般爲5;


2、/etc/yum.repos.d/*repo (重要)

這是yum的源倉庫的配置文件。有了程序的倉庫,就不怕找不到想要的程序包了。

[base]
name=CentOS-$releasever - Base
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


[*]:源倉庫的名字,可隨意寫;

name:源倉庫的描述信息,也可隨意寫;

baseurl:這個是倉庫的具體路徑,必須正確;

gpgcheck:這個是否開啓gpg檢測,1爲開啓,0爲關閉;

gpgkey:這個是指定gpg檢測時使用的key路徑。使用前提是gpgcheck=1。/etc/pki/rpm-gpg 目錄下存放的是key文件

    當我想要使用yum安裝程序的時候,yum會首先搜索/etc/yum.repos.d/這個配置文件下的*.repo文件中倉庫的baseurl路徑,從而找到程序包,並緩存到本地。默認,系統攜帶CentOS-Base.repo、CentOS-fasttrack.repo、CentOS-Vault.repo、CentOS-Debuginfo.repo、CentOS-Media.repo 這麼幾個倉庫配置文件。這些配置文件中包含的baseurl是互聯網站點,因此,當我的linux主機能上Inter網,那麼這些默認的配置文件就能派上用場了。 某些時候,我們無法上網,就需要在/etc/yum.repos.d/目錄下面自己手動創建yum的源倉庫了。   


yum命令的內部執行過程:

  1. 打上yum命令之後,yum開始尋找本地倉庫配置文件中指定給它的可用yum倉庫地址;

  2. 把那些倉庫中的各個元數據文件下載並緩存到本地,以便快速分析;

  3. 根據分析結果,查看當前系統上要安裝的程序de依賴包安裝到還剩多少沒有安裝;

  4. 統計還沒有安裝的依賴包,下載,並一起安裝;


yum倉庫的幾種路徑(baseurl=?)

  1. ftp方式:ftp ://server-ip-address/path/to/repo;

  2. http方式:http ://server-ip-address/path/to/repo;

  3. nfs方式:nfs: //server-ip-address/path/to/repo;

  4. 本地方式:file: ///path/to/repo。(前兩個//是協議分隔符)


yum客戶端的工作:

  1. 存有yum的源倉庫配置文件:指定各個可用的yum倉庫地址,可以多個;

  2. yum緩存元數據:yum回到各個可用yum倉庫獲取元數據,並緩存至本地。默認/var/cache/yum/目錄下;

  3. 分析元數據:根據具體的操作請求,完成元數據分析,可能包括檢查依賴關係、文件列表等;

  4. 執行具體操作;


yum源的搭建:

前提:yum在有網絡的時候,是很好用的。但是,某些客觀情況下,我們不能接入互聯網絡。怎麼辦?

  1. 通過光盤,使用rpm命令進行安裝--安裝過程繁雜,無法自行解決依賴關係;

  2. 自己手動搭建一個yum源倉庫--部署過程繁雜,但是安裝過程更簡單;


yum源的組成部分:

yum倉庫=rpm程序包+元數據(程序包索引)+md5校驗值+gpgkey(可選)


yum源的搭建方式:

  1. file:本地;

  2. ftp:文件協議;

  3. http:web;


yum倉庫元數據和md5校驗值的創建命令:createrepo

    createrepo命令也是一個rpm程序,系統必須提前安裝才行;

    createrepo + rpm程序所在目錄  (生成)===> 元數據(程序索引)和md5值; (關鍵)




搭建步驟:

一、使用本地訪問的方式自定義搭建yum源倉庫:


1、首先,我們得要蒐集rpm包程序,(這裏我們用centos系統光盤中的rpm包)把他們集中放在一個固定目錄下,該目錄就當作一個倉庫根目錄來使用了;

[root@localhost /]# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only   :把光盤掛到/media/下面;
[root@localhost /]#
[root@localhost /]# mkdir /yum/server -p       :新建兩個目錄,作爲倉庫的根目錄;
[root@localhost /]#
[root@localhost /]# cp /media/Packages/* /yum/server/     :把光盤中的rpm程序包都複製到根目錄下面去;

[root@localhost /]# ls /yum/server/ | wc -l
4185           :複製完成之後,可以看到有4千多行了;

[root@localhost /]#

 

2、修改yum的服務端配置文件,關閉gpg檢測;           

vim /etc/yum.conf

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=0     :修改yum的服務端配置文件,將gpg檢測關掉;(此步驟也可在*.repo下去改)


3、安裝createrepo程序,創建一個光盤yum源倉庫

因爲要安裝createrepo這個程序才能創建源倉庫的索引和md5校驗值,因此,要麼使用rpm,直接去光盤中找到對應的那個rpm包安裝即可,要麼把光盤製作成yum源倉庫來進行安裝。後者稍複雜,但解決了依賴關係,選後者額;


[root@localhost /]# vim /etc/yum.repos.d/test.repo   :在本地自定義一個倉庫配置文件,test.repo
gpgkey=ftp://172.16.16.11/pub/ftp-yum/RPM-GPG-KEY-CentOS-6
[test]
name=test
baseurl=file:///media/       :將倉庫的路徑寫到本地的光盤掛載目錄下面;
enabled=1       :開啓此倉庫;
gpgcheck=0      :關閉gpg校驗。(本地路徑一般不需要)


[root@localhost media]# ls
CentOS_BuildTag  GPL       Packages                  RPM-GPG-KEY-CentOS-6           RPM-GPG-KEY-CentOS-Testing-6
EFI              images    RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Debug-6     TRANS.TBL
EULA             isolinux  repodata                  RPM-GPG-KEY-CentOS-Security-6
[root@localhost media]# 

 爲什麼我們要寫到/media/目錄呢?

    因爲系統光盤本身就是rpm包+元數據(程序包索引)+md5校驗值+gpgkey 的組成,它符合yum倉庫的要求,因此,只要把路徑指到光盤目錄即可;

“Packages ”:放rpm程序包;

“repodata”:裏面存放的將就是createrepo命令創建的元數據+md5校驗值了;

[root@localhost media]# cd repodata/
[root@localhost repodata]#
[root@localhost repodata]# ls
036dd72d77ba4abf25f5583b7973558f5f7a6bc90ee18be1f27a9d93072313f8-primary.sqlite.bz2
1449a8ec2555257108f11679628d0f70e57031a4be8adc73456443a0462a1b65-primary.xml.gz
3dd75f6c0394f9a55bd6d15102dc023d27c057c99182cca8b0d3c8f71912fc62-filelists.sqlite.bz2
460862ca0e99160b41eecc41b944eb2abc0b82609bd12407bc5609922627eac4-c6-x86_64-comps.xml.gz
7fe6caf79ef1ada2e8f84ad92cd6568ac508d38d3c31dba907832ba7058ebb77-filelists.xml.gz
99b1dfe7d6129ba0fe7c019459b4a8594b74c5d3dacae9511afda520f6912660-other.xml.gz
9a5c649c5eb8b0b1365aa19954766d0ea80ee59b701b41a555792443456557f3-other.sqlite.bz2
9e2ddcc42b44eb150ebc61dde29c997318d8330b92205b3dbb3a87bcc06d10be-c6-x86_64-comps.xml

repomd.xml
TRANS.TBL

“repomd.xml”:就是rpm包的索引。其他紅色部分就是rpm包的md5值了;


4、repo配置文件指定好之後,開始驗證光盤倉庫是否能正常工作;

[root@localhost /]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id                                                repo name                                            status
test                                                   test                                                 4,184
repolist: 4,184
[root@localhost /]#
    :顯示了4184個rpm程序包,說明光盤倉庫搭建完成了;


5、  現在利用yum,來安裝createrepo程序:

[root@localhost /]# yum install createrepo


6、利用createrepo命令和程序包來創建元數據和md5校驗;

[root@CentOS6 ~]# createrepo /yum/server/
Spawning worker 0 with 4184 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete   :提示成功了;
[root@CentOS6 ~]#   


7、修改本地倉庫配置文件,讓它指到我們自定義的倉庫路徑下:

[root@localhost /]# vim /etc/yum.repos.d/test.repo
[test]        :此處注意,不可跟系統中其他倉庫名有衝突,不然無效;
name=test
baseurl=file:///yum/server/
enabled=1
gpgcheck=0   完成。


8、裝包驗證:

[root@CentOS6 ~]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
test                                                                                       | 2.9 kB     00:00 ...
test/primary_db                                                                            | 3.4 MB     00:00 ...
repo id                                             repo name                                               status
test                                                createrepo                                              4,184
repolist: 4,184
[root@CentOS6 ~]#   :test.repo裏的倉庫路徑被識別了!


[root@CentOS6 ~]# yum list available | less
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Available Packages
389-ds-base.x86_64                        1.2.11.15-46.el6                  test
389-ds-base-libs.i686                     1.2.11.15-46.el6                  test
389-ds-base-libs.x86_64                   1.2.11.15-46.el6                  test
DeviceKit-power.i686                      014-3.el6                         test
ElectricFence.i686                        2.2.2-28.el6                      test
ElectricFence.x86_64                      2.2.2-28.el6                      test

    分頁顯示yum倉庫中沒有被安裝的程序包;


[root@CentOS6 ~]# yum install xsettings-kde
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package xsettings-kde.x86_64 0:0.11-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================
 Package                        Arch                    Version                       Repository             Size
==================================================================================================================
Installing:
 xsettings-kde                  x86_64                  0.11-1.el6                    test                   23 k

Transaction Summary
==================================================================================================================
Install       1 Package(s)

Total download size: 23 k
Installed size: 47 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : xsettings-kde-0.11-1.el6.x86_64                                                                1/1
  Verifying  : xsettings-kde-0.11-1.el6.x86_64                                                                1/1

Installed:
  xsettings-kde.x86_64 0:0.11-1.el6                                                                               

Complete!
[root@CentOS6 ~]#   測試一個,安裝成功,本地源倉庫就搭建完畢了;



二、使用ftp訪問的方式自定義搭建yum源倉庫:

    當公司使用一臺ftp服務器,集中管理rpm程序的時候,ftp作爲yum源倉庫就是很好的選擇了;

1、使用rpm,在光盤中找到vsftpd程序,並安裝、開啓ftp服務;

[root@localhost Packages]# rpm -ivh vsftpd-2.2.2-12.el6_5.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:vsftpd                 ########################################### [100%]
[root@localhost Packages]# 

[root@localhost Packages]# service vsftpd start

[root@localhost Packages]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN  
  


2、配置ftp。在ftp根目錄下面自定義一個目錄,將yum源倉庫放到ftp根目錄下面。

[root@localhost /]# mkdir /var/ftp/pub/yum   
[root@localhost /]# cp -r /media/Packages/* /var/ftp/pub/yum/

[root@localhost /]#


3、創建源倉庫的程序元數據和md5值

[root@CentOS6 ~]# createrepo /var/ftp/pub/ftp-yum/
Spawning worker 0 with 4184 pkgs

Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete


4、修改本地yum倉庫路徑:

[root@CentOS6 ~]# vim /etc/yum.repos.d/test.repo
[test]
name=createrepo
baseurl=ftp://172.16.16.11/pub/ftp-yum/
enable=1
#gpgcheck=1
#gpgkey=ftp://172.16.16.11/pub/ftp-yum/RPM-GPG-KEY-CentOS-6


5、驗證:

[root@CentOS6 ~]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
test                                                                                       | 2.9 kB     00:00     
test/primary_db                                                                            | 3.4 MB     00:00     
repo id                                             repo name                                               status
test                                                createrepo                                              4,184
repolist: 4,184
[root@CentOS6 ~]#


[root@CentOS6 ~]# yum install qperf
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package qperf.x86_64 0:0.4.9-1.el6 will be installed
--> Processing Dependency: librdmacm.so.1(RDMACM_1.0)(64bit) for package: qperf-0.4.9-1.el6.x86_64
--> Processing Dependency: libibverbs.so.1(IBVERBS_1.1)(64bit) for package: qperf-0.4.9-1.el6.x86_64
--> Processing Dependency: libibverbs.so.1(IBVERBS_1.0)(64bit) for package: qperf-0.4.9-1.el6.x86_64
--> Processing Dependency: librdmacm.so.1()(64bit) for package: qperf-0.4.9-1.el6.x86_64
--> Processing Dependency: libibverbs.so.1()(64bit) for package: qperf-0.4.9-1.el6.x86_64
--> Running transaction check
---> Package libibverbs.x86_64 0:1.1.8-3.el6 will be installed
---> Package librdmacm.x86_64 0:1.0.18.1-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================
 Package                     Arch                    Version                          Repository             Size
==================================================================================================================
Installing:
 qperf                       x86_64                  0.4.9-1.el6                      test                   55 k
Installing for dependencies:
 libibverbs                  x86_64                  1.1.8-3.el6                      test                   52 k
 librdmacm                   x86_64                  1.0.18.1-1.el6                   test                   57 k

Transaction Summary
==================================================================================================================
Install       3 Package(s)

Total download size: 165 k
Installed size: 386 k
Is this ok [y/N]: y
Downloading Packages:
(1/3): libibverbs-1.1.8-3.el6.x86_64.rpm                                                   |  52 kB     00:00     
(2/3): librdmacm-1.0.18.1-1.el6.x86_64.rpm                                                 |  57 kB     00:00     
(3/3): qperf-0.4.9-1.el6.x86_64.rpm                                                        |  55 kB     00:00     
------------------------------------------------------------------------------------------------------------------
Total                                                                             1.6 MB/s | 165 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : libibverbs-1.1.8-3.el6.x86_64                                                                  1/3
  Installing : librdmacm-1.0.18.1-1.el6.x86_64                                                                2/3
  Installing : qperf-0.4.9-1.el6.x86_64                                                                       3/3
  Verifying  : librdmacm-1.0.18.1-1.el6.x86_64                                                                1/3
  Verifying  : qperf-0.4.9-1.el6.x86_64                                                                       2/3
  Verifying  : libibverbs-1.1.8-3.el6.x86_64                                                                  3/3

Installed:
  qperf.x86_64 0:0.4.9-1.el6                                                                                      

Dependency Installed:
  libibverbs.x86_64 0:1.1.8-3.el6                        librdmacm.x86_64 0:1.0.18.1-1.el6                       

Complete!
[root@CentOS6 ~]#   結束;


三、使用http訪問的方式自定義搭建yum源倉庫:

http方式的yum源倉庫主要爲一些開源組織或軟件開發商等使用,主要放在外網站點。如果放在內部使用,建議還是ftp效率更高一點。


1、需要安裝httpd程序,以提供http功能,默認系統基本都會安裝好,如沒有安裝,就需要自行安裝了。


[root@CentOS6 Packages]# rpm -ivh httpd-2.2.15-39.el6.centos.x86_64.rpm
warning: httpd-2.2.15-39.el6.centos.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
        package httpd-2.2.15-39.el6.centos.x86_64 is already installed
[root@CentOS6 Packages]# 

    我這因爲安裝過,所以提示已安裝。


2、安裝好http服務之後,當我遠程http://主機ip時,會默認訪問http的根目錄。因此,在此爲了測試,我們在http的根目錄下創建一個空目錄,並製作成倉庫目錄:(默認訪問http時,訪問的就是http服務端下的,/var/www/html/)

[root@localhost ~]# mkdir /var/www/html/yum
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ls /var/www/html/
 yum
[root@localhost ~]# 

[root@localhost ~]# cp /media/Packages/* /var/www/html/yum/
[root@localhost ~]#
[root@localhost ~]# ls /var/www/html/yum/ | wc -l
4185
[root@localhost ~]#
[root@CentOS6 /]# service httpd start
Starting httpd:
[root@CentOS6 /]#
[root@CentOS6 /]#
[root@CentOS6 /]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:55031               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 :::49141                    :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN      
tcp        0      0 :::80                       :::*                        LISTEN      
[root@CentOS6 /]#


3、準備好rpm包和要創建目錄之後,使用createrepo命令生成rpm包的元數據索引和md5校驗值。

[root@localhost ~]# createrepo /var/www/html/yum/
Spawning worker 0 with 4184 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost ~]#


4、http服務端的yum源配置完成了。接下來該去客戶端上修改yum倉庫配置文件了。(注意服務端防火牆配置

[root@CentOS6 /]# vim /etc/yum.repos.d/
aa/        test.repo  
[root@CentOS6 /]# vim /etc/yum.repos.d/test.repo
[test]
name=test
baseurl=http://1.1.1.2/yum/    :注意,只要寫到/yum/即可,前面ip對應的就是/var/www/html/;
gpgcheck=0


5、安裝檢測:

[root@CentOS6 /]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id                                   repo name                               status
test                                      test                                    4,184
repolist: 4,184


[root@CentOS6 /]# yum list available | less
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Available Packages
389-ds-base.x86_64                        1.2.11.15-46.el6                  test
389-ds-base-libs.i686                     1.2.11.15-46.el6                  test
389-ds-base-libs.x86_64                   1.2.11.15-46.el6                  test
DeviceKit-power.i686                      014-3.el6                         test
ElectricFence.i686                        2.2.2-28.el6                      test
ElectricFence.x86_64                      2.2.2-28.el6                      test
GConf2.i686                               2.28.0-6.el6                      test
GConf2-devel.i686                         2.28.0-6.el6                      test
GConf2-devel.x86_64                       2.28.0-6.el6                      test
ImageMagick.i686                          6.5.4.7-7.el6_5                   test
ImageMagick.x86_64                        6.5.4.7-7.el6_5                   test
ImageMagick-c++.x86_64                    6.5.4.7-7.el6_5                   test
MySQL-python.x86_64                       1.2.3-0.3.c1.1.el6                test
NetworkManager-glib.i686                  1:0.8.1-75.el6                    test
NetworkManager-openswan.x86_64            0.8.0-8.el6                       test
ORBit2.i686                               2.14.17-5.el6                     test
ORBit2-devel.i686                         2.14.17-5.el6                     test
ORBit2-devel.x86_64                       2.14.17-5.el6                     test
OpenEXR-libs.i686                         1.6.1-8.1.el6                     test
OpenEXR-libs.x86_64                       1.6.1-8.1.el6                     test
OpenIPMI.x86_64                           2.0.16-14.el6                     test
OpenIPMI-libs.i686                        2.0.16-14.el6                     test


[root@CentOS6 /]# yum install yajl
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package yajl.x86_64 0:1.0.7-3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
 Package           Arch                Version                  Repository         Size
========================================================================================
Installing:
 yajl              x86_64              1.0.7-3.el6              test               27 k

Transaction Summary
========================================================================================
Install       1 Package(s)

Total download size: 27 k
Installed size: 89 k
Is this ok [y/N]: y
Downloading Packages:
yajl-1.0.7-3.el6.x86_64.rpm                                      |  27 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : yajl-1.0.7-3.el6.x86_64                                              1/1
  Verifying  : yajl-1.0.7-3.el6.x86_64                                              1/1

Installed:
  yajl.x86_64 0:1.0.7-3.el6                                                             

Complete!
[root@CentOS6 /]#   結束。


另外,關於完整性校驗key的實驗如下:

    我們拿http作爲yum源倉庫,來進行示範。

1、現在我們安裝好了yum源,並且能正常提供服務了。現在客戶端倉庫配置文件中,我們打開gpg檢測,即,gpgcheck=1;

[root@CentOS6 /]# vim /etc/yum.repos.d/test.repo
[test]
name=test
baseurl=http://1.1.1.2/yum         :yum倉庫路徑;
enabled=1
gpgcheck=1
gpgkey=http://1.1.1.2/yum/RPM-GPG-KEY-CentOS-6      :yum的gpgkey絕對路徑。一定要絕對路徑!!;


2、驗證,當yum源倉庫真的沒有key的情況下,客戶端開啓gpg完整性校驗會出現什麼現象:

[root@CentOS6 /]# yum reinstall yajl
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Reinstall Process
Determining fastest mirrors
test                                                             | 2.9 kB     00:00     
test/primary_db                                                  | 3.4 MB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package yajl.x86_64 0:1.0.7-3.el6 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
 Package           Arch                Version                  Repository         Size
========================================================================================
Reinstalling:
 yajl              x86_64              1.0.7-3.el6              test               27 k

Transaction Summary
========================================================================================
Reinstall     1 Package(s)

Total download size: 27 k
Installed size: 89 k
Is this ok [y/N]: y
Downloading Packages:
yajl-1.0.7-3.el6.x86_64.rpm                                      |  27 kB     00:00     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Retrieving key from http://1.1.1.2/http-yum
Invalid GPG Key from http://1.1.1.2/http-yum: No key found in given key data

    當我安裝程序包時,提示沒有key,無法完成校驗,不能安裝!!


3、此時,我們在yum源服務端,將key複製到源倉庫目錄下,再次安裝程序看看會出現什麼:

[root@localhost ~]# ls /etc/pki/rpm-gpg/   :存放系統gpgkey的目錄
RPM-GPG-KEY-CentOS-6        RPM-GPG-KEY-CentOS-Security-6
RPM-GPG-KEY-CentOS-Debug-6  RPM-GPG-KEY-CentOS-Testing-6
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cp /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 /var/www/html/yum/
[root@localhost ~]#

[root@CentOS6 /]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: test
Cleaning up Everything
[root@CentOS6 /]#
[root@CentOS6 /]#
[root@CentOS6 /]#
[root@CentOS6 /]#
[root@CentOS6 /]# yum -y reinstall yajl
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Reinstall Process
Determining fastest mirrors
test                                                             | 2.9 kB     00:00     
test/primary_db                                                  | 3.4 MB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package yajl.x86_64 0:1.0.7-3.el6 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
 Package           Arch                Version                  Repository         Size
========================================================================================
Reinstalling:
 yajl              x86_64              1.0.7-3.el6              test               27 k

Transaction Summary
========================================================================================
Reinstall     1 Package(s)

Total download size: 27 k
Installed size: 89 k
Downloading Packages:
yajl-1.0.7-3.el6.x86_64.rpm                                      |  27 kB     00:00     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Retrieving key from http://1.1.1.2/http-yum/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid: "CentOS-6 Key (CentOS 6 Official Signing Key) <[email protected]>"
 From  : http://1.1.1.2/yum/RPM-GPG-KEY-CentOS-6   :(提示使用哪裏的key進行的完整性校驗

Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : yajl-1.0.7-3.el6.x86_64                                              1/1
  Verifying  : yajl-1.0.7-3.el6.x86_64                                              1/1

Installed:
  yajl.x86_64 0:1.0.7-3.el6                                                             

Complete!
[root@CentOS6 /]#   ok,搞定了!!





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章