程序包管理: 包管理器:打包,包管理(安装、升级、卸载、查询及校验) deb: debian rpm: redhat package manager RPM is Package Manager 程序包的组成部分: 二进制程序:/bin, /sbin,/ /usr/bin, /usr/sbin, 库文件:/lib64, /usr/lib64 配置文件:/etc 帮助文件:manual, info RPM: REDHAT PACKAGE MANAGER SRPM:SOURCE RPM 这个srpm里面含有源代码,它所提供的软件并没有经过编译,通常srpm的扩展名:xxx.src.rpm来命名。 文件格式 文件名格式 直接安装与否 内含程序类型 可否修改参数编译 RPM xxx.rpm 是 已编译 不可 SRPM xxx.src.rpm 否 未编译 可. rp-pppoe - 3.1 - 5 .i386 .rpm 软件名称 软件的版本信息 发布版本次 适合的硬件平台 扩展名 安装: rpm {-i|--install} [install-options] PACKAGE_FILE ... rpm -ivh acl-2.2.51-12.el7.x86_64.rpm 参数: -i:install -v:查看详细的安装画面信息 -h:显示安装进度 [[email protected] Packages]# rpm -ivh acl-2.2.51-12.el7.x86_64.rpm Preparing... ################################# [100%] package acl-2.2.51-12.el7.x86_64 is already installed --nodeps:当发生软件属性依赖问题而无法安装,可使用此参数强行安装 --replacefiles:覆盖文件 --replacepkgs:重新安装某个已安装的软件 --forc:强制安装 --test:检查软件的依赖性 [[email protected] Packages]# rpm -ivh OpenIPMI-2.0.19-11.el7.x86_64.rpm //此包依赖以下安装包 error: Failed dependencies: OpenIPMI-libs = 2.0.19-11.el7 is needed by OpenIPMI-2.0.19-11.el7.x86_64 libIPMIlanserv.so.0()(64bit) is needed by OpenIPMI-2.0.19-11.el7.x86_64 libOpenIPMI.so.0()(64bit) is needed by OpenIPMI-2.0.19-11.el7.x86_64 libOpenIPMIcmdlang.so.0()(64bit) is needed by OpenIPMI-2.0.19-11.el7.x86_64 libOpenIPMIglib.so.0()(64bit) is needed by OpenIPMI-2.0.19-11.el7.x86_64 libOpenIPMIposix.so.0()(64bit) is needed by OpenIPMI-2.0.19-11.el7.x86_64 libOpenIPMIui.so.1()(64bit) is needed by OpenIPMI-2.0.19-11.el7.x86_64 libOpenIPMIutils.so.0()(64bit) is needed by OpenIPMI-2.0.19-11.el7.x86_64 libnetsnmp.so.31()(64bit) is needed by OpenIPMI-2.0.19-11.el7.x86_64 [[email protected] Packages]# rpm -ivh OpenIPMI-2.0.19-11.el7.x86_64.rpm --nodeps //使用--nodeps 强制安装 Preparing... ################################# [100%] Updating / installing... 1:OpenIPMI-2.0.19-11.el7 ################################# [100%] [[email protected] Packages]# rpm -e OpenIPMI //为了以后方便,还是将此软件卸载 升级: rpm {-U|--upgrade} [install-options] PACKAGE_FILE ... rpm {-F|--freshen} [install-options] PACKAGE_FILE ... -Uvh: 如果有旧版程序包,则升级之;如果没有,则安装之; -Fvh: 如果有旧版程序包,则升级之;如果没有,则不安装; --nodeps --oldpackage:降级; --force: 卸载: rpm {-e|--erase} [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ... [[email protected] Packages]# rpm -e OpenIPMI //卸载的时候,可以直接接软件名 查询: rpm {-q|--query} [select-options] [query-options] 查询选项: -qa: 查询本机已经安装的所有程序包; -qf /PATH/TO/SOMEFILE: 查询此处的文件由哪个程序包安装生成; -qc: 查询指定程序包安装生成的配置文件 -qd: 查询指定的程序包安装生成的文档 -qi: 查询指定的程序包的相关信息; -ql: 查询程序包安装生成的所有文件的列表; -q --scripts:查询程序包相关的脚本: preinstall: 安装前脚本 postinstall:安装后脚本 preuninstall: 卸载前脚本 postuninstall: 卸载后脚本 -p: 查询针对是未安装的程序包文件; -qR:列出与该软件有关的依赖软件所含的文件 所有的参数前,只有加入了p参数才是查询。 [[email protected] Packages]# rpm -q logrotate //查找本机是否安装logrotate logrotate-3.8.6-4.el7.x86_64 [[email protected] Packages]# rpm -q logrotating //查找本机是否安装logrotating package logrotating is not installed [[email protected] Packages]# rpm -qi logrotate //-qi: 查询指定的程序包的相关信息; Name : logrotate Version : 3.8.6 Release : 4.el7 Architecture: x86_64 Install Date: Tue 08 Sep 2015 12:28:07 AM CST Group : System Environment/Base Size : 102451 License : GPL+ Signature : RSA/SHA256, Fri 04 Jul 2014 11:34:56 AM CST, Key ID 24c6a8a7f4a80eb5 Source RPM : logrotate-3.8.6-4.el7.src.rpm Build Date : Tue 10 Jun 2014 05:58:02 AM CST Build Host : worker1.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : https://fedorahosted.org/logrotate/ Summary : Rotates, compresses, removes and mails system log files Description : The logrotate utility is designed to simplify the administration of log files on a system which generates a lot of log files. Logrotate allows for the automatic rotation compression, removal and mailing of log files. Logrotate can be set to handle a log file daily, weekly, monthly or when the log file gets to a certain size. Normally, logrotate runs as a daily cron job. Install the logrotate package if you need a utility to deal with the log files on your system. [[email protected] Packages]# rpm -ql logrotate //查询程序包安装生成的所有文件的列表 /etc/cron.daily/logrotate /etc/logrotate.conf /etc/logrotate.d /usr/sbin/logrotate /usr/share/doc/logrotate-3.8.6 /usr/share/doc/logrotate-3.8.6/CHANGES /usr/share/doc/logrotate-3.8.6/COPYING /usr/share/man/man5/logrotate.conf.5.gz /usr/share/man/man8/logrotate.8.gz /var/lib/logrotate.status [[email protected] Packages]# rpm -qc logrotate //查询指定程序包安装生成的配置文件 /etc/logrotate.conf /var/lib/logrotate.status [[email protected] Packages]# rpm -qd logrotate // 查询指定的程序包安装生成的文档 /usr/share/doc/logrotate-3.8.6/CHANGES /usr/share/doc/logrotate-3.8.6/COPYING /usr/share/man/man5/logrotate.conf.5.gz /usr/share/man/man8/logrotate.8.gz 校验:Verify rpm {-V|--verify} [select-options] [verify-options] 参数: -V:后面接软件的名称,若该软件所含的文件被改动过,才会列出来 -Va:列出目前系统上所有可能被改动过的文件 -Vp:接文件名称,列出该软件可能改动的文件 -Vf:列出某个文件是否改动 [[email protected] Packages]# rpm -V logrotate //如果没有内容输出,说明没有改动 [[email protected] Packages]# rpm -Vf /etc/fstab [[email protected] Packages]# vi /etc/logrotate.conf //修改/etc/logrotate.conf 里面的rotate [[email protected] Packages]# rpm -V logrotate ..5....T. c /etc/logrotate. 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 数字证书:digital signature Centos 使用的数值证书系统为GNU计划的GnuPG (GNU Privacy Guard,GPG) [[email protected] Packages]# ll /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 //centos的数值证书 -rw-r--r--. 1 root root 1690 Apr 1 06:27 /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [[email protected] Packages]# cat /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 //centos的数值证书的内容是一项随机数字 -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.5 (GNU/Linux) mQINBFOn/0sBEADLDyZ+DQHkcTHDQSE0a0B2iYAEXwpPvs67cJ4tmhe/iMOyVMh9 ...... uPNL0eRx4S1G4Jn5 =OGYX -----END PGP PUBLIC KEY BLOCK----- [[email protected] Packages]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 //导入数字证书 YUM: Yellowdog Updater Modified 1.查询功能:yum [list|info|search|provides|whatprovides] -y:当yum等待用户输入y时自动输入 --installroot=/*/* :将该软件安装到指定的位置 search: 搜索某个软件的名称或描述重要关键字 info:同上 provides:由文件搜索软件 list:列出目前yum所管理的所有软件名称与版本 [[email protected] ~]# yum list |less // 列出目前yum所管理的所有软件名称与版本 abrt.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-addon-ccpp.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-addon-kerneloops.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-addon-pstoreoops.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-addon-python.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-addon-vmcore.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-addon-xorg.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-cli.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-console-notification.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-libs.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-python.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-retrace-client.x86_64 2.1.11-19.el7.centos.0.3 @anaconda abrt-tui.x86_64 2.1.11-19.el7.centos.0.3 @anaconda acl.x86_64 2.2.51-12.el7 @anaconda ...... [[email protected] ~]# yum info python //查看python相关信息 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.zju.edu.cn * updates: mirrors.pubyun.com Installed Packages Name : python Arch : x86_64 Version : 2.7.5 Release : 16.el7 Size : 79 k Repo : installed From repo : anaconda Summary : An interpreted, interactive, object-oriented programming language URL : http://www.python.org/ License : Python Description : Python is an interpreted, interactive, object-oriented programming : language often compared to Tcl, Perl, Scheme or Java. Python includes : modules, classes, exceptions, very high level dynamic data types and : dynamic typing. Python supports interfaces to many system calls and : libraries, as well as to various windowing systems (X11, Motif, Tk, : Mac and MFC). : : Programmers can write new built-in modules for Python in C or C++. : Python can be used as an extension language for applications that need : a programmable interface. : : Note that documentation for Python is provided in the python-docs : package. : : This package provides the "python" executable; most of the actual : implementation is within the "python-libs" package. [[email protected] ~]# yum provides python //由文件搜索软件 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.zju.edu.cn * updates: mirrors.pubyun.com python-2.7.5-16.el7.x86_64 : An interpreted, interactive, object-oriented programming language Repo : base python-2.7.5-18.el7_1.1.x86_64 : An interpreted, interactive, object-oriented programming language Repo : updates python-2.7.5-16.el7.x86_64 : An interpreted, interactive, object-oriented programming language Repo : @anaconda 2.安装升级 参数: install 安装 update 升级 [[email protected] ~]# yum install python Loaded plugins: fastestmirror, langpacks base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 Loading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.zju.edu.cn * updates: mirrors.pubyun.com Resolving Dependencies --> Running transaction check ---> Package python.x86_64 0:2.7.5-16.el7 will be updated ---> Package python.x86_64 0:2.7.5-18.el7_1.1 will be an update --> Processing Dependency: python-libs(x86-64) = 2.7.5-18.el7_1.1 for package: python-2.7.5-18.el7_1.1.x86_64 --> Running transaction check ---> Package python-libs.x86_64 0:2.7.5-16.el7 will be updated ---> Package python-libs.x86_64 0:2.7.5-18.el7_1.1 will be an update --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================== Package Arch Version Repository Size ================================================================================================================== Updating: python x86_64 2.7.5-18.el7_1.1 updates 86 k Updating for dependencies: python-libs x86_64 2.7.5-18.el7_1.1 updates 5.6 M Transaction Summary ================================================================================================================== Upgrade 1 Package (+1 Dependent package) Total download size: 5.7 M Is this ok [y/d/N]: [[email protected] ~]# yum remove python //删除 3.yum的组功能 参数: grouplist :列出所有可使用的组列表 groupinfo :列出组信息 groupinstall :安装一组软件 groupremove :删除一组软件 [[email protected] ~]# yum grouplist 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 * base: mirrors.163.com * extras: mirrors.zju.edu.cn * updates: mirrors.pubyun.com 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
YUM的配置文件
[[email protected] yum.repos.d]# vi CentOS-Base.repo //以下是我本机容器内容
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
"CentOS-Base.repo" 44L, 1664C
【base】:代表容器的名称,中括号一定要存在,名字任取,但不能有两个相同的容器名称
【name】:说明这个容器的意义
【mirrorlist】:容器使用的镜像站点
【baseurl】:这个很重要,主要的事情说三遍,这就是容器的实际网址,这就是容器的实际网址,这就是容器的实际网址。mirrorlist是由yum程序自行去找镜像站点,而baseurl是指定镜像站点。
【enabled】:如果值为1,表示启动这个容器,为0则不启动
【gpgcheck】:是否查阅RPM的数字证书,为1表示查阅,0表示不查阅
【gpgkey】:数字证书公钥的存放路径
接下来我将指定ftp.twaren.net作为容器的网址。
[[email protected] yum.repos.d]# vi CentOS-Base.repo //这里只演示【base】这个容器
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - lysBase //自定义容器名字
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra //添加# ,不让yum自动选择镜像站点
baseurl=http://ftp.twaren.net/Linux/CentOS/$releasever/os/$basearch/ //指定镜像站点
gpgcheck=1
enabled=1 //表示启动这个容器
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
保存退出
[[email protected] yum.repos.d]# yum clean all //将所有容器数据清除
[[email protected] yum.repos.d]# yum repolist all //列出yum server所使用的容器