rpm和yum程序包的管理
rpm简介:
RPM,是RPM Package Manager(RPM软件包管理器)的缩写,这一文件格式名称虽然打上了RedHat的标志,但是其原始设计理念是开放式的,现在包括OpenLinux、S.u.S.E.以及Turbo Linux等Linux的分发版本都有采用,可以算是公认的行业标准了。
程序包管理:
内核功能:进程管理、内存管理、网络协议栈、驱动程序、...
应用程序:由二进制程序、管理程序文件、配置文件、文档文件、帮助手册文件组成
程序包的组成部分:
二进制程序:/bin, /sbin,/ /usr/bin, /usr/sbin;
库文件:/lib64, /usr/lib64;
配置文件:/etc;
帮助文件:/usr/share/man
软件手册:/usr/share/doc
linux软件包类型:
deb:debian
rpm:redhat package manager
tar:linux系统的打包工具tar打包的
bin:有些Linux软件不公开源代码,只发布二进制可执行程序,这类程序一般会以bin来标记
分包机制:
testapp-VERSION.tar.gz
核心包:testapp-VERSION
支包:testapp-devel-VERSION
VERSION:major.minor.release
列子:software-1.2.3-1.tar.gz
软件名称:ase | 版本号:4.2.4 | 修正版本:1 | 包类型:tar.gz
rpm包的命名机制:
name-VERSION-RELEASE.ARCH.rpm
bash-4.2.4-1.el7.x86_64.rpm
bash-devel-4.2.4-1.el7.x86_64.rpm
RELEASE: rpm release
例子:sfotware-1.2.3-1.i386.rpm
软件名称:software | 版本号:1.2.3 |修正版本:1 |可用平台:i386,x86平台 | 类型:rpm
包和包之间:有可能存在依赖关系:
X --> Y --> Z
基于rpm命令实现程序包管理:
rpm数据库:/var/lib/rpm/
如何获取rpm包:
1、发行版提供的程序包;
2、Fedora-EPEL
3、项目的官方站点
4、本地光盘
5、搜索引擎
安装:
rpm {-i|--install} [install-options] PACKAGE_FILE ...
-i:install package(s)
-v:显示详细过程,-vv, -vvv
-h:打印软件包安装过程
例子:安装一个RPM包
[root@localhost /]# mount /dev/cdrom /media/ #挂载光盘 mount: block device /dev/sr0 is write-protected, mounting read-only [root@localhost /]# cd /media/Packages/ #切换RPM目录 [root@localhost Packages]# rpm -ivh zsh-4.3.11-4.el6.centos.x86_64.rpm #安装zshRPM包 warning: zsh-4.3.11-4.el6.centos.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:zsh ########################################### [100%]
每个rpm包都提供一个或多个capabilities
--nodeps:忽略依赖关系安装
--replacepkgs:重装程序包
例子:遇到依赖关系怎么处理?
[root@localhost Packages]# rpm -ivh mysql-server-5.1.73-5.el6_6.x86_64.rpm #安装mysql-server warning: mysql-server-5.1.73-5.el6_6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY error: Failed dependencies: #发生依赖关系 mysql = 5.1.73-5.el6_6 is needed by mysql-server-5.1.73-5.el6_6.x86_64 perl(DBI) is needed by mysql-server-5.1.73-5.el6_6.x86_64 perl-DBD-MySQL is needed by mysql-server-5.1.73-5.el6_6.x86_64 perl-DBI is needed by mysql-server-5.1.73-5.el6_6.x86_64 [root@localhost Packages]# rpm -ivh mysql-server-5.1.73-5.el6_6.x86_64.rpm perl-DBD-MySQL-4.013-3.el6.x86_64.rpm perl-DBI-1.609-4.el6.x86_64.rpm mysql-5.1.73-5.el6_6.x86_64.rpm #逐一安装所依赖的包 warning: mysql-server-5.1.73-5.el6_6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:perl-DBI ########################################### [ 25%] 2:perl-DBD-MySQL ########################################### [ 50%] 3:mysql ########################################### [ 75%] 4:mysql-server ########################################### [100%] [root@localhost Packages]# rpm -qa | grep mysql #查询mysql是否安装完毕 mysql-server-5.1.73-5.el6_6.x86_64 mysql-libs-5.1.73-5.el6_6.x86_64 mysql-5.1.73-5.el6_6.x86_64
例子:忽略依赖关系,强行安装(一般不建议这样做)
[root@localhost Packages]# rpm -ivh mysql-server-5.1.73-5.el6_6.x86_64.rpm --nodeps #强制安装参数 warning: mysql-server-5.1.73-5.el6_6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:mysql-server ########################################### [100%]
升级:
-Uvh: 如果有旧版程序包,则升级之;如果没有,则安装之;
-Fvh: 如果有旧版程序包,则升级之;如果没有,则不安装;
--nodeps
--oldpackage:降级;
--force:
例子:升级RPM包
[root@localhost soft]# ls #先去相关站点找到最新软件包下载 sudo-1.8.6p3-20.el6_7.x86_64.rpm VMwareTools-9.6.1-1378637.tar.gz sudo-devel-1.8.6p3-20.el6_7.i686.rpm vmware-tools-distrib sudo-devel-1.8.6p3-20.el6_7.x86_64.rpm [root@localhost soft]# rpm -qa | grep sudo sudo-1.8.6p3-19.el6.x86_64 [root@localhost soft]# rpm -Uvh sudo-1.8.6p3-20.el6_7.x86_64.rpm #进行升级 warning: sudo-1.8.6p3-20.el6_7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:sudo ########################################### [100%] [root@localhost soft]# rpm -qa | grep sudo #查询已经是最新版本 sudo-1.8.6p3-20.el6_7.x86_64
卸载:
rpm {-e|--erase} [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...
例子:
[root@localhost Packages]# rpm -e zsh-4.3.11-4.el6.centos.x86_64 [root@localhost Packages]# rpm -e zsh-4.3.11-4.el6.centos.x86_64 --nodeps
查询:
-qa: 查询本机已经安装的所有程序包;
-qf /PATH/TO/SOMEFILE: 查询此处的文件由哪个程序包安装生成;
-qc: 查询指定程序包安装生成的配置文件
-qd: 查询指定的程序包安装生成的文档
-qi: 查询指定的程序包的相关信息;
-ql: 查询程序包安装生成的所有文件的列表;
-q --scripts:查询程序包相关的脚本:
preinstall: 安装前脚本
postinstall:安装后脚本
preuninstall: 卸载前脚本
postuninstall: 卸载后脚本
-p: 查询针对是未安装的程序包文件;
例子:相关查询命令使用
[root@localhost Packages]# rpm -qa | grep ^httpd #查询httpd是否安装 httpd-tools-2.2.15-45.el6.centos.x86_64 httpd-2.2.15-45.el6.centos.x86_64 [root@localhost Packages]# rpm -qf /etc/httpd/conf/httpd.conf httpd-2.2.15-45.el6.centos.x86_64 [root@localhost Packages]# rpm -qc httpd /etc/httpd/conf.d/welcome.conf /etc/httpd/conf/httpd.conf /etc/httpd/conf/magic /etc/logrotate.d/httpd /etc/sysconfig/htcacheclean /etc/sysconfig/httpd ..... [root@localhost Packages]# rpm -qd httpd #查询httpd安装生成的相关文档 /usr/share/doc/httpd-2.2.15/ABOUT_APACHE /usr/share/doc/httpd-2.2.15/CHANGES /usr/share/doc/httpd-2.2.15/LICENSE /usr/share/doc/httpd-2.2.15/NOTICE /usr/share/doc/httpd-2.2.15/README /usr/share/doc/httpd-2.2.15/VERSIONING ..... [root@localhost Packages]# rpm -qi httpd #查询httpd软件包的相关信息 Name : httpd Relocations: (not relocatable) Version : 2.2.15 Vendor: CentOS Release : 45.el6.centos Build Date: 2015年07月24日 星期五 19时53分33秒 Install Date: 2015年08月25日 星期二 21时15分23秒 Build Host: c6b9.bsys.dev.centos.org Group : System Environment/Daemons Source RPM: httpd-2.2.15-45.el6.centos.src.rpm Size : 3090869 License: ASL 2.0 Signature : RSA/SHA1, 2015年07月25日 星期六 04时42分58秒, Key ID 0946fca2c105b9de Packager : CentOS BuildSystem <http://bugs.centos.org> URL : http://httpd.apache.org/ Summary : Apache HTTP Server Description : The Apache HTTP Server is a powerful, efficient, and extensible web server. [root@localhost Packages]# rpm -ql httpd #查询httpd程序包安装生成的所有文件的列表 /etc/httpd /etc/httpd/conf /etc/httpd/conf.d /etc/httpd/conf.d/README /etc/httpd/conf.d/welcome.conf /etc/httpd/conf/httpd.conf /etc/httpd/conf/magic /etc/httpd/logs /etc/httpd/modules /etc/httpd/run /etc/logrotate.d/httpd /etc/rc.d/init.d/htcacheclean /etc/rc.d/init.d/httpd /etc/sysconfig/htcacheclean /etc/sysconfig/httpd ...... [root@localhost Packages]# rpm -q --scripts httpd #查询httpd所要执行的相关脚本 preinstall scriptlet (using /bin/sh): #安装前 # Add the "apache" user getent group apache >/dev/null || groupadd -g 48 -r apache getent passwd apache >/dev/null || useradd -r -u 48 -g apache -s /sbin/nologin -d /var/www -c "Apache" apache exit 0 postinstall scriptlet (using /bin/sh): #安装后 # Register the httpd service /sbin/chkconfig --add httpd /sbin/chkconfig --add htcacheclean preuninstall scriptlet (using /bin/sh): #卸载前 if [ $1 = 0 ]; then /sbin/service httpd stop > /dev/null 2>&1 /sbin/chkconfig --del httpd /sbin/service htcacheclean stop > /dev/null 2>&1 /sbin/chkconfig --del htcacheclean fi posttrans scriptlet (using /bin/sh): #卸载后 test -f /etc/sysconfig/httpd-disable-posttrans || /sbin/service httpd condrestart >/dev/null 2>&1 || : [root@localhost Packages]# rpm -qR zsh #查询软件所依赖的服务器库 /bin/sh /bin/sh /bin/sh /bin/sh /bin/zsh /sbin/install-info /sbin/install-info config(zsh) = 4.3.11-4.el6.centos coreutils grep grep libc.so.6()(64bit) libc.so.6(GLIBC_2.11)(64bit) libc.so.6(GLIBC_2.2.5)(64bit) [root@localhost Packages]# rpm -qpi php-5.3.3-40.el6_6.x86_64.rpm #查询未安装的软件信息(需要加p选项) warning: php-5.3.3-40.el6_6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Name : php Relocations: (not relocatable) Version : 5.3.3 Vendor: CentOS Release : 40.el6_6 Build Date: 2014年10月31日 星期五 04时22分27秒 Install Date: (not installed) Build Host: c6b8.bsys.dev.centos.org Group : Development/Languages Source RPM: php-5.3.3-40.el6_6.src.rpm Size : 3702253 License: PHP Signature : RSA/SHA1, 2014年10月31日 星期五 21时11分06秒, Key ID 0946fca2c105b9de Packager : CentOS BuildSystem <http://bugs.centos.org> URL : http://www.php.net/ Summary : PHP scripting language for creating dynamic web sites Description : PHP is an HTML-embedded scripting language. PHP attempts to make it easy for developers to write dynamically generated webpages. PHP also offers built-in database integration for several commercial and non-commercial database management systems, so writing a database-enabled webpage with PHP is fairly simple. The most common use of PHP coding is probably as a replacement for CGI scripts. The php package contains the module which adds support for the PHP language to Apache HTTP Server.
校验:
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---MD5文件校验码发生变化
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@localhost Packages]# rpm -ql zsh #查询zsh文件的相关所有文件 [root@localhost Packages]# vim /usr/share/zsh/4.3.11/functions/zftype #修改zsh相关的文件 [root@localhost Packages]# rpm -V zsh #校验软件包 S.5....T. /usr/share/zsh/4.3.11/functions/zftype
包校验:
来源合法性验正:非对称加密
完整性验正:单向加密
导入密钥:rpm --import /PATH/TO/KEY_FILE
校验:rpm -K /PATH/TO/RPM_FILE
例子:导入密钥
[root@localhost media]# rpm --import RPM-GPG-KEY-CentOS-6 [root@localhost media]# cd Packages/ [root@localhost Packages]# rpm -ivh zsh-4.3.11-4.el6.centos.x86_64.rpm Preparing... ########################################### [100%] 1:zsh ########################################### [100%]
yum简介:
Yum(全称为 Yellow dog Updater, Modified),是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。
文件服务器:
ftp://hostname/PATH/TO/REPO
http://hostname/PATH/TO/REPO
file:///PATH/TO/REPO
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=
例子:配置实例
[a] name=a #定义yum源名字 baseurl=file:///media #来源仓库类型 gpgcheck=0 #关闭校验 enabled=1 #开启本源 [163] name=163yum #定义yum源名字 baserul=http://mirrors.163.com/centos/6.7/os/x86_64/ #来源仓库类型 gpgcheck=0 #关闭校验 enabled=1 #开启本源
定义仓库指向可用变量:
$releasever: 引用当前系统的主版本号;
$basearch: 当前系统的基本架构;
i386, i486, i586, i686: i386
http://mirrors.magedu.com/CentOS/$releasever/os/$basearch
yum命令:
yum [options] [command] [package ...]
命令:
安装:install
卸载:remove
升级:update
查询:
info
search KEYWORD
list all|installed|availiable
provides /PATH/TO/SOMEFILE: 查询指定文件由哪个包安装生成
重新安装:reinstall
降级:downgrade
清理缓存:clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
生动生成缓存:makecache
例子:yum命令相关操作
[root@localhost yum.repos.d]# yum clean all #清理yum所有缓存 已加载插件:fastestmirror, refresh-packagekit, security Cleaning repos: 163 a 清理一切 Cleaning up list of fastest mirrors [root@localhost yum.repos.d]# yum makecache #刷新yum缓存(一般是有新的yum仓库) 已加载插件:fastestmirror, refresh-packagekit, security Determining fastest mirrors 163 | 3.7 kB 00:00 163/group_gz | 219 kB 00:00 163/filelists_db | 6.3 MB 00:13 163/primary_db | 4.6 MB 00:09 163/other_db | 2.8 MB 00:06 a | 4.0 kB 00:00 ... a/group_gz | 219 kB 00:00 ... a/filelists_db | 6.2 MB 00:00 ... a/primary_db | 4.6 MB 00:00 ... a/other_db | 2.8 MB 00:00 ... 元数据缓存已建立 [root@localhost yum.repos.d]# yum remove wget telnet -y #安装wget 和telnet 已安装: telnet.x86_64 1:0.17-48.el6 wget.x86_64 0:1.12-5.el6_6.1 完毕! [root@localhost yum.repos.d]# yum remove wget telnet -y #卸载wget和telnet 删除: telnet.x86_64 1:0.17-48.el6 wget.x86_64 0:1.12-5.el6_6.1 完毕! [root@localhost yum.repos.d]# yum list #查询当前源所有安装包 [root@localhost yum.repos.d]# yum list installed #查询所有以安装的包 [root@localhost yum.repos.d]# yum list all #查询所有安装和源仓库的包 [root@localhost yum.repos.d]# yum info php-mysql #查询指定软件的相关信息 已加载插件:fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile 可安装的软件包 Name : php-mysql Arch : x86_64 Version : 5.3.3 Release : 40.el6_6 Size : 84 k Repo : 163 Summary : A module for PHP applications that use MySQL databases URL : http://www.php.net/ License : PHP Description : The php-mysql package contains a dynamic shared object that will add : MySQL database support to PHP. MySQL is an object-relational database : management system. PHP is an HTML-embeddable scripting language. If : you need MySQL support for PHP applications, you will need to install : this package and the php package. [root@localhost yum.repos.d]# yum provides /etc/fstab #查询指定文件的安装包 已加载插件:fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile setup-2.8.14-20.el6_4.1.noarch : A set of system configuration and setup files Repo : 163 匹配来自于: Filename : /etc/fstab setup-2.8.14-20.el6_4.1.noarch : A set of system configuration and setup files Repo : a 匹配来自于: Filename : /etc/fstab setup-2.8.14-20.el6_4.1.noarch : A set of system configuration and setup files Repo : installed 匹配来自于: Other : 提供依赖满足:/etc/fstab
包组:
grouplist
groupinfo "GRP_NAME"
groupinstall "GRP_NAME"
groupremove "GRP_NAME"
例子:安装一个仓库组
[root@localhost yum.repos.d]# yum groupinstall "Development Tools" -y
仓库:
repolist [all|enabled|disabled]
repoinfo [all|enabled|disabled]
例子:查看当前yum仓库有哪些
[root@localhost yum.repos.d]# yum repolist 已加载插件:fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile 仓库标识 仓库名称 状态 163 163yum 6,575 a a 6,575 repolist: 13,150
创建本地仓库(首先要安装http或ftp服务等):
yum install createrepo
createrepo /PATH/TO/RPMFILES/
本文出自 “做自己想做的事!” 博客,转载请与作者联系!
原文地址:http://807257775.blog.51cto.com/2448194/1694368