码迷,mamicode.com
首页 > 系统相关 > 详细

Linux 包管理工具之Yum

时间:2018-04-26 17:02:08      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:linux yum

Yum(全称为 Yellow dog Updater, Modified)是基于RPM包的包管理工具,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。至于RPM的介绍,请参考 http://blog.51cto.com/marvin89/2107904

yum简单流程图:
技术分享图片

yum配置文件查看

[root@localhost Packages]# rpm -q yum
yum-3.4.3-154.el7.centos.noarch
[root@localhost Packages]# rpm -qc yum
/etc/logrotate.d/yum
/etc/yum.conf
/etc/yum/version-groups.conf

配置文件分2端

[root@localhost Packages]# man yum.conf

#主配置
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0    #
debuglevel=2
logfile=/var/log/yum.log
exactarch=1    #centos6  centos7 之类是否精确匹配
obsoletes=1
gpgcheck=1    #来源合法性
plugins=1    #支持插件机制
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release   

#仓库配置
[repositoryID]
name=Some name for this repository  #介绍
baseurl=url://path/to/repository/      #必须跟repodata同一个目录
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL  #公钥 
enablegroups={1|0} #用组的方式管理程序包
failovermethod={roundrobin|priority}
    默认为:roundrobin,意为随机挑选; baseurl
cost=默认为1000  权重越高优先使用

配置以centos光盘为仓库的yum

准备yum源 cd盘?

[root@localhost rpm]# cd /mnt/dvd/
[root@localhost dvd]# ls
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

配置仓库

[root@localhost yum.repos.d]# vim /etc/yum.repos.d/local.repo
[base]
name=Base repo from cd
baseurl=file:///mnt/dvd/
gpgcheck=1
gpgkey=file:///mnt/dvd/RPM-GPG-KEY-CentOS-7

1、显示仓库列表:

 #repolist [all|enabled|disabled]
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                               repo name                                        status
!base                                 Base repo from cd                                9,591
repolist: 9,591

2、安装

 [root@localhost yum.repos.d]# yum install zsh-html   [#-y]    默认安装最新版本,安装老版本需要手动指定

3、升级、检查升级 (也可以是本地程序包)

#升级
[root@localhost yum.repos.d]# yum update  zsh-html
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
No packages marked for update
-----------------------------------------------------------
#检查升级
[root@localhost yum.repos.d]# yum check-update zsh-html
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

4、卸载 只会卸载当前包和依赖当前包的包
不会删除安装时候依赖ImageMagick的包 ?因为这些包依赖ImageMagick,而不是被依赖

[root@localhost yum.repos.d]# yum install ImageMagick
Dependencies Resolved

=============================================================================================
 Package                        Arch          Version                      Repository   Size
=============================================================================================
Installing:
 ImageMagick                    x86_64        6.7.8.9-15.el7_2             base        2.1 M
Installing for dependencies:
 OpenEXR-libs                   x86_64        1.7.1-7.el7                  base        217 k
 avahi-libs                     x86_64        0.6.31-17.el7                base         61 k
 cairo                          x86_64        1.14.8-2.el7                 base        713 k
 cups-libs                      x86_64        1:1.6.3-29.el7               base        356 k
 fontconfig                     x86_64        2.10.95-11.el7               base        229 k
 fontpackages-filesystem        noarch        1.44-8.el7                   base        9.9 k
 gdk-pixbuf2                    x86_64        2.36.5-1.el7                 base        567 k
 ghostscript                    x86_64        9.07-28.el7                  base        4.3 M
 ghostscript-fonts              noarch        5.50-32.el7                  base        324 k
 graphite2                      x86_64        1.3.6-1.el7_2                base        112 k
 harfbuzz                       x86_64        1.3.2-1.el7                  base        177 k
 ilmbase                        x86_64        1.0.3-7.el7                  base        100 k
 jasper-libs                    x86_64        1.900.1-31.el7               base        150 k
.....

[root@localhost yum.repos.d]# yum remove ImageMagick
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package ImageMagick.x86_64 0:6.7.8.9-15.el7_2 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================
 Package                Arch              Version                     Repository        Size
=============================================================================================
Removing:
 ImageMagick            x86_64            6.7.8.9-15.el7_2            @base            7.6 M

Transaction Summary
=============================================================================================
Remove  1 Package

卸载ImageMagick的依赖包OpenEXR-libs,会把ImageMagick也卸载

[root@localhost yum.repos.d]# yum remove  OpenEXR-libs
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package OpenEXR-libs.x86_64 0:1.7.1-7.el7 will be erased
--> Processing Dependency: libIlmImf.so.7()(64bit) for package: ImageMagick-6.7.8.9-15.el7_2.x86_64
--> Running transaction check
---> Package ImageMagick.x86_64 0:6.7.8.9-15.el7_2 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================
 Package                Arch             Version                       Repository       Size
=============================================================================================
Removing:
 OpenEXR-libs           x86_64           1.7.1-7.el7                   @base           844 k
Removing for dependencies:
 ImageMagick            x86_64           6.7.8.9-15.el7_2              @base           7.6 M

个人觉得这个卸载方式不是很好,会残留很多无用的包

?
5、显示程序包:

