程序包的组成部分
二进制程序:/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin
库文件:/lib64 /usr/lib64 (64位系统)
配置文件:/etc 下子目录
帮助文档:manual、readme、info等
包管理器功能:
打包、安装、卸载、升级、查询、校验
程序包分包机制:(哲学思想:每一个包实现一种功能,组合小程序完成复杂任务)
核心包
支包
程序包命名机制:major.minor.release
rpm包命名:name-version-release.arch.rpm
release 是rpm的release,而不是源代码的release
rpm公共数据库/var/lib/rpm/
重建数据库
rpm {--initdb|--rebuilddb}
初始化:--initdb
如果事先不存在数据,则会新之;否则,不执行任何操作
重新构建:--rebuilddb
无论当前是否已经存在数据库,都会直接重建并覆盖现有数据库;
获取程序包的途径:
发行版提供的程序包
fedora-EPEL社区
项目的官方站点
搜索引擎(rpmfind.netrpm.pbone.netpkgs.org)
rpm命令
安装
rpm {-i|--install} [install-options] PACKAGE_FILE ...
-ivh或者-ivvh 可以显示更详细安装情况
[root@localhost Packages]# rpm -ivh ftp-0.17-54.el6.x86_64.rpm Preparing... ########################################### [100%] 1:ftp ########################################### [100%]
安装选项
--repleasepkgs重装
--nodeps 不检查依赖关系
[root@localhost Packages]# rpm -q ftp#经查询已经安装 ftp-0.17-54.el6.x86_64 [root@localhost Packages]# rpm -ivh --replacepkgs ftp-0.17-54.el6.x86_64.rpm #加上--replacepkgs可以重复安装 Preparing... ########################################### [100%] 1:ftp ########################################### [100%] [root@localhost Packages]# rpm -ivh ftp-0.17-54.el6.x86_64.rpm #但如果不加的话,会提示已经安装过的 Preparing... ########################################### [100%] package ftp-0.17-54.el6.x86_64 is already installed [root@localhost Packages]# [root@localhost Packages]# rpm -ivh php-5.3.3-40.el6_6.x86_64.rpm #安装php的主程序包时提示依赖php-cli error: Failed dependencies: php-cli(x86-64) = 5.3.3-40.el6_6 is needed by php-5.3.3-40.el6_6.x86_64 [root@localhost Packages]# rpm -ivh --nodeps php-5.3.3-40.el6_6.x86_64.rpm #安装时不检查依赖关系,不过这样安装可能导致软件不正常工作 Preparing... ########################################### [100%] 1:php ########################################### [100%] [root@localhost Packages]#
升级
-Uupdate如果旧版程序包存在则升级,不存在也安装
-Ffreshen如果旧版程序包存在则升级,不存在则不安装
[root@localhost Packages]# rpm -qa |grep zsh#查询已安装的包,筛选一下zsh,没有安装 [root@localhost Packages]# rpm -Uvh zsh-4.3.11-4.el6.centos.x86_64.rpm #使用-Uvh选项,如果没有安装则安装之 Preparing... ########################################### [100%] 1:zsh ########################################### [100%] [root@localhost Packages]# [root@localhost Packages]# rpm -qa |grep samba#筛选一下samba,并没有核心包,而是一堆支包 samba-common-3.6.23-20.el6.x86_64 samba-winbind-3.6.23-20.el6.x86_64 samba-winbind-clients-3.6.23-20.el6.x86_64 samba4-libs-4.0.0-66.el6_6.rc4.x86_64 samba-client-3.6.23-20.el6.x86_64 [root@localhost Packages]# rpm -Fvh samba-3.6.23-20.el6.x86_64.rpm #使用-Fvh选项,没有安装则不安装 [root@localhost Packages]# rpm -qa |grep samba#筛选出来依旧是samba的支包 samba-common-3.6.23-20.el6.x86_64 samba-winbind-3.6.23-20.el6.x86_64 samba-winbind-clients-3.6.23-20.el6.x86_64 samba4-libs-4.0.0-66.el6_6.rc4.x86_64 samba-client-3.6.23-20.el6.x86_64 [root@localhost Packages]#
--force强制
--oldpackage降级
[root@localhost Packages]# rpm -ivh --force --oldpackage samba-client-3.6.23-20.el6.x86_64.rpm #强制的安装,(虽然samba-client跟已安装的是相同版本) Preparing... ########################################### [100%] 1:samba-client ########################################### [100%] [root@localhost Packages]#
卸载
rpm {-e|--erase} [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...
[root@localhost Packages]# rpm -qa |grep samba#筛选出已安装的程序包全名 samba-common-3.6.23-20.el6.x86_64 samba-winbind-3.6.23-20.el6.x86_64 samba-client-3.6.23-20.el6.x86_64 samba-winbind-clients-3.6.23-20.el6.x86_64 samba4-libs-4.0.0-66.el6_6.rc4.x86_64 [root@localhost Packages]# rpm -e samba-common-3.6.23-20.el6.x86_64 #卸载包(程序包的全名),提示有依赖 error: Failed dependencies: samba-common = 0:3.6.23-20.el6 is needed by (installed) samba-winbind-0:3.6.23-20.el6.x86_64 samba-common = 0:3.6.23-20.el6 is needed by (installed) samba-client-0:3.6.23-20.el6.x86_64 [root@localhost Packages]# rpm -e --nodeps samba-common-3.6.23-20.el6.x86_64#忽略依赖卸载,卸载成功 [root@localhost Packages]#
查询
rpm {-q|--query} [select-options] [query-options]
-qa查询本机已安装的所有程序包
-qf/PATH/TO/SOMEFILE 查询文件是由哪个软件包生成的
-qcPACKAGE_NAME 查询指定程序包生成的配置文件
-qd PACKAGE_NAME 查询指定程序包生成的文档
-qiPACKAGE_NAME 查询指定程序包的相关信息
-ql PACKAGE_NAME 查询指定程序包安装生成的所有文件列表
-q --scriptsPACKAGE_NAME查询指定程序包相关脚本
preinstall安装前脚本
postinstall安装后脚本
preuninstall卸载前脚本
postuninstall卸载后脚本
-p查询未安装的程序包文件
[root@localhost Packages]# rpm -qa | wc -l 1126#本机已安装程序包数量1126个 [root@localhost Packages]# rpm -qf /etc/samba/smb.conf #查询smb.conf有由哪个程序包生成的 samba-common-3.6.23-20.el6.x86_64 [root@localhost Packages]# rpm -qa |grep samba samba-winbind-3.6.23-20.el6.x86_64 samba-client-3.6.23-20.el6.x86_64 samba-winbind-clients-3.6.23-20.el6.x86_64 samba4-libs-4.0.0-66.el6_6.rc4.x86_64 samba-3.6.23-20.el6.x86_64 samba-common-3.6.23-20.el6.x86_64 [root@localhost Packages]# rpm -qc samba-3.6.23-20.el6.x86_64#可以根据查找出来的程序包完整名字来进行查询 /etc/logrotate.d/samba /etc/pam.d/samba /etc/samba/smbusers [root@localhost Packages]# rpm -qc samba /etc/logrotate.d/samba /etc/pam.d/samba /etc/samba/smbusers [root@localhost Packages]# [root@localhost Packages]# rpm -qa|grep ftp vsftpd-2.2.2-14.el6.x86_64 gvfs-obexftp-1.4.3-22.el6.x86_64 [root@localhost Packages]# rpm -qc vsftpd#也可以根据程序包的名字进行查找生成了哪些配置文件(注意:写成vsftp或ftp都会报错) /etc/logrotate.d/vsftpd /etc/pam.d/vsftpd /etc/vsftpd/ftpusers /etc/vsftpd/user_list /etc/vsftpd/vsftpd.conf [root@localhost Packages]# rpm -qd vsftpd-2.2.2-14.el6.x86_64 #也可以写成rpm -qd vsftpd /usr/share/doc/vsftpd-2.2.2/AUDIT /usr/share/doc/vsftpd-2.2.2/BENCHMARKS /usr/share/doc/vsftpd-2.2.2/BUGS /usr/share/doc/vsftpd-2.2.2/COPYING /usr/share/doc/vsftpd-2.2.2/Changelog /usr/share/doc/vsftpd-2.2.2/EXAMPLE/INTERNET_SITE/README ……内容太多,省略 [root@localhost Packages]# rpm -qi samba#查看指定软件的相关信息(samba是主程序包) Name : samba Relocations: (not relocatable) Version : 3.6.23 Vendor: CentOS Release : 20.el6 Build Date: Fri 24 Jul 2015 11:17:04 AM CST Install Date: Fri 11 Sep 2015 03:22:15 PM CST Build Host: c6b8.bsys.dev.centos.org Group : System Environment/Daemons Source RPM: samba-3.6.23-20.el6.src.rpm Size : 18517685 License: GPLv3+ and LGPLv3+ Signature : RSA/SHA1, Sat 25 Jul 2015 04:40:35 AM CST, Key ID 0946fca2c105b9de Packager : CentOS BuildSystem <http://bugs.centos.org> URL : http://www.samba.org/ Summary : Server and Client software to interoperate with Windows machines Description : Samba is the suite of programs by which a lot of PC-related machines share files, printers, and other information (such as lists of available files and printers). The Windows NT, OS/2, and Linux operating systems support this natively, and add-on packages can enable the same thing for DOS, Windows, VMS, UNIX of all kinds, MVS, and more. This package provides an SMB/CIFS server that can be used to provide network services to SMB/CIFS clients. Samba uses NetBIOS over TCP/IP (NetBT) protocols and does NOT need the NetBEUI (Microsoft Raw NetBIOS frame) protocol. [root@localhost Packages]# rpm -qi samba-common-3.6.23-20.el6.x86_64#查看完整包名的相关情况 Name : samba-common Relocations: (not relocatable) Version : 3.6.23 Vendor: CentOS Release : 20.el6 Build Date: Fri 24 Jul 2015 11:17:04 AM CST Install Date: Fri 11 Sep 2015 02:53:18 PM CST Build Host: c6b8.bsys.dev.centos.org Group : Applications/System Source RPM: samba-3.6.23-20.el6.src.rpm Size : 37554531 License: GPLv3+ and LGPLv3+ Signature : RSA/SHA1, Sat 25 Jul 2015 04:43:32 AM CST, Key ID 0946fca2c105b9de Packager : CentOS BuildSystem <http://bugs.centos.org> URL : http://www.samba.org/ Summary : Files used by both Samba servers and clients Description : Samba-common provides files necessary for both the server and client packages of Samba. [root@localhost Packages]# rpm -ql vsftp#尽量写完整的包名 package vsftp is not installed [root@localhost Packages]# rpm -ql vsftpd-2.2.2-14.el6.x86_64 /etc/logrotate.d/vsftpd /etc/pam.d/vsftpd /etc/rc.d/init.d/vsftpd /etc/vsftpd /etc/vsftpd/ftpusers /etc/vsftpd/user_list /etc/vsftpd/vsftpd.conf …… 内容太多,省略 [root@localhost Packages]# rpm -q --scripts setup-2.8.14-20.el6_4.1.noarch#查看一个程序相关脚本 postinstall scriptlet (using <lua>): for i, name in ipairs({"passwd", "shadow", "group", "gshadow"}) do os.remove("/etc/"..name..".rpmnew") end [root@localhost Packages]# rpm -qf /etc/samba/ lmhosts smb.conf smbusers [root@localhost Packages]# rpm -qf /etc/samba/smb.conf samba-common-3.6.23-20.el6.x86_64 [root@localhost Packages]# rpm -q --scripts samba-common-3.6.23-20.el6.x86_64 postinstall scriptlet (using /bin/sh): /sbin/ldconfig postuninstall scriptlet (using /bin/sh): /sbin/ldconfig [root@localhost Packages]#
-p 是查询针对未安装的程序包
[root@localhost Packages]# rpm -qa|grep dhcp dhcp-common-4.1.1-49.P1.el6.centos.x86_64 [root@localhost Packages]# rpm -qpc dhcp- dhcp-4.1.1-49.P1.el6.centos.x86_64.rpm dhcp-common-4.1.1-49.P1.el6.centos.x86_64.rpm [root@localhost Packages]# rpm -qpc dhcp-4.1.1-49.P1.el6.centos.x86_64.rpm #未安装的程序包包名 /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd6.conf /etc/openldap/schema/dhcp.schema /etc/portreserve/dhcpd /etc/sysconfig/dhcpd /etc/sysconfig/dhcpd6 /etc/sysconfig/dhcrelay ……省略
校验
-V校验安装到系统的文件跟原程序包中是否相符
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@localhost Packages]# vi /etc/vsftpd/vsftpd.conf #对配置文件稍稍改动一下,校验检查 [root@localhost Packages]# rpm -V vsftpd-2.2.2-14.el6.x86_64 S.5....T. c /etc/vsftpd/vsftpd.conf#S:文件大小发生改变,5:MD5校验值发生改变,T:mtime发生改变 [root@localhost Packages]#
包校验
rpm --import PUBKEY ...
rpm {-K|--checksig} [--nosignature] [--nodigest] PACKAGE_FILE ...
[root@localhost mnt]# rpm --import RPM-GPG-KEY-CentOS- RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Security-6 RPM-GPG-KEY-CentOS-Testing-6 [root@localhost mnt]# rpm --import RPM-GPG-KEY-CentOS-6 [root@localhost mnt]# rpm -K Packages/zsh-4.3.11-4.el6.centos.x86_64.rpm Packages/zsh-4.3.11-4.el6.centos.x86_64.rpm: rsa sha1 (md5) pgp md5 OK [root@localhost mnt]# rpm -qa|grep gpg-pubkey#我分别导入了5,6,7的gpg-key,所有有三条记录 gpg-pubkey-e8562897-459f07a4 gpg-pubkey-c105b9de-4e0fd3a3 gpg-pubkey-f4a80eb5-53a7ff4b [root@localhost mnt]# rpm -e gpg-pubkey-e8562897-459f07a4 [root@localhost mnt]# rpm -e gpg-pubkey-c105b9de-4e0fd3a3 [root@localhost mnt]# rpm -e gpg-pubkey-f4a80eb5-53a7ff4b [root@localhost mnt]# rpm -K Packages/zsh-4.3.11-4.el6.centos.x86_64.rpm #卸载以后校验失败 Packages/zsh-4.3.11-4.el6.centos.x86_64.rpm: RSA sha1 ((MD5) PGP) md5 NOT OK (MISSING KEYS: (MD5) PGP#c105b9de) [root@localhost mnt]# rpm -qa|grep gpg-pubkey [root@localhost mnt]# rpm --import RPM-GPG-KEY-CentOS-6 [root@localhost mnt]# rpm -qa|grep gpg-pubkey gpg-pubkey-c105b9de-4e0fd3a3 [root@localhost yum.repos.d]# rpm -K /mnt/Packages/zsh-4.3.11-4.el6.centos.x86_64.rpm #再次导入可校验 /mnt/Packages/zsh-4.3.11-4.el6.centos.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
YUM管理
一个完整的yum服务,需要:
1、yum仓库(存储rpm文件和索引文件)
2、提供rpm下载的网络(http、ftp或者本地)
3、客户端yum命令
4、客户端yum仓库信息配置
yum配置文件/etc/yum.conf这个文件内容一般不需要改动
指明yum命令仓库配置文件 在/etc/yum.repos.d/ 下以.repo结尾
[repositoryid]
# 对于当前系统的yum来讲,此repositoryid用于惟一标识此repository指向,因此,其必须惟一;
name=
# 当前仓库描述信息;
baseurl=url://path/to/repository/
# 指明repository的访问路径;通常为一个文件服务器上输出的某repository;url 可以是 ftp,http 或者本地文件系统的 url
enabled={1|0}
此仓库是否可被使用
gpgcheck={1|0}
是否对程序包做校验
gpgkey=url://path/to/keyfile
指明gpgkey文件路径;
cost=#
指明当前repository的访问开销,默认为1000;
如:
[root@localhost yum.repos.d]# cat CentOS-Base.repo [centostest] name=centos6.7 mirrors.aliyun.com epel baseurl=http://mirrors.aliyun.com/centos/6.7/os/x86_64/ enabled=1 gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/6.7/os/x86_64/RPM-GPG-KEY-CentOS-6 cost=100 [root@localhost yum.repos.d]#
有些内容是这样的:
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
$releasever
当前 OS 发行版的主版本号,如对 CentOS 6.6 系统,这个值为 6
$arch
当前系统的平台,如 i386, x86_64 等
$basearch
基础平台,如 x86_64 和 amd64 平台的基础平台同为 x86_64
仓库管理
yum repolist
yum repolist [all|enabled|disabled]
[root@localhost yum.repos.d]# yum repolist#默认列出来的就是enabled Loaded plugins: fastestmirror, refresh-packagekit, security Determining fastest mirrors centostest | 3.7 kB 00:00 centostest/primary_db | 4.6 MB 00:10 repo id repo name status centostest centos6.7 mirrors.aliyun.com epel 6,575 repolist: 6,575
清理缓存
clean 清理缓存
yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
如果不知道清理哪些好,就直接yum clean all
makecache 缓存创建
yum makecache 将会自动连接至每一个可用仓库,下载其元数据,并将其创建为缓存
[root@localhost yum.repos.d]# yum clean metadata Loaded plugins: fastestmirror, refresh-packagekit, security Cleaning repos: centostest 2 metadata files removed 1 sqlite files removed 0 metadata files removed [root@localhost yum.repos.d]# yum clean all Loaded plugins: fastestmirror, refresh-packagekit, security Cleaning repos: centostest Cleaning up Everything Cleaning up list of fastest mirrors [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# yum makecache#创建缓存 Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile centostest | 3.7 kB 00:00 centostest/group_gz | 219 kB 00:00 centostest/filelists_db | 6.3 MB 00:13 centostest/other_db | 2.8 MB 00:06 Metadata Cache Created [root@localhost yum.repos.d]#
程序包查找
yum list
yum list all #列出所有可用的程序包,不建议这么列出,太多了
yum list package_name
[root@localhost yum.repos.d]# yum list vsftp*#也可以使用通配符进行查找 Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Installed Packages vsftpd.x86_64 2.2.2-14.el6 @centostest [root@localhost yum.repos.d]#
程序包安装
yum install packages
[root@localhost yum.repos.d]# yum install -y mysql#安装过程中会出现交互,提醒是否安装,-y则不会出现交互 Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package mysql.x86_64 0:5.1.73-5.el6_6 will be installed --> Finished Dependency Resolution ……省略 Installing : mysql-5.1.73-5.el6_6.x86_64 1/1 Verifying : mysql-5.1.73-5.el6_6.x86_64 1/1 Installed: mysql.x86_64 0:5.1.73-5.el6_6 Complete!
重新安装
yum reinstall packages 跟install用法一样
程序包升级
yum update package
程序包降级
yum downgrade 降级包的包名
卸载程序包
yum remove package
[root@localhost yum.repos.d]# yum remove mysql ……省略 Removed: mysql.x86_64 0:5.1.73-5.el6_6 Complete!
查询软件包相关信息
[root@localhost yum.repos.d]# yum info samba#类似 rpm -qi samba查询的结果 Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Installed Packages Name : samba Arch : x86_64 Version : 3.6.23 Release : 20.el6 Size : 18 M Repo : installed Summary : Server and Client software to interoperate with Windows machines URL : http://www.samba.org/ License : GPLv3+ and LGPLv3+ Description : : Samba is the suite of programs by which a lot of PC-related machines : share files, printers, and other information (such as lists of : available files and printers). The Windows NT, OS/2, and Linux : operating systems support this natively, and add-on packages can : enable the same thing for DOS, Windows, VMS, UNIX of all kinds, MVS, : and more. This package provides an SMB/CIFS server that can be used to : provide network services to SMB/CIFS clients. : Samba uses NetBIOS over TCP/IP (NetBT) protocols and does NOT : need the NetBEUI (Microsoft Raw NetBIOS frame) protocol. [root@localhost yum.repos.d]#
包组管理
yum grouplist列出所有组
[root@localhost yum.repos.d]# yum grouplist Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Group Process Loading mirror speeds from cached hostfile Installed Groups: Additional Development Base CIFS file server Debugging Tools Desktop Desktop Debugging and Performance Tools Desktop Platform Dial-up Networking Support Directory Client Directory Server E-mail server FTP server Fonts General Purpose Desktop ……省略
yum groupinfogroup查看包组详情
yum groupinstall group安装包组
yum groupremovegroup 卸载包组
yum groupupdategroup 升级包组
用法跟普通软件包相同,-y可以不显示交互
[root@localhost yum.repos.d]# yum groupinstall ‘FTP server‘ -y #安装一个包组 Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Group Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package vsftpd.x86_64 0:2.2.2-14.el6 will be installed --> Finished Dependency Resolution ……省略 Installed: vsftpd.x86_64 0:2.2.2-14.el6 Complete! [root@localhost yum.repos.d]# yum groupremove -y ‘FTP server‘ #卸载一个包组 Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Group Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package vsftpd.x86_64 0:2.2.2-14.el6 will be erased --> Finished Dependency Resolution ……省略 Removed: vsftpd.x86_64 0:2.2.2-14.el6 Complete!
原文地址:http://wangkunpeng.blog.51cto.com/1538469/1693934