yum,Yellowdog Update Modifier是redhat系列发行版的一个前端包管理器,可以有效的解决包依赖关系,然而其底层调用的是rpm这个后端程序
RPM
包管理器
程序包管理器:
功能:将编译好的应用程序的各组成文件打包一个或几个程序包文件,从而方便快捷地实现程序包的安装、卸载、查询、升级和校验等管理操作
包文件组成 (每个包独有)
RPM包内的文件
RPM的元数据,如名称,版本,依赖性,描述等
安装或卸载时运行的脚本
数据库(公共):/var/lib/rpm
程序包名称及版本
依赖关系
功能说明
包安装后生成的各文件路径及校验码信息
[root@centos6 ~]# ll /var/lib/rpm
total 77796
-rw-r--r--. 1 root root 5521408 Apr 20 09:46 Basenames
-rw-r--r--. 1 root root 12288 Apr 10 16:05 Conflictname
-rw-r--r-- 1 root root 73728 Apr 20 09:59 __db.001
-rw-r--r-- 1 root root 237568 Apr 20 09:59 __db.002
-rw-r--r-- 1 root root 1318912 Apr 20 09:59 __db.003
-rw-r--r-- 1 root root 753664 Apr 20 09:59 __db.004
-rw-r--r--. 1 root root 1552384 Apr 20 09:46 Dirnames
-rw-r--r--. 1 root root 10555392 Apr 20 09:46 Filedigests
-rw-r--r--. 1 root root 20480 Apr 20 09:46 Group
-rw-r--r--. 1 root root 20480 Apr 20 09:46 Installtid
-rw-r--r--. 1 root root 86016 Apr 20 09:46 Name
-rw-r--r--. 1 root root 24576 Apr 17 16:08 Obsoletename
-rw-r--r--. 1 root root 60223488 Apr 20 09:46 Packages
-rw-r--r--. 1 root root 1327104 Apr 20 09:46 Providename
-rw-r--r--. 1 root root 700416 Apr 20 09:46 Provideversion
-rw-r--r--. 1 root root 12288 Mar 27 17:00 Pubkeys
-rw-r--r--. 1 root root 516096 Apr 20 09:46 Requirename
-rw-r--r--. 1 root root 303104 Apr 20 09:46 Requireversion
-rw-r--r--. 1 root root 172032 Apr 20 09:46 Sha1header
-rw-r--r--. 1 root root 86016 Apr 20 09:46 Sigmd5
-rw-r--r--. 1 root root 12288 Mar 27 17:10 Triggername
程序包的来源
管理程序包的方式:
使用包管理器:rpm
使用前端工具:yum
获取程序包的途径:
(1) 系统发版的光盘或官方的服务器;
CentOS镜像:
https://www.centos.org/download/
http://mirrors.aliyun.com
http://mirrors.sohu.com
http://mirrors.163.com
(2) 项目官方站点
(3) 第三方组织:
Fedora-EPEL:
Extra Packages for Enterprise Linux
Rpmforge:RHEL推荐,包很全
搜索引擎:
http://pkgs.org
http://rpmfind.net
http://rpm.pbone.net
https://sourceforge.net/
(4) 自己制作
注意:第三方包建议要检查其合法性 来源合法性,程序包的完整性
rpm包管理
CentOS系统上使用rpm命令管理程序包:
安装、卸载、升级、查询、校验、数据库维护
安装:
rpm {-i|--install} [install-options] PACKAGE_FILE…
-v: verbose
-vv:
-h: 以#显示程序包管理执行进度
常用搭配:rpm -ivh PACKAGE_FILE ...
[root@centos6 Packages]# rpm -ivh finger-0.17-40.el6.x86_64.rpm
warning: finger-0.17-40.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:finger ########################################### [100%]
注:rpm后面只能跟文件名,而不能跟finger包名,其不能识别finger整个文件名
rpm包安装
[install-options]
--test: 测试安装,但不真正执行安装,即dry run模式
--nodeps:忽略依赖关系
--replacepkgs | replacefiles
--nosignature: 不检查来源合法性
--nodigest:不检查包完整性
--noscripts:不执行程序包脚本
%pre: 安装前脚本; --nopre
%post: 安装后脚本; --nopost
%preun: 卸载前脚本; --nopreun
%postun: 卸载后脚本;--nopostun
[root@centos6 Packages]# rpm -ivh --test kernel-2.6.32-696.el6.x86_64.rpm
warning: kernel-2.6.32-696.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
package kernel-3.18.12-11.el6.x86_64 (which is newer than kernel-2.6.32-696.el6.x86_64) is already installed
package kernel-2.6.32-696.el6.x86_64 is already installed
rpm包升级
升级:
rpm {-U|--upgrade} [install-options] PACKAGE_FILE...
rpm {-F|--freshen} [install-options] PACKAGE_FILE...
upgrade:安装有旧版程序包,则“升级” ,如果不存在旧版程序包,则“安装”
freshen:安装有旧版程序包,则“升级” ,如果不存在旧版程序包,则不执行升级操作
常用搭配:
rpm -Uvh PACKAGE_FILE ...
rpm -Fvh PACKAGE_FILE ...
--oldpackage:降级
--force: 强制安装
升级注意项
注意:
(1) 不要对内核做升级操作;Linux支持多内核版本并存,因此,对直接安装新版本内核
(2) 如果原程序包的配置文件安装后曾被修改,升级时,新版本的提供的同一个配置文件并不会直接覆盖老版本的配置文件,而把新版本的文件重命名(FILENAME.rpmnew)后保留
rpm包查询
rpm {-q|--query} [select-options] [query-options]
[select-options]
-a: 所有包
-f: 查看指定的文件由哪个程序包安装生成
-p rpmfile:针对尚未安装的程序包文件做查询操作
--whatprovides CAPABILITY:查询指定的CAPABILITY由哪个包所提供
--whatrequires CAPABILITY:查询指定的CAPABILITY被哪个包所依赖
rpm2cpio 包文件|cpio –itv 预览包内文件
rpm2cpio 包文件|cpio –id “*.conf” 释放包内文件
[query-options]
--changelog:查询rpm包的changelog
-c: 查询程序的配置文件
-d: 查询程序的文档
-i: information
-l: 查看指定的程序包安装后生成的所有文件
--scripts:程序包自带的脚本
--provides: 列出指定程序包所提供的CAPABILITY
-R: 查询指定的程序包所依赖的CAPABILITY
常用查询用法:
-qi PACKAGE, -qf FILE, -qc PACKAGE, -ql PACKAGE, -qd PACKAGE -qpi PACKAGE_FILE, -qpl PACKAGE_FILE, ... -qa
查看已安装包信息
[root@centos6 ~]# rpm -qi bash
Name : bash Relocations: (not relocatable)
Version : 4.1.2 Vendor: CentOS
Release : 48.el6 Build Date: Thu 23 Mar 2017 08:17:20 AM CST
Install Date: Tue 27 Mar 2018 05:00:50 PM CST Build Host: c1bm.rdu2.centos.org
Group : System Environment/Shells Source RPM: bash-4.1.2-48.el6.src.rpm
Size : 3142529 License: GPLv3+
Signature : RSA/SHA1, Thu 23 Mar 2017 10:59:39 PM CST, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
URL : http://www.gnu.org/software/bash
Summary : The GNU Bourne Again shell
Description :
The GNU Bourne Again shell (Bash) is a shell or command language
interpreter that is compatible with the Bourne shell (sh). Bash
incorporates useful features from the Korn shell (ksh) and the C shell
(csh). Most sh scripts can be run by bash without modification.
查询生成的文件是由那个包提供
[root@centos6 ~]# rpm -qf /bin/ls
coreutils-8.4-46.el6.x86_64
查看包生成的配置文件
[root@centos6 ~]# rpm -qc bash
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc
查看包生成的所有文件
[root@centos6 ~]# rpm -ql finger
/usr/bin/finger
/usr/share/man/man1/finger.1.gz
查看问安装包信息,后必须跟文件名
[root@centos6 Packages]# rpm -ivh finger-0.17-40.el6.x86_64.rpm
warning: finger-0.17-40.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:finger ########################################### [100%]
[root@centos6 Packages]# rpm -qpi tree-1.5.3-3.el6.x86_64.rpm
warning: tree-1.5.3-3.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Name : tree Relocations: (not relocatable)
Version : 1.5.3 Vendor: CentOS
Release : 3.el6 Build Date: Wed 14 Jan 2015 08:21:02 PM CST
Install Date: (not installed) Build Host: c6b9.bsys.dev.centos.org
Group : Applications/File Source RPM: tree-1.5.3-3.el6.src.rpm
Size : 66687 License: GPLv2+
Signature : RSA/SHA1, Wed 14 Jan 2015 10:12:21 PM CST, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
URL : http://mama.indstate.edu/users/ice/tree/
Summary : File system tree viewer
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.
包卸载:
rpm {-e|--erase} [--allmatches] [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...
包校验
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
已安装包来源合法性验正及完整性验正
[root@centos6 Packages]# cat >> /usr/bin/zip
[root@centos6 Packages]# rpm -V zip
prelink: /usr/bin/zip: prelinked file size differs
S.?....T. /usr/bin/zip
完整性验正:SHA256
来源合法性验正:RSA
公钥加密
对称加密:加密、解密使用同一密钥
非对称加密:密钥是成对儿的
public key: 公钥,公开所有人
secret key: 私钥, 不能公开
导入所需要公钥
rpm -K|checksig rpmfile 检查包的完整性和签名
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
CentOS 7发行版光盘提供:RPM-GPG-KEY-CentOS-7
rpm -qa “gpg-pubkey*”
导入公钥,检查包完整性
[root@centos6 date]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[root@centos6 date]# rpm -K /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm
/misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
rpm数据库
数据库重建: /var/lib/rpm
rpm {--initdb|--rebuilddb}
initdb: 初始化 ,如果事先不存在数据库,则新建之 否则,不执行任何操作
rebuilddb:重建已安装的包头的数据库索引目录
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/96602