# yum list [all | glob_exp1] [glob_exp2] [...]
# yum list {available|installed|updates} [glob_exp1] [...]

[root@localhost yum.repos.d]# yum list
Installed Packages
GeoIP.x86_64                                1.5.0-11.el7                           @anaconda #@表示安装过的。anaconda表示操作系统

....
zziplib-devel.i686                              0.13.62-5.el7                       base   #还未安装的
zziplib-devel.x86_64                            0.13.62-5.el7                       base
zsh-html.x86_64                             5.0.2-28.el7                          @base      #base源安装的

6、具体包信息查看

[root@localhost yum.repos.d]# yum info ImageMagick
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name        : ImageMagick
Arch        : x86_64
Version     : 6.7.8.9
Release     : 15.el7_2
Size        : 7.6 M
Repo        : installed
From repo   : base
Summary     : An X application for displaying and manipulating images
....

7、查看指定的特性(可以是某文件)是由哪个程序包所提供:相当于rpm -qf

# provides | whatprovides feature1 [feature2] [...]

[root@localhost yum.repos.d]# yum provides /etc/passwd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
setup-2.8.71-7.el7.noarch : A set of system configuration and setup files
Repo        : base
Matched from:
Filename    : /etc/passwd

setup-2.8.71-7.el7.noarch : A set of system configuration and setup files
Repo        : @anaconda
Matched from:
Filename    : /etc/passwd

8、查看 以指定的关键字搜索程序包名及summary信息;

[root@localhost yum.repos.d]# yum search zsh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
===================================== N/S matched: zsh ======================================
zsh-html.x86_64 : Zsh shell manual in html format
zsh.x86_64 : Powerful interactive shell

  Name and summary matches only, use "search all" for everything.

9、依赖包查看

[root@localhost yum.repos.d]# yum deplist bash
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
package: bash.x86_64 4.2.46-28.el7
  dependency: libc.so.6(GLIBC_2.15)(64bit)
   provider: glibc.x86_64 2.17-196.el7
  dependency: libdl.so.2()(64bit)
......

10、查看yum事务历史:

#history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
[root@localhost yum.repos.d]# yum history
Loaded plugins: fastestmirror
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    17 | root <root>              | 2018-04-25 21:53 | Install        |    1
    16 | root <root>              | 2018-04-25 21:49 | Erase          |    1
    15 | root <root>              | 2018-04-25 21:49 | Install        |   48

11、包组查看

[root@localhost yum.repos.d]# yum grouplist
Installed Groups:
   .....
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Graphical Administration Tools
   Development Tools
    .....

12、安装包组

[root@localhost yum.repos.d]# yum groupinstall "Development Tools"
# 升级 groupupdate group1 [group2] [...]

13、移除包组

[root@localhost yum.repos.d]# yum groupremove  "Development Tools"

14、包组信息查看

[root@localhost yum.repos.d]# yum groupinfo  "Development Tools"

建立自己的yum源

1、添加几个rpm包,为yum源

[root@localhost yum.repos.d]# mkdir -p /yum/repo
[root@localhost yum.repos.d]# cp /mnt/dvd/Packages/z* /yum/repo/

2、centos7需要安装createrepo

[root@localhost repo]# yum install createrepo

3、初始化仓库

[root@localhost repo]# pwd
/yum/repo

[root@localhost repo]# createrepo ../   #在上级目录下创建repodata
Spawning worker 0 with 5 pkgs
Spawning worker 1 with 5 pkgs
Spawning worker 2 with 5 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

[root@localhost repo]# cd ..
[root@localhost yum]# ls repodata
447ec135b1c7f6b6270eefc3c48487b7111af058b6a8e69d2752dff8fe692f10-filelists.sqlite.bz2
5bf5f6ef05024c6fa8323255156d043213eac62f765d4106d71e57e133e16990-other.xml.gz
6c2ee7607b3b821acc6907604067e85d101fb4eecc6e10baa45086f26e0343f8-primary.sqlite.bz2
c881c0f911ca54a1ade1d96280a04b8224a5d782522d555f7c6d1b528c2ddd7f-other.sqlite.bz2
e018c8c524d20f6f30d26b42c909757eb2966a55c2f1a90d543602848db03384-filelists.xml.gz
ed266c67e84620208b4124883f03e6a8eaf0ba1d98a0dddd85c5a57beb8efbc4-primary.xml.gz
repomd.xml

4、编辑配置文件

[myrepo]
name=test repo
baseurl=file:///yum
gpgcheck=0

5、使用自己的yum源

[root@localhost repodata]# yum remove zsh
[root@localhost repodata]# yum install zsh
Loaded plugins: fastestmirror
myrepo                                                  | 2.9 kB     00:00
myrepo/primary_db                                         | 9.2 kB   00:00
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================
 Package       Arch             Version                 Repository        Size
===============================================================================
Installing:
 zsh           x86_64           5.0.2-28.el7            myrepo           2.4 M

Transaction Summary
===============================================================================
Install  1 Package

Total download size: 2.4 M
Installed size: 5.6 M
Is this ok [y/d/N]:

Linux 包管理工具之Yum

标签:linux yum

原文地址:http://blog.51cto.com/marvin89/2108154

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!