RPM:
RPM,Redhat Package Manager,RPM is Package Manager
功能:將編譯好的應用程序的各組成文件打包一個或幾個程序包文件,從而方便快捷地實現程序包的安裝、卸載、查詢、升級和校驗等管理操作
1)RPM包的命名
2)RPM包文件的組成
1、包文件的組成(每個包獨有):
RPM包內的文件
RPM的元數據,如名稱,版本,依賴性,描述
安裝或卸載時運行的腳本(有的有有的沒有)
2、 數據庫(存放安裝好的包)(不在系統里而在RPM里)
程序包元數據及版本
3)RPM管理包文件
(1)查詢:q
rpm -qa 查詢所有包
rpm -ql 包名 查看此rpm包內有哪些文件
-qf查看指定的文件由哪個程序包安裝生成(如果缺少哪個文件,可以使用此參數)
-qpl rpmfile(rpm文件):針對尚未安裝的程序包文件做查詢操作
–-whatprovidesCAPABILITY:查詢指定的CAPABILITY由哪個包所提供
–whatrequiresCAPABILITY:查詢指定的CAPABILITY被哪個包所依賴
-qc: 查詢程序的配置文件 (config)
-qd: 查詢程序的文檔
-qi: information
-ql: 查看指定的程序包安裝后生成的所有文件;
(2)安裝:-ivh ,–nodeps,–replacepakgs
–test: 測試安裝,但不真正執行安裝
–nodeps:忽略依賴關系
–replacepkgs| replacefiles
注意:
replacepkgs(替代安裝)只能替代同一個包,版本號也要相同
如果個別文件損壞,使用普通安裝可能會出現already install,此時便使用replacepkgs
replacefiles(包名和版本號都可以不一樣,只要有相同的文件即可,一般是幫助文檔)
(3)升級:U|F
rpm -Uvh|Fvh packages..
upgrade:安裝有舊版程序包,則“升級”
如果不存在舊版程序包,則“安裝”(只留一份新版本)
freshen:安裝有舊版程序包,則“升級”
如果不存在舊版程序包,則不執行升級操作
注意:
想使用新內核時候最好不要使用-U升級操作,因為會將舊內核給刪掉,使用ivh安裝會保留舊內核。
–force: 強行升級
(4)卸載:e
rpm {-e|–erase} [–allmatches] [–nodeps] [–noscripts] [–notriggers] [–test] PACKAGE_NAME …
如果有兩個包名相同,版本號不同,卸載時候會出錯,此時使用[–allmatches]參數,全部卸載
–nodeps表示不考慮依賴關系
(5)校驗 -V
為了檢查rpm包的完整性及其合法性,每個rpm包里面都有簽名內容,rpm通過/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7這個文件來檢查他的合法性。
rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
只有導入這個文件,帶具有檢查簽名的能力(如果不導入默認安裝會出現warning signature)
注意:破壞rpm包文件尾部并不能破壞其簽名
rpm -K|checksigrpmfile檢查包的完整性和簽名(前提需要導入公鑰文件)
如果將公鑰文件卸載,則檢測不出來完整性
4)RPM數據庫
/var/lib/rpm
數據庫重建:
/var/lib/rpm
rpm {–initdb|–rebuilddb}
initdb: 初始化
如果事先不存在數據庫,則新建之;否則,不執行任何操作
rebuilddb:重建(重建的只是一個索引文件)
無論當前存在與否,直接重新創建數據庫
YUM:
全稱為 Yellow dog Updater, Modified,由于RPM包之間互相存在依賴關系,使用rpm命令安裝rpm包時,系統只能顯示其直接依賴或者直接被依賴的包,YUM根據各軟件的依賴關系,當用戶指定下載某個軟件時,可以自動的解決軟件的依賴關系。
1)yum工作原理
yum
類似于c/s架構,遠方的服務器負責提供rpm包并且存放在一個單獨的目錄里面(Packages),并且需要將rpm包頭的元數據以及其依賴關系提取出
來放在一個目錄里面(repodata),yum通過分析其依賴性及元數據信息,找到所需的RPM包,隨后進行安裝。當YUM讀取repodata文件夾
時候,會將其信息放在本地緩存一份,等下次安裝時候直接讀取本地的repodata文件夾,去索要所需的rpm包,當遠方服務器的repodata更改
時,會提醒本地更新repodata文件夾信息
yum repository: yum repo,存儲了眾多rpm包,以及包的相關的元數據文件(放置于特定目錄repodata下)
文件服務器:
ftp:// (表示使用ftp服務)
http://(表示使用http服務)
file:/// (表示使用本地文件)
2)yum配置文件
(1)/etc/yum.conf:為所有倉庫提供公共配置
[main] cachedir=/var/cache/yum/$basearch/$releasever //rpm包的緩存目錄 keepcache=0 //是否保持緩存,1是2否 debuglevel=2 // logfile=/var/log/yum.log //yum日志文件 exactarch=1 obsoletes=1 gpgcheck=1 //是否檢查簽名信息,1代表是 plugins=1 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release # This is the default, if you make this bigger yum won't see if the metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important, to have correct metadata, for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage, it's much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d
(2)/etc/yum.repos.d/*.repo:為倉庫的指向提供配置
[repositoryID] //軟件源的名稱,將被yum識別 name=NAME //當前倉庫的描述信息 baseurl=url://path/to/repository/ / /path/to/repository為文件服務器上的repodata的父目錄 enabled={1|0} //表示是否啟用,0表示禁用 gpgcheck={1|0} //是否檢查簽名信息,1表示檢查 gpgkey=URL //用于校驗gpg的密鑰,URL表示其所在位置
URL通常分為三種格式,和文件服務器提供的服務有關,分為以下三類。
ftp:// (表示使用ftp服務)
http://(表示使用http服務)
file:/// (表示使用本地文件,通常為本地掛在鏡像光盤)
[root@localhost ~]# cat /etc/yum.repos.d/base.repo [base] name=shui baseurl= //表示使用http協議進行傳輸,后面跟的即路徑 gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
注意:上述路徑中可能會存在個別變量
$releaserver:當前OS的發行版的主版本號;
$arch:平臺
$basearch:基礎平臺
$YUM0-YUM9
實例: http://server/centos/$releasever/$basearch/ http://server/centos/7/x86_64 http://server/centos/6/i384
3)yum管理命令
(1)列表信息
顯示倉庫列表:repolist[all|enabled|disabled]
[root@localhost ~]# yum repolist Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile repo id repo name status !base shui 9,007 repolist: 9,007
顯示程序包 list
[root@localhost ~]# yum list Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile
(2)安裝程序包 install
install package1 [package2] […]
reinstall package1 [package2] […] (重新安裝)
(3)升級程序包:
update [package1] [package2] […]
downgrade package1 [package2] […] (降級)
(4)檢查可用升級:
check-update
(5)卸載程序包:
remove | erase package1 [package2] […]
[root@localhost ~]# yum remove tree Loaded plugins: fastestmirror, langpacks Resolving Dependencies --> Running transaction check ---> Package tree.x86_64 0:1.6.0-10.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================================== Removing: tree x86_64 1.6.0-10.el7 @base 87 k Transaction Summary ==================================================================================================================================================== Remove 1 Package Installed size: 87 k Is this ok [y/N]:
(6)查看程序包的infomation
[root@localhost ~]# yum info tree Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Installed Packages Name : tree Arch : x86_64 Version : 1.6.0 Release : 10.el7 Size : 87 k Repo : installed From repo : base Summary : File system tree viewer URL : http://mama.indstate.edu/users/ice/tree/ License : GPLv2+ Description : The tree utility recursively displays the contents of directories in a : tree-like format. Tree is basically a UNIX port of the DOS tree : utility.
(7)清理本地緩存:
clean [ packages | metadata | expire-cache | rpmdb| plugins | all ]
root@localhost ~]# yum makecache //構建yum緩存 Loaded plugins: fastestmirror, langpacks base | 3.6 kB 00:00:00 (1/2): base/other_db | 2.3 MB 00:00:00 (2/2): base/filelists_db | 6.2 MB 00:00:00 Loading mirror speeds from cached hostfile Metadata Cache Created [root@localhost ~]# cat /var/cache/yum/x86_64/7/ base/ c7-media/ CentOS7-Localsource/ extras/ .gpgkeyschecked.yum timedhosts timedhosts.txt [root@localhost ~]# cat /var/cache/yum/x86_64/7/ base/ c7-media/ CentOS7-Localsource/ extras/ .gpgkeyschecked.yum timedhosts timedhosts.txt [root@localhost ~]# cat /var/cache/yum/x86_64/7/base/ //查看其目錄錄下的內容,一會與清理元數據后對比 308b19b243c882f0278206ea4ffc4e120df78c0218867917916fd437e4d0ea49-filelists.sqlite.bz2 436345f4b666f0a461d479ccfabc2c22823d4f2173c2653e5250fea62f0afe98-c7-x86_64-comps.xml.gz 653b04e156ef4b2e3d35a01b04a148c046827373ccd79ec02091feef89170f77-other.sqlite.bz2 c6411f1cc8a000ed2b651b49134631d279abba1ec1f78e5dcca79a52d8c1eada-primary.sqlite.bz2 cachecookie gen/ packages/ repomd.xml [root@localhost ~]# yum clean metadata Loaded plugins: fastestmirror, langpacks Cleaning repos: base 4 metadata files removed 6 sqlite files removed 0 metadata files removed [root@localhost ~]# cat /var/cache/yum/x86_64/7/base/ gen/ packages/ //清理后只剩這兩個目錄
(8)搜索:search string1 [string2] […](模糊搜索)
[root@localhost ~]# yum search tree Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile ================================================================ N/S matched: tree ================================================================= maven-dependency-tree.noarch : Maven dependency tree artifact maven-dependency-tree-javadoc.noarch : Javadoc for maven-dependency-tree perl-File-CheckTree.noarch : Run many file-test checks on a tree perl-HTML-Tree.noarch : HTML tree handling modules for Perl perl-Tree-DAG_Node.noarch : Class for representing nodes in a tree perl-XML-TreeBuilder.noarch : Parser that builds a tree of XML::Element objects subscription-manager-plugin-ostree.x86_64 : A plugin for handling OSTree content. texlive-pst-tree.noarch : Trees, using pstricks texlive-pst-tree-doc.noarch : Documentation for pst-tree tree.x86_64 : File system tree viewer baobab.x86_64 : A graphical directory tree analyzer cscope.x86_64 : C source code tree search and browse tool drpmsync.x86_64 : Sync a file tree with deltarpms gitk.noarch : Git revision tree visualiser golang-src.noarch : Golang compiler source tree hardlink.x86_64 : Create a tree of hardlinks perl-Class-ISA.noarch : Report the search path for a class's ISA tree perl-File-Path.noarch : Create or remove directory trees perl-Test-ClassAPI.noarch : Provides basic first-pass API testing for large class trees perl-XML-Twig.noarch : Perl module for processing huge XML documents in tree mode perl-XML-XPathEngine.noarch : Re-usable XPath engine for DOM-like trees python-lxml.x86_64 : ElementTree-like Python bindings for libxml2 and libxslt Name and summary matches only, use "search all" for everything. [root@localhost ~]#
(9)查看yum事務歷史
[root@localhost ~]# yum history Loaded plugins: fastestmirror, langpacks ID | Login user | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 5 | root <root> | 2016-08-19 17:48 | Install | 1 4 | root <root> | 2016-08-19 17:48 | Erase | 1 3 | root <root> | 2016-08-18 09:24 | Install | 1 < 2 | root <root> | 2016-07-29 16:47 | Install | 50 >< 1 | System <unset> | 2016-07-25 20:07 | Install | 1171 > history list
4)yum日志
/var/log/yum.log
[root@localhost ~]# cat /var/log/yum.log Jul 29 16:47:37 Installed: perl-Test-Harness-3.28-3.el7.noarch Jul 29 16:47:37 Installed: perl-Pod-Parser-1.61-2.el7.noarch Jul 29 16:47:37 Installed: perl-XML-SAX-Base-1.08-7.el7.noarch Jul 29 16:47:38 Installed: perl-XML-NamespaceSupport-1.11-10.el7.noarch Jul 29 16:47:39 Installed: perl-XML-SAX-0.99-9.el7.noarch Jul 29 16:47:40 Installed: 1:perl-XML-LibXML-2.0018-5.el7.x86_64 Jul 29 16:47:41 Installed: perl-Pod-LaTeX-0.61-2.el7.noarch Jul 29 16:47:41 Installed: perl-Pod-Checker-1.60-2.el7.noarch Jul 29 16:47:41 Installed: perl-Pod-Plainer-1.03-4.el7.noarch Jul 29 16:47:42 Installed: perl-Test-Simple-0.98-243.el7.noarch Jul 29 16:47:42 Installed: redhat-lsb-submod-multimedia-4.1-27.el7.centos.1.x86_64 Jul 29 16:47:43 Installed: perl-local-lib-1.008010-3.el7.noarch Jul 29 16:47:44 Installed: libpng12-1.2.50-6.el7.x86_64 Jul 29 16:47:44 Installed: spax-1.5.2-13.el7.x86_64 Jul 29 16:47:45 Installed: perl-File-CheckTree-4.42-3.el7.noarch Jul 29 16:47:46 Installed: perl-Text-Unidecode-0.04-20.el7.noarch Jul 29 16:47:46 Installed: perl-Text-Soundex-3.04-4.el7.x86_64 Jul 29 16:47:46 Installed: foomatic-filters-4.0.9-8.el7.x86_64 Jul 29 16:47:47 Installed: 1:perl-FCGI-0.74-8.el7.x86_64 Jul 29 16:47:47 Installed: perl-CGI-3.63-4.el7.noarch Jul 29 16:47:47 Installed: perl-Class-ISA-0.36-1010.el7.noarch Jul 29 16:47:47 Installed: perl-autodie-2.16-2.el7.noarch Jul 29 16:47:48 Installed: systemtap-sdt-devel-2.8-10.el7.x86_64 Jul 29 16:47:48 Installed: patch-2.7.1-8.el7.x86_64 Jul 29 16:47:52 Installed: kernel-headers-3.10.0-327.el7.x86_64 Jul 29 16:47:54 Installed: glibc-headers-2.17-105.el7.x86_64 Jul 29 16:47:55 Installed: glibc-devel-2.17-105.el7.x86_64 Jul 29 16:47:55 Installed: libdb-devel-5.3.21-19.el7.x86_64 Jul 29 16:47:56 Installed: perl-Sys-Syslog-0.33-3.el7.x86_64 Jul 29 16:47:57 Installed: perl-Locale-Codes-3.26-2.el7.noarch Jul 29 16:47:57 Installed: perl-Env-1.04-2.el7.noarch Jul 29 16:47:57 Installed: gdbm-devel-1.10-8.el7.x86_64 Jul 29 16:47:57 Installed: perl-Locale-Maketext-1.23-3.el7.noarch Jul 29 16:47:58 Installed: m4-1.4.16-10.el7.x86_64 Jul 29 16:47:58 Installed: 1:perl-Digest-SHA-5.85-3.el7.x86_64 Jul 29 16:47:59 Installed: perl-ExtUtils-Manifest-1.61-244.el7.noarch Jul 29 16:47:59 Installed: perl-ExtUtils-MakeMaker-6.68-3.el7.noarch Jul 29 16:47:59 Installed: perl-ExtUtils-Install-1.58-286.el7.noarch Jul 29 16:48:00 Installed: 1:perl-ExtUtils-ParseXS-3.18-2.el7.noarch Jul 29 16:48:01 Installed: 4:perl-devel-5.16.3-286.el7.x86_64 Jul 29 16:48:02 Installed: perl-CPAN-1.9800-286.el7.noarch Jul 29 16:48:02 Installed: 1:perl-Module-Pluggable-4.8-3.el7.noarch Jul 29 16:48:02 Installed: perl-B-Lint-1.17-3.el7.noarch Jul 29 16:48:03 Installed: redhat-lsb-submod-security-4.1-27.el7.centos.1.x86_64 Jul 29 16:48:03 Installed: redhat-lsb-core-4.1-27.el7.centos.1.x86_64 Jul 29 16:48:04 Installed: redhat-lsb-desktop-4.1-27.el7.centos.1.x86_64 Jul 29 16:48:04 Installed: redhat-lsb-languages-4.1-27.el7.centos.1.x86_64 Jul 29 16:48:04 Installed: redhat-lsb-printing-4.1-27.el7.centos.1.x86_64 Jul 29 16:48:04 Installed: redhat-lsb-cxx-4.1-27.el7.centos.1.x86_64 Jul 29 16:48:05 Installed: redhat-lsb-4.1-27.el7.centos.1.x86_64 Aug 18 09:25:00 Installed: ftp-0.17-66.el7.x86_64 Aug 19 17:48:27 Erased: tree-1.6.0-10.el7.x86_64 Aug 19 17:48:37 Installed: tree-1.6.0-10.el7.x86_64 [root@localhost ~]#
從上面的日志信息,yum日志記錄的是yum裝過或者卸載的所有的包的信息。
5)程序包組管理 group
(1)列出所有包組
[root@localhost ~]# yum grouplist Loaded plugins: fastestmirror, langpacks There is no installed groups file. Maybe run: yum groups mark convert (see man yum) base | 3.6 kB 00:00:00 (1/2): base/group_gz | 155 kB 00:00:00 (2/2): base/primary_db | 5.3 MB 00:00:00 Determining fastest mirrors Available Environment Groups: Minimal Install Compute Node Infrastructure Server File and Print Server Basic Web Server Virtualization Host Server with GUI GNOME Desktop KDE Plasma Workspaces Development and Creative Workstation Available Groups: Compatibility Libraries Console Internet Tools Development Tools Graphical Administration Tools Legacy UNIX Compatibility Scientific Support Security Tools Smart Card Support System Administration Tools System Management Done [root@localhost ~]#
(2)安裝程序組
groupinstall 組名
[root@localhost ~]# yum groupinstall "Development Tools" //yum groupinstall 組名 Loaded plugins: fastestmirror, langpacks There is no installed groups file. Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package autoconf.noarch 0:2.69-11.el7 will be installed ---> Package automake.noarch 0:1.13.4-3.el7 will be installed --> Processing Dependency: perl(Thread::Queue) for package: automake-1.13.4-3.el7.noarch ---> Package bison.x86_64 0:2.7-4.el7 will be installed ---> Package byacc.x86_64 0:1.9.20130304-3.el7 will be installed ---> Package cscope.x86_64 0:15.8-7.el7 will be installed ---> Package ctags.x86_64 0:5.8-13.el7 will be installed ---> Package diffstat.x86_64 0:1.57-4.el7 will be installed ---> Package doxygen.x86_64 1:1.8.5-3.el7 will be installed ---> Package flex.x86_64 0:2.5.37-3.el7 will be installed ---> Package gcc.x86_64 0:4.8.5-4.el7 will be installed ---> Package gcc-c++.x86_64 0:4.8.5-4.el7 will be installed
(3)移除程序組
groupremove group1
[root@localhost ~]# yum groupremove "Basic Web Server" Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile No group named Basic Web Server exists Resolving Dependencies --> Running transaction check ---> Package crypto-utils.x86_64 0:2.4.1-42.el7 will be erased ---> Package httpd.x86_64 0:2.4.6-40.el7.centos will be erased ---> Package httpd-manual.noarch 0:2.4.6-40.el7.centos will be erased ---> Package mod_fcgid.x86_64 0:2.3.9-4.el7 will be erased ---> Package mod_ssl.x86_64 1:2.4.6-40.el7.centos will be erased --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================================== Removing: crypto-utils x86_64 2.4.1-42.el7 @base 179 k httpd x86_64 2.4.6-40.el7.centos @base 9.4 M httpd-manual noarch 2.4.6-40.el7.centos @base 5.5 M mod_fcgid x86_64 2.3.9-4.el7 @base 228 k mod_ssl x86_64 1:2.4.6-40.el7.centos @base 224 k Transaction Summary ==================================================================================================================================================== Remove 5 Packages Installed size: 15 M Is this ok [y/N]:
注意:因為測試需要,所以我事先安裝了Basic Web Server這個組
(4)顯示某包組的信息
groupinfogroup1 […]
[root@localhost ~]# yum groupinfo "Basic Web Server" Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Environment Group: Basic Web Server Environment-Id: web-server-environment Description: Server for serving static and dynamic internet content. Mandatory Groups: +base +core +web-server Optional Groups: +backup-client +debugging +directory-client +guest-agents +hardware-monitoring +java-platform +large-systems +load-balancer +mariadb-client +network-file-system-client +performance +perl-web +php +postgresql-client +python-web +remote-system-management +web-servlet [root@localhost ~]#
(5)升級程序包組
groupupdategroup1 [group2] […]
[root@localhost ~]# yum groupupdate "Basic Web Server" Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package crypto-utils.x86_64 0:2.4.1-42.el7 will be installed ---> Package httpd.x86_64 0:2.4.6-40.el7.centos will be installed ---> Package httpd-manual.noarch 0:2.4.6-40.el7.centos will be installed ---> Package mod_fcgid.x86_64 0:2.3.9-4.el7 will be installed ---> Package mod_ssl.x86_64 1:2.4.6-40.el7.centos will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================================== Installing for group upgrade "Web Server": crypto-utils x86_64 2.4.1-42.el7 base 78 k httpd x86_64 2.4.6-40.el7.centos base 2.7 M httpd-manual noarch 2.4.6-40.el7.centos base 1.3 M mod_fcgid x86_64 2.3.9-4.el7 base 79 k mod_ssl x86_64 1:2.4.6-40.el7.centos base 103 k Transaction Summary ==================================================================================================================================================== Install 5 Packages Total download size: 4.3 M Installed size: 15 M Is this ok [y/d/N]:
謝謝瀏覽..
原創文章,作者:我的滑板鞋,如若轉載,請注明出處:http://www.www58058.com/37988
寫的不錯,圖文并貌,有理論也有實踐。繼續保持。