yum(Yellodog Updater Modified)简介:
yum是由yello dog开发的并被Red Hat系列发扬光大的一款前端RPM包管理器,其还是依赖于RPM
包而存在,但是却解决了RPM安装时候的各种依赖关系,大大方便了用户。
yum原理:
建立一个yum仓库,并在yum配置文件中指定其URL,当用户用yum安装某软件时,yum先连接到指定的仓库,下载器仓库下的对所有软件映射的元数据文件——包含了每个软件的各种信息,例如依赖关系,然后与本地软件数据库文件对比,分析需要安装哪些软件,然后从指定的yum仓库下载需要的所有软件自动安装,安装完成以后自动将所有下载的软件包文件删除,但是元数据文件不删除,这是方便以后
再使用这个指定仓库时候不用下载元数据文件(在repodata下),但是每次使用yum安装软件时候都会
再去请求这个元数据文件的校验码与本地缓存的元数据校验,如果没有发生变化就不重新下载这个元数据文件,如果发生变化了就不用重新下载而是接着使用缓存中的元数据文件。
yum配置:
可以通过rpm -qc查询出yum的配置文件。
[root@bogon ~]# rpm -qc yum /etc/logrotate.d/yum /etc/yum.conf /etc/yum/version-groups.conf
这里面主要是/etc/yum.conf这是主配置文件,其里面包含了/etc/yum.repos.d/*.repo
# PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d
虽然文件只是指定了这个目录,但是需要注意的是/etc/repos.d下的文件只有以.repo结尾才
会被yum识别。这样的话就可以在这个目录下自己创建以.repo结尾的配置文件来自己指定yum仓库,系统
自带的yum配置文件如下
[root@bogon ~]# ls /etc/yum.repos.d CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
如果自己去看看除了第一个仓库以外的其他仓库,会发现都没有启用(enable=0),例如
[root@bogon ~]# less /etc/yum.repos.d/CentOS-Debuginfo.repo 省略、、 [base-debuginfo] name=CentOS-7 - Debuginfo baseurl=http://debuginfo.centos.org/7/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7 enabled=0
仓库配置法则:
[ID号](不要重复)
name=可自己随意取名
baseurl=自己要指定的yum仓库,注意是指定到有repodata的地方!!可以指定多个。
gpgcheck:合法性检验为0不检验为1检验
gpgkey=key所在路径,既然要检验那就德告诉yum key的位置啊。
enable=0或1,0代表不启用这个仓库,为1表达启用,默认就是启用
这样一个仓库就配置好了,如果需要了解更多的配置man /etc/yum.conf
这里baseurl可以用mirrorlist替换,就是指定这个mirrorlist的路径,然后yum通过这个路径
找到mirrorlist,这里面配置了baseurl,但是需要插件。
由于官方发行版光盘可以当一个yum仓库,所以可以直接挂载并配置文件使用。注意先把开启的那个仓库改名,只要不是以.repo结尾就行。不然的话还是会使用这个仓库。
[root@bogon yum.repos.d]# mount -r /dev/cdrom /media/cdrom/ [root@bogon yum.repos.d]# ls /media/cdrom/ CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7 EFI p_w_picpaths Packages RPM-GPG-KEY-CentOS-Testing-7 EULA isolinux repodata TRANS.TBL [root@bogon yum.repos.d]# ls CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo local.repo.bak [root@bogon yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak [root@bogon yum.repos.d]# ls CentOS-Base.repo.bak CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo [ yum.repos.d]#vim local.repo 1 [base] 2 name=localrepo 3 baseurl=file:///media/cdrom 4 gpgcheck=0 注意: baseurl可以是ftp,http,file
好了,在使用前得先知道yum命令啊,下面来说说yum命令的使用
刚配置完yum先来查看一下有哪些yum仓库可用,使用
yum repolist:列出可用仓库
[root@bogon yum.repos.d]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status base localrepo 9,007 repolist: 9,007
yum list[installed|updates|avaliable|all]:列出仓库所有程序与all一样,已安装程序
可更新程序,可用程序。
yum install 软件名(可用接多个):安装
[root@bogon yum.repos.d]# rpm -q zshpackage zsh is not installed[root@bogon yum.repos.d]# yum install zshLoaded plugins: fastestmirrorbase | 3.6 kB 00:00:00 base/primary_db | 2.8 MB 00:00:00 Loading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package zsh.x86_64 0:5.0.2-14.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved======================================================================================== Package Arch Version Repository Size========================================================================================Installing: zsh x86_64 5.0.2-14.el7 base 2.4 MTransaction Summary========================================================================================Install 1 PackageTotal download size: 2.4 MInstalled size: 5.6 MIs this ok [y/d/N]: yDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : zsh-5.0.2-14.el7.x86_64 1/1 Verifying : zsh-5.0.2-14.el7.x86_64 1/1Installed: zsh.x86_64 0:5.0.2-14.el7 Complete![root@bogon yum.repos.d]# [root@bogon yum.repos.d]# rpm -q zsh zsh-5.0.2-14.el7.x86_64
yum update 程序名:升级
yum info 程序名:输出指定程序的信息
[root@bogon yum.repos.d]# yum info zshLoaded plugins: fastestmirrorL oading mirror speeds from cached hostfileInstalled PackagesName : zshArch : x86_64Version : 5.0.2Release : 14.el7Size : 5.6 MRepo : installedFrom repo : baseSummary : Powerful interactive shellURL : License : MITDescription : The zsh shell is a command interpreter usable as an interactive login : shell and as a shell script command processor. Zsh resembles the ksh : shell (the Korn shell), but includes many enhancements. Zsh supports : command line editing, built-in spelling correction, programmable : command completion, shell functions (with autoloading), a history : mechanism, and more.
yum check-update:检查可用升级
yum remove 程序名:卸载
[root@bogon yum.repos.d]# yum remove zshLoaded plugins: fastestmirrorResolving Dependencies--> Running transaction check---> Package zsh.x86_64 0:5.0.2-14.el7 will be erased--> Finished Dependency ResolutionDependencies Resolved======================================================================================== Package Arch Version Repository Size========================================================================================Removing: zsh x86_64 5.0.2-14.el7 @base 5.6 MTransaction Summary========================================================================================Remove 1 PackageInstalled size: 5.6 MIs this ok [y/N]: yDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction Erasing : zsh-5.0.2-14.el7.x86_64 1/1 Verifying : zsh-5.0.2-14.el7.x86_64 1/1Removed: zsh.x86_64 0:5.0.2-14.el7 Complete![root@bogon yum.repos.d]# [root@bogon yum.repos.d]# rpm -q zshpackage zsh is not installed
yum provides 程序名:查询哪个程序包提供了这个功能(whatprovides也行)
[root@bogon yum.repos.d]# yum provides zshLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfilezsh-5.0.2-14.el7.x86_64 : Powerful interactive shellRepo : base
yum clean all:手动清理所有缓存,与只对应的构建缓存是yum makecache
yum search 字符串:以字符串搜索匹配的程序和信息
yum reinstall 程序名:重新安装
[root@bogon yum.repos.d]# rpm -q zshzsh-5.0.2-14.el7.x86_64[root@bogon yum.repos.d]# yum reinstall zshLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package zsh.x86_64 0:5.0.2-14.el7 will be reinstalled--> Finished Dependency ResolutionDependencies Resolved======================================================================================== Package Arch Version Repository Size========================================================================================Reinstalling: zsh x86_64 5.0.2-14.el7 base 2.4 MTransaction Summary========================================================================================Reinstall 1 PackageTotal download size: 2.4 MInstalled size: 5.6 MIs this ok [y/d/N]: t^Hy^H^H^HIs this ok [y/d/N]: yDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : zsh-5.0.2-14.el7.x86_64 1/1 Verifying : zsh-5.0.2-14.el7.x86_64 1/1Installed: zsh.x86_64 0:5.0.2-14.el7 Complete![root@bogon yum.repos.d]#
yum deplist 程序名:列出此程序的依赖程序以及其提供者
[root@bogon yum.repos.d]# yum deplist zshLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfilepackage: zsh.x86_64 5.0.2-14.el7 dependency: /bin/sh provider: bash.x86_64 4.2.46-19.el7 dependency: /sbin/install-info provider: info.x86_64 5.1-4.el7 dependency: coreutils provider: coreutils.x86_64 8.22-15.el7 dependency: grep provider: grep.x86_64 2.20-2.el7 dependency: libc.so.6(GLIBC_2.15)(64bit) provider: glibc.x86_64 2.17-105.el7 dependency: libdl.so.2()(64bit) provider: glibc.x86_64 2.17-105.el7 dependency: libdl.so.2(GLIBC_2.2.5)(64bit) provider: glibc.x86_64 2.17-105.el7 dependency: libm.so.6()(64bit) provider: glibc.x86_64 2.17-105.el7 dependency: libm.so.6(GLIBC_2.2.5)(64bit) provider: glibc.x86_64 2.17-105.el7 dependency: libncursesw.so.5()(64bit) provider: ncurses-libs.x86_64 5.9-13.20130511.el7 dependency: librt.so.1()(64bit) provider: glibc.x86_64 2.17-105.el7 dependency: librt.so.1(GLIBC_2.2.5)(64bit) provider: glibc.x86_64 2.17-105.el7 dependency: libtinfo.so.5()(64bit) provider: ncurses-libs.x86_64 5.9-13.20130511.el7 dependency: rtld(GNU_HASH) provider: glibc.x86_64 2.17-105.el7[root@bogon yum.repos.d]#
yum history:历史yum事件
[root@bogon yum.repos.d]# yum historyLoaded plugins: fastestmirrorID | Command line | Date and time | Action(s) | Altered------------------------------------------------------------------------------- 38 | reinstall zsh | 2016-03-19 19:44 | Reinstall | 1 37 | install zsh | 2016-03-19 19:44 | Install | 1 36 | remove zsh | 2016-03-19 19:36 | Erase | 1 35 | install zsh | 2016-03-19 19:30 | Install | 1 34 | install links | 2016-03-19 15:58 | Install | 3 33 | install wget | 2016-03-19 15:55 | Install | 1 P< 32 | install ftp | 2016-03-18 11:33 | Install | 1 > 31 | groupremove gnome deskto | 2016-03-18 11:05 | Erase | 158 30 | groupinstall gnome deskt | 2016-03-18 10:56 | Install | 679 29 | install tree | 2016-03-18 10:54 | Install | 1 28 | groupinstall development | 2016-03-18 10:49 | Install | 30 27 | groupremove Development | 2016-03-18 10:49 | Erase | 30 26 | groupinstall Development | 2016-03-18 10:48 | Install | 30 25 | remove gcc | 2016-03-18 10:47 | Erase | 1 24 | reinstall gcc | 2016-03-18 10:47 | Reinstall | 1 23 | install gcc | 2016-03-18 10:47 | Install | 1 22 | groupremove Development | 2016-03-18 10:45 | Erase | 30 21 | groupinstall Development | 2016-03-18 10:44 | Install | 30 20 | groupremove Development | 2016-03-18 10:44 | Erase | 30 19 | groupinstall Development | 2016-03-18 10:43 | Install | 30 history list[root@bogon yum.repos.d]#
组管理:
yum grouplist:列出所有可用包组
[root@bogon yum.repos.d]# yum grouplistLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfileAvailable 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 WorkstationInstalled Groups: Development ToolsAvailable Groups: Compatibility Libraries Console Internet Tools Graphical Administration Tools Legacy UNIX Compatibility Scientific Support Security Tools Smart Card Support System Administration Tools System ManagementDone[root@bogon yum.repos.d]#
yum groupinstall "包组名"
[root@bogon yum.repos.d]# yum groupinstall security toolsLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfileWarning: group security does not exist.Warning: group tools does not exist.Maybe run: yum groups mark install (see man yum)No packages in any requested group available to install or update[root@bogon yum.repos.d]# yum groupinstall Security ToolsLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfileWarning: group Security does not exist.Warning: group Tools does not exist.Maybe run: yum groups mark install (see man yum)No packages in any requested group available to install or update[root@bogon yum.repos.d]# yum groupinstall "Security Tools"Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package scap-security-guide.noarch 0:0.1.25-3.el7.centos.0.1 will be installed--> Processing Dependency: openscap-scanner >= 1.2.5 for package: scap-security-guide-0.1.25-3.el7.centos.0.1.noarch--> Running transaction check---> Package openscap-scanner.x86_64 0:1.2.5-3.el7 will be installed--> Processing Dependency: openscap(x86-64) = 1.2.5-3.el7 for package: openscap-scanner-1.2.5-3.el7.x86_64--> Processing Dependency: libopenscap.so.8()(64bit) for package: openscap-scanner-1.2.5-3.el7.x86_64--> Running transaction check---> Package openscap.x86_64 0:1.2.5-3.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved======================================================================================== Package Arch Version Repository Size========================================================================================Installing for group install "Security Tools": scap-security-guide noarch 0.1.25-3.el7.centos.0.1 base 672 kInstalling for dependencies: openscap x86_64 1.2.5-3.el7 base 2.9 M openscap-scanner x86_64 1.2.5-3.el7 base 48 kTransaction Summary========================================================================================Install 1 Package (+2 Dependent packages)Total download size: 3.6 MInstalled size: 59 MIs this ok [y/d/N]: 按下y就可以了
yum groupupdate "包组":更新指定包组
yum groupremove "包组":卸载指定包组
yum groupinfo "包组":显示指定包组信息
yum命令行选项:
--nogpgcheck:不检查包签名
-y:自动安装完
还有别的可以man下相信现在很容易理解了
下面自行创建yum仓库,这里我将光盘中的程序包都复制到/tmp/pack下,要创建yum仓库其实
就是使用createrepo这个命令来提取每个程序的元数据信息生成repodata目录。
[root@bogon yum.repos.d]# cp -r /media/cdrom/Packages/ /tmp/pack[root@bogon pack]# createrepo ./Spawning worker 0 with 1862 pkgsSpawning worker 1 with 1861 pkgsWorkers FinishedSaving Primary metadataSaving file lists metadataSaving other metadataGenerating sqlite DBsSqlite DBs complete[root@bogon pack]# ls | grep "repodata"repodata[root@bogon pack]# vim /etc/yum.repos.d/local.repo 编辑此yum仓库配置文件,当然你也可以自己重新建一个 1 [base] 2 name=localrepo 3 baseurl=file:///tmp/pack 4 gpgcheck=0 将baseurl改一下[root@bogon pack]# yum repolistLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfilerepo id repo name statusbase localrepo 3,723repolist: 3,723 [root@bogon pack]# yum install zshLoaded plugins: fastestmirrorbase | 2.9 kB 00:00:00 base/primary_db | 2.8 MB 00:00:00 Loading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package zsh.x86_64 0:5.0.2-14.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved======================================================================================== Package Arch Version Repository Size========================================================================================Installing: zsh x86_64 5.0.2-14.el7 base 2.4 MTransaction Summary========================================================================================Install 1 PackageTotal download size: 2.4 MInstalled size: 5.6 MIs this ok [y/d/N]: yDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : zsh-5.0.2-14.el7.x86_64 1/1 Verifying : zsh-5.0.2-14.el7.x86_64 1/1Installed: zsh.x86_64 0:5.0.2-14.el7 Complete![root@bogon pack]#
ok!!!