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.178linux.com/37988
评论列表(1条)
写的不错,图文并貌,有理论也有实践。继续保持。