20150910 課後練習 RPM YUM

1、總結rpm和yum實現程序包的管理功能.

RPM

RPM解釋:

RPM全稱爲RedhatPackageManager,最早由RedHat公司制定實施,隨後被GNU開源操作系統接受併成爲很多Linux系統(RHEL)的既定軟件標準.

RPM的特點就是將你要安裝的軟件先編譯過,並且打包成RPM機制的安裝包。

    優點:(1)已經編譯好了,所以軟件安裝方便。

        (2)在被安裝,會先檢查系統的硬盤容量,操作系統版本等,避免文件被錯誤安裝。

        (3)rpm本身提供軟件版本信息,依賴屬性軟件名稱,軟件用途說明,軟件所含文件等信息。


程序包的組成部分:

二進制程序:/bin, /sbin,/ /usr/bin, /usr/sbin,

庫文件:/lib64, /usr/lib64

配置文件:/etc

幫助文件:manual, info,


命名規則:

以 zsh-4.3.11-4.el6.centos.x86_64.rpm來說明:

zsh:是軟件的名字

4.3.11-4:這是軟件的版本號

e16:基於該版本的軟件包的發行版本號,有軟件打包商設置,不一定是原始軟件開發商.

x86_64:編譯的軟件包可以運行的處理器架構(x86_64)


    特殊說明:

        1、fcXX,elXX:表示這個軟件包的發行商版本,就像這裏的fc18,說明這個軟件包是在Fedora 18下使用的。而openssl-1.0.0-20.el6.x86_64.rpm表示這個軟件包是在RHEL 6.x(Red Hat Enterprise Linux)/CentOS 6.x下使用。

        2、devel:表示這個RPM包是軟件的開發包,例如mysql-devel-5.1.52-1.el6_0.1.i686.rpm。

        3、noarch:說明這樣的軟件包可以在任何平臺上安裝,不需要特定的硬件平臺。在任何硬件平臺上都可以運行。


安裝,卸載類

-i:install的意思。

-v:更詳細的安裝信息畫面

-h:顯示安裝進度

--nodeps:忽略依賴關係

--replacepkgs 重裝軟件包

-e:卸載軟件包


1.安裝rpm -ivh zsh-4.3.11-4.el6.centos.x86_64.rpm  安裝軟件包:

wKiom1XzzEDx4gU2AAC0zmCR9MQ294.jpg


2安裝rpm -ivh qt3-MySQL-3.3.8b-30.el6.x86_64.rpm 出現依賴包錯誤顯示:

wps6677.tmp


如果要強制安裝此rpm包就需要 --nodeps 參數:

wps6678.tmp


4.如果一個軟件已經安裝過但是想要重裝的話就需要--replacepkgs

wps6679.tmp


5.如果要卸載一個軟件:rpm -e

wps667A.tmp


查詢類

-q:僅查詢,後面的軟件名稱是否安裝。

-qa:列出系統上已經安裝的所有軟件名稱。

-ql:列出該軟件所有的文件與目錄所在的完整文件名。

-qi:列出軟件的詳細信息,包含開發商版本說明。

-qf:查詢軟件由那個包生成的。

-qc:查看當前程序生成了哪些配置文件。

-p: 查詢針對是未安裝的程序包文件



1.查詢軟件包是否安裝:rpm -q name:

wps667B.tmp

wps668C.tmp


2.查詢已安裝的軟件:rpm -qa(我這裏一共安裝了454個軟件)

wps668D.tmp


3.查詢zsh所有的文件目錄:rpm -ql

wps668E.tmp


4.查詢zsh包含有的信息:rpm  -qi

wps669E.tmp


5.查詢軟件由哪個包生成的:rpm -qf

wps669F.tmp


6.查詢當前軟件生成了哪些配置文件:rpm -qc

wps66A0.tmp


7.查詢針對未安裝的程序文件:rpm -qpi ,rpm -qpl

wps66B1.tmp

wps66B2.tmp


軟件更新

-Uvh:後面跟的軟件如果沒有安裝過,則直接安裝,如果有安裝舊版,則系統自動更新。

-Fvh:後面跟的軟件如果沒有安裝過,則不會安裝,只有安裝到系統內部的軟件會被升級。


校驗:

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 -V zsh

[root@localhost Packages]# rpm -V zsh
S.5....T.    /usr/share/zsh/4.3.11/functions/zrecompile
[root@localhost Packages]#



包校驗:

來源合法性驗正:非對稱加密

完整性驗正:單向加密

導入密鑰:rpm -ivh RPM-GPG-KEY-CentOS-6

校驗:rpm -K /PATH/TO/RPM_FILE

[root@localhost Packages]# rpm -K zsh-4.3.11-4.el6.centos.x86_64.rpm
zsh-4.3.11-4.el6.centos.x86_64.rpm: rsa sha1 (md5) pgp md5 OK


wps66B3.tmp


YUM

YUM命令的解釋:

yum(全稱爲 Yellow dog Updater, Modified)是一個在Fedora和RedHat以及SUSE中的Shell前端軟件包管理器。基於RPM包管理,能夠從指定的服務器自動下載RPM包並且安裝,可以自動處理依賴性關係,並且一次安裝所有依賴的軟體包,無須繁瑣地一次次下載、安裝。yum提供了查找、安裝、刪除某一個、一組甚至全部軟件包的命令,而且命令簡潔而又好記。

yum程序的配置文件:

/etc/yum.conf

定義全局配置:對所有倉庫都適用的配置

/etc/yum.repos.d/*.repo

一個文件通常用於一個或一組功能相近或相關的倉庫

   

     定義一個倉庫指向:

        [REPO_ID]
        name=
        baseurl=
        # mirrorlist=SCHEME://HOSTNAME/PATH/TO/MIRROR_LIST_FILE
        enabled={1|0}
        gpgcheck={1|0}
        gpgkey=
        cost=



    比如創建阿里源和epel源:

[centos]
name=Centos aliyun
baseurl=http://mirrors.aliyun.com/centos/6/os/x86_64/
enabled=1
gpgcheck=0


[Fedora-epel]
name=Fedora-epel
baseurl=http://mirrors.aliyun.com/epel/6Server/x86_64/
enabled=1
gpgcheck=0


1.安裝類  

yum install 安裝:yum install wget

[root@localhost Packages]# yum install wget
省略:
Running Transaction
  Installing : wget-1.12-5.el6_6.1.x86_64                                                                                                                                                  1/1
  Verifying  : wget-1.12-5.el6_6.1.x86_64                                                                                                                                                  1/1
Installed:
  wget.x86_64 0:1.12-5.el6_6.1                                                                                                                                                                
Complete!
[root@localhost Packages]#


yum remove 卸載軟件包:yum remove wget

[root@localhost Packages]# yum remove wget
省略:
Warning: RPMDB altered outside of yum.
  Erasing    : wget-1.12-5.el6_6.1.x86_64                                                                                                                                                  1/1
  Verifying  : wget-1.12-5.el6_6.1.x86_64                                                                                                                                                  1/1
Removed:
  wget.x86_64 0:1.12-5.el6_6.1                                                                                                                                                                
Complete!
[root@localhost Packages]#


2 更新和升級

yum update 全部更新

[root@localhost Packages]# yum update
Loaded plugins: fastestmirror
Setting up Update Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package ibus-table-cangjie.noarch 0:1.2.0.20100210-1.el6 will be obsoleted
---> Package ibus-table-chinese-cangjie.noarch 0:1.4.6-1.el6 will be obsoleting
省略
.
.
Complete!
[root@localhost Packages]#


yum update 包名 指定軟件包更新

[root@localhost Packages]# yum update wget
Loaded plugins: fastestmirror
Setting up Update Process
Loading mirror speeds from cached hostfile
No Packages marked for Update
[root@localhost Packages]#



yum check-update檢查可更新的程序

[root@localhost Packages]# yum check-update

wps66C3.tmp



3 查找和顯示

yum info 顯示包的信息

[root@localhost Packages]# yum info zsh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name        : zsh
Arch        : x86_64
Version     : 4.3.11
Release     : 4.el6.centos
Size        : 5.0 M
Repo        : installed
Summary     : A powerful interactive shell
URL         : http://zsh.sunsite.dk/
License     : BSD
Description : The zsh shell is a command interpreter usable as an interactive login
            : shell and as a shell script command processor.  Zsh resembles the ksh
            : shell (the Korn shell), but includes many enhancements.  Zsh supports
            : command line editing, built-in spelling correction, programmable
            : command completion, shell functions (with autoloading), a history
            : mechanism, and more.
[root@localhost Packages]#


yum list  顯示指定程序包安裝情況

[root@localhost Packages]# yum list zsh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
zsh.x86_64                                                                            4.3.11-4.el6.centos                                                                             installed
[root@localhost Packages]#


yum serach all 查看所有包的信息

[root@localhost Packages]# yum search all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
====================================================================================== N/S Matched: all =======================================================================================
PackageKit-debug-install.x86_64 : Facility to install debugging packages using PackageKit
alliance-doc.x86_64 : Alliance VLSI CAD Sytem - Documentations
alliance-libs.i686 : Alliance VLSI CAD Sytem - multilibs
alliance-libs.x86_64 : Alliance VLSI CAD Sytem - multilibs
ctan-kerkis-calligraphic-fonts.noarch : Kerkis Calligraphic Type1 fonts
eclipse-callgraph.x86_64 : C/C++ Call Graph Visualization Tool
yum.noarch : RPM package installer/updater/manager
yum-plugin-auto-update-debug-info.noarch : Yum plugin to enable automatic updates to installed debuginfo packages
yum-plugin-fs-snapshot.noarch : Yum plugin to automatically snapshot your filesystems during updates
yum-plugin-local.noarch : Yum plugin to automatically manage a local repo. of downloaded packages
yum-plugin-merge-conf.noarch : Yum plugin to merge configuration changes when installing packages
yum-plugin-show-leaves.noarch : Yum plugin which shows newly installed leaf packages
  Name and summary matches only, use "search all" for everything.
[root@localhost Packages]#


yum search 查看zsh包的詳細信息

[root@localhost Packages]# yum search zsh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
====================================================================================== N/S Matched: zsh =======================================================================================
autojump-zsh.noarch : Autojump for zsh
docker-io-zsh-completion.x86_64 : zsh completion files for docker
gromacs-zsh.noarch : GROMACS zsh support
python-twisted-core-zsh.x86_64 : Tab completion for Zsh and Twisted Core
zsh-html.x86_64 : Zsh shell manual in html format
zsh.x86_64 : A powerful interactive shell
zsh-lovers.noarch : A collection of tips, tricks and examples for the Z shell
  Name and summary matches only, use "search all" for everything.
[root@localhost Packages]#


yum repolist 顯示系統配置源的情況

[root@localhost ~]# yum repolist all
Loaded plugins: aliases, auto-update-debuginfo, changelog, dellsysid, fastestmirror, filter-data, fs-snapshot, keys, list-data, local, merge-conf, post-transaction-actions, presto,
              : priorities, protectbase, ps, remove-with-leaves, rpm-warm-cache, security, show-leaves, tmprepo, tsflags, upgrade-helper, verify, versionlock
Loading mirror speeds from cached hostfile
0 packages excluded due to repository protections
repo id                                                                             repo name                                                                                   status
C6.0-base                                                                           CentOS-6.0 - Base                                                                           disabled
C6.0-centosplus                                                                     CentOS-6.0 - CentOSPlus                                                                     disabled
C6.0-contrib                                                                        CentOS-6.0 - Contrib                                                                        disabled
C6.0-extras                                                                         CentOS-6.0 - Extras                                                                         disabled
C6.0-updates                                                                        CentOS-6.0 - Updates                                                                        disabled
C6.1-base                                                                           CentOS-6.1 - Base                                                                           disabled
C6.1-centosplus                                                                     CentOS-6.1 - CentOSPlus                                                                     disabled
C6.1-contrib                                                                        CentOS-6.1 - Contrib                                                                        disabled
C6.1-extras                                                                         CentOS-6.1 - Extras                                                                         disabled
C6.1-updates                                                                        CentOS-6.1 - Updates                                                                        disabled
C6.2-base                                                                           CentOS-6.2 - Base                                                                           disabled
C6.2-centosplus                                                                     CentOS-6.2 - CentOSPlus                                                                     disabled
C6.2-contrib                                                                        CentOS-6.2 - Contrib                                                                        disabled
C6.2-extras                                                                         CentOS-6.2 - Extras                                                                         disabled
C6.2-updates                                                                        CentOS-6.2 - Updates                                                                        disabled
C6.3-base                                                                           CentOS-6.3 - Base                                                                           disabled
C6.3-centosplus                                                                     CentOS-6.3 - CentOSPlus                                                                     disabled
C6.3-contrib                                                                        CentOS-6.3 - Contrib                                                                        disabled
C6.3-extras                                                                         CentOS-6.3 - Extras                                                                         disabled
C6.3-updates                                                                        CentOS-6.3 - Updates                                                                        disabled
C6.4-base                                                                           CentOS-6.4 - Base                                                                           disabled
C6.4-centosplus                                                                     CentOS-6.4 - CentOSPlus                                                                     disabled
C6.4-contrib                                                                        CentOS-6.4 - Contrib                                                                        disabled
C6.4-extras                                                                         CentOS-6.4 - Extras                                                                         disabled
C6.4-updates                                                                        CentOS-6.4 - Updates                                                                        disabled
C6.5-base                                                                           CentOS-6.5 - Base                                                                           disabled
C6.5-centosplus                                                                     CentOS-6.5 - CentOSPlus                                                                     disabled
C6.5-contrib                                                                        CentOS-6.5 - Contrib                                                                        disabled
C6.5-extras                                                                         CentOS-6.5 - Extras                                                                         disabled
C6.5-updates                                                                        CentOS-6.5 - Updates                                                                        disabled
C6.6-base                                                                           CentOS-6.6 - Base                                                                           disabled
C6.6-centosplus                                                                     CentOS-6.6 - CentOSPlus                                                                     disabled
C6.6-contrib                                                                        CentOS-6.6 - Contrib                                                                        disabled
C6.6-extras                                                                         CentOS-6.6 - Extras                                                                         disabled
C6.6-updates                                                                        CentOS-6.6 - Updates                                                                        disabled
Fedora-epel                                                                         Fedora-epel                                                                                 enabled: 11,765
base-debuginfo                                                                      CentOS-6 - Debuginfo                                                                        disabled
c6-media                                                                            CentOS-6 - Media                                                                            disabled
centos                                                                              Centos aliyun                                                                               enabled:  6,575
fasttrack                                                                           CentOS-6 - fasttrack                                                                        disabled
repolist: 18,340
[root@localhost ~]#


4.刪除程序

yum remove

[root@localhost Packages]# yum remove wget
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.12-5.el6_6.1 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================================================
 Package                                   Arch                                        Version                                              Repository                                    Size
===============================================================================================================================================================================================
Removing:
 wget                                      x86_64                                      1.12-5.el6_6.1                                       @centos                                      1.8 M
Transaction Summary
===============================================================================================================================================================================================
Remove        1 Package(s)
Installed size: 1.8 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing    : wget-1.12-5.el6_6.1.x86_64                                                                                                                                                  1/1 
  Verifying  : wget-1.12-5.el6_6.1.x86_64                                                                                                                                                  1/1 
Removed:
  wget.x86_64 0:1.12-5.el6_6.1                                                                                                                                                                 
Complete!


yum deplist  查看程序依賴情況



5.清除緩存   

yum clean all 清除緩存目錄下的軟件包    

[root@localhost Packages]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: Fedora-epel centos
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@localhost Packages]#


yum makecache 建立緩存

[root@localhost Packages]# yum makecache

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Fedora-epel                                                                                                                                                             | 4.3 kB     00:00    
centos                                                                                                                                                                  | 3.7 kB     00:00    
Metadata Cache Created
[root@localhost Packages]#


6.包組管理

yum grouplist 列出所有的包組

[root@localhost Packages]#  yum grouplist
Loaded plugins: fastestmirror
Setting up Group Process
Loading mirror speeds from cached hostfile
Installed Groups:
   Additional Development
   Development tools
   E-mail server
   Fonts
   General Purpose Desktop
   Graphical Administration Tools
   Input Methods
   Legacy X Window System compatibility
   Milkymist
   Networking Tools
   Perl Support
   Security Tools
Installed Language Groups:
   Chinese Support [zh]
Available Groups:
省略
.
.
Upper Sorbian Support [hsb]
   Urdu Support [ur]
   Uzbek Support [uz]
   Venda Support [ve]
   Vietnamese Support [vi]
   Walloon Support [wa]
   Welsh Support [cy]
   Xhosa Support [xh]
   Zulu Support [zu]
Done
[root@localhost Packages]#


yum groupinfo 顯示包組內具體信息

[root@localhost Packages]# yum groupinfo  "Development tools"
Loaded plugins: fastestmirror
Setting up Group Process
Loading mirror speeds from cached hostfile
Group: Development tools
Description: A basic development environment.
Mandatory Packages:
   autoconf
   automake
   binutils
   bison
   flex
   gcc
   gcc-c++
   gettext
   libtool
   make
   patch
   pkgconfig
   redhat-rpm-config
   rpm-build
Default Packages:
trac-git-plugin
   trac-mercurial-plugin
   trac-webadmin
   translate-toolkit
[root@localhost Packages]#


yum groupinstall 安裝包組

[root@localhost Packages]# yum groupinstall  'Development tools'
Loaded plugins: fastestmirror
Setting up Group Process
Loading mirror speeds from cached hostfile
Package flex-2.5.35-9.el6.x86_64 already installed and latest version
Package gcc-4.4.7-16.el6.x86_64 already installed and latest version
Package autoconf-2.63-5.1.el6.noarch already installed and latest version
Package redhat-rpm-config-9.0.3-44.el6.centos.noarch already installed and latest version
Package rpm-build-4.8.0-47.el6.x86_64 already installed and latest version
Package git-1.7.1-3.el6_4.1.x86_64 already installed and latest version
Package cscope-15.6-6.el6.x86_64 already installed and latest version
Package swig-1.3.40-6.el6.x86_64 already installed and latest version
Warning: Group development does not have any packages.
No packages in any requested group available to install or update
[root@localhost Packages]#


yum groupremove 卸載包組

[root@localhost Packages]# yum groupremove "Development tools"
Loaded plugins: fastestmirror
Setting up Group Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.63-5.1.el6 will be erased
---> Package automake.noarch 0:1.11.1-4.el6 will be erased
---> Package binutils.x86_64 0:2.20.51.0.2-5.43.el6 will be erased
--> Processing Dependency: binutils for package: module-init-tools-3.9-25.el6.x86_64
---> Package bison.x86_64 0:2.4.1-5.el6 will be erased
---> Package byacc.x86_64 0:1.9.20070509-7.el6 will be erased
省略
.
.
---> Package libselinux-devel.x86_64 0:2.0.94-5.8.el6 will be erased
---> Package libsepol-devel.x86_64 0:2.0.41-4.el6 will be erased
---> Package pcre-devel.x86_64 0:7.8-7.el6 will be erased
---> Package rsyslog.x86_64 0:5.8.10-10.el6_6 will be erased
---> Package zlib-devel.x86_64 0:1.2.3-29.el6 will be erased
--> Processing Dependency: /sbin/new-kernel-pkg for package: kernel-2.6.32-573.el6.x86_64
Skipping the running kernel: kernel-2.6.32-573.el6.x86_64
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
--> Finished Dependency Resolution
Error: Trying to remove "yum", which is protected
[root@localhost Packages]#


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