Linux软件包的管理--YUM

简介:

    在上一篇博客《Linux软件包的管理--RPM包管理器》中详细讲述了RPM,但是存在一个问题?就是RPM不能自动解决软件包之间的依赖性。所以就出现了增强版的RPM管理器-YUM。

    以下讲解以CentOS6系列为例。


一、YUM介绍

    YUM(Yellowdog Updater Modified)是一种C/S架构,它为什么就能自动解决依赖性关系呢?这取决于 YUM 服务端的RPM仓库,在这个仓库里放着我们经常用到的rpm格式的软件包。

1、yum仓库的组成


组成 内容
数据
存放各个rpm包
元数据

包名、版本信息、依赖关系、包分组信息、依赖关系列表。

在centos6中遵循sqlite格式,生成的元数据目录是repodata。

2、yum客户端如何访问服务端


    以升级为例:

wKiom1PKQOHycOhCAAGR0TdSJ6A513.jpg

3、如何配置yum的服务端和客户端

1)在服务器端

    首先:在服务器端要确保有可用的yum仓库。yum仓库其实就是文件服务器。repodata目录所在的父目录就是一个yum仓库。

    其次:服务器端必须通过某种手段将yum仓库共享出去,可以让客户端使用,常见的共享方式有:ftp,http,nfs。如果是本地使用(客户端和服务端是同一台机器),也可以使用file方式。

2)yum客户端

    提供repo配置文件,指明仓库访问路径及各种属性。主配置文件(中心配置文件):/etc/yum.conf。 

1
2
3
4
5
6
7
8
9
10
11
12
13
# 在这里定义一些默认配置属性和全局配置属性
[main]
cachedir= /var/cache/yum/ $basearch/$releasever
keepcache=0
debuglevel=2
logfile= /var/log/yum .log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http: //bugs .centos.org /set_project .php?project_id=16&ref=http: //bugs .centos.org /bug_report_page .php?category=yum
distroverpkg=centos-release

    一个后几个相关的仓库的配置保存成一个文件,文件名都以.repo结尾,保存在/etc/yum.repo.d目录中。

    下面介绍一下文件格式(以163镜像为例):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[base]   # 指明仓库名称,用户可自行定义
name=CentOS-$releasever - Base - 163.com  # 一般是对这个仓库名称的说明
# 最关键的是这一项,指明仓库的访问路径
# 为了配置方便,yum引入了变量,yum配置文件中可用的四个变量:
# releasever: 程序的版本,对Yum而言指的是redhat-release版本;只替换为主版本号,如RedHat 6.5,则替换为6; 
# arch: 系统架构
# basearch: 系统基本架构,如i686,i586等的基本架构为i386; 
# YUM0-9: 在系统中定义的环境变量,可以在yum中使用;
# 最常用的就是 releasever 和 basearch
# 下面在访问的时候会被替换成:baseurl=# baseurl可以使用多个:例如
# baseurl=#         # 使用多个baseurl时需要用到以上格式  
baseurl=http: //mirrors .163.com /centos/ $releasever /os/ $basearch/
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
# baseurl和mirrlist通常只需一个,我们一般配置baseurl
gpgcheck=1   # 是否进行gpg检测(包的完整性和合法性)
gpgkey=  # gpg检测是的秘钥文件
 
# 还有其他选型,读者在配置时,可自行选择
# 常用的还有:
# enabled={0|1} 是否启用该仓库
# cost=N 配置仓库的”花费“,等价于优先级。N的值越小,优先级越高。

    配置好这些准备工作,就可以使用yum工具了。


三、yum工具的使用

    这里以互联网163镜像为例演示。

1、列出所有可用repo

    yum repolist {enabled|disabled|all}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# yum repolist {enabled|disabled|all}
# enabled 列出可用的 
# disabled 不可用的 
# all所有的
[root@server yum.repos.d] # yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
base                                                       | 3.7 kB     00:00     
extras                                                     | 3.4 kB     00:00     
updates                                                    | 3.4 kB     00:00     
repo  id                                 repo name                            status
base                                  CentOS-6 - Base - 163.com              6,367
extras                                CentOS-6 - Extras - 163.com            14
updates                               CentOS-6 - Updates - 163.com           1,153
repolist: 7,534

2、列出rpm包

    yum list {all|installed|available}

1
2
3
4
5
6
7
8
9
# yum list {all|installed|available}
# all 列出所有的包  等价于  yum list 
# installed 列出已安装的包
# available 列出可用的包(不包括已安装的)
 
# 一般情况下,会这样使用
[root@server yum.repos.d] # yum list installed | grep "http"
httpd.x86_64            2.2.15-26.el6.centos
httpd-tools.x86_64      2.2.15-26.el6.centos

3、包的描述信息

    yum info package_name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Loading mirror speeds from cached hostfile
Installed Packages
Name        : httpd
Arch        : x86_64
Version     : 2.2.15
Release     : 26.el6.centos
Size        : 2.9 M
Repo        : installed
From repo   : anaconda-CentOS-201303050102.x86_64
Summary     : Apache HTTP Server
URL         : http: //httpd .apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
             : web server.
Available Packages
Name        : httpd
Arch        : x86_64
Version     : 2.2.15
Release     : 30.el6.centos
Size        : 821 k
Repo        : updates
Summary     : Apache HTTP Server
URL         : http: //httpd .apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
             : web server.


4、列出所有的包组信息

    yum grouplist

1
2
3
4
5
6
# 经常情况下我们会是这样来使用
[root@server yum.repos.d] # yum grouplist | grep "Deve"
    Additional Development
    Desktop Platform Development
    Development tools
    Server Platform Development

5、显示包组的信息:例如组中包含的程序包列表

    yum groupinfo "GROUP NAME"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
[root@server yum.repos.d] # yum groupinfo "Development tools"
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
 
Group: Development tools
  Description: A basic development environment.
  Mandatory Packages:
    autoconf
    automake
    binutils
    bison
    flex
    gcc
    gcc-c++
    gettext
    libtool
    make
    patch
    pkgconfig
    redhat-rpm-config
    rpm-build
  Default Packages:
    byacc
    cscope
    ctags
    cvs
    diffstat
    doxygen
    elfutils
    gcc-gfortran
    git
    indent
    intltool
    patchutils
    rcs
    subversion
    swig
    systemtap
  Optional Packages:
    ElectricFence
    ant
    babel
    bzr
    chrpath
    cmake
    compat-gcc-34
    compat-gcc-34-c++
    compat-gcc-34-g77
    cvs-inetd
    dejagnu
    expect
    gcc-gnat
    gcc-java
    gcc-objc
    gcc-objc++
    imake
    jpackage-utils
    kdewebdev
    ksc
    libstdc++-docs
    mercurial
    mod_dav_svn
    nasm
    perltidy
    python-docs
    rpmdevtools
    rpmlint
    systemtap-sdt-devel
    systemtap-server

6、清理缓存

    yum clean {all|packages|metadata|expire-cache|rpmdb|plugins}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# yum clean {all|packages|metadata|expire-cache|rpmdb|plugins}
# all 所有缓存
# packages   清除包缓存
# metedata   清除元数据缓存
# expire-cache 清除过期缓存
# rpmdb    清除RPM数据库缓存
# plufins 清除插件缓存
 
# 最常用的就是 yum clean all
[root@server yum.repos.d] # yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors


7、安装程序包

    yum install package_name

1
yum  install  httpd -y  # 常用选项是 -y 意思是不需要确认,直接安装

wKiom1PKdIrQ2CS_AAS68Jnry00075.jpg  

  重新安装:

    yum reinstall package_name

1
yum reinstall httpd -y

8、升级

    yum check-update: 检查可用的升级包

wKiom1PKd1iAcJ4pAADWasr_URw300.jpg

    yum update package_name 升级软件

wKioL1PKeUmDibpIAAN3IyhKUU8012.jpg

1
2
[root@server yum.repos.d] # rpm -q ntp
ntp-4.2.6p5-1.el6.centos.x86_64

    

    yum downgrade package_name 降级使用的,退回原来的版本

1
2
3
4
5
6
7
# yum downgrade ntp -y 降级第一次可能会出现错误,解决办法之一是:yum upgrade -y 升级yum工具
[root@server yum.repos.d] # yum downgrade ntp -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Downgrade Process
Loading mirror speeds from cached hostfile
Only Upgrade available on package: ntp-4.2.6p5-1.el6.centos.x86_64
Nothing to  do


9、卸载

    yum remove|erase package_name

1
yum remove httpd -y

10、查询某文件是由哪个包安装生成的

    yum whatprovides|provides /path/to/somefile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 会列出所有的提供此配置文件的包
[root@server yum.repos.d] # yum provides /etc/httpd/conf/httpd.conf 
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
httpd-2.2.15-30.el6.centos.x86_64 : Apache HTTP Server
Repo        : updates
Matched from:
Filename    :  /etc/httpd/conf/httpd .conf
 
 
 
httpd-2.2.15-29.el6.centos.x86_64 : Apache HTTP Server
Repo        : base
Matched from:
Filename    :  /etc/httpd/conf/httpd .conf
 
 
 
httpd-2.2.15-30.el6.centos.x86_64 : Apache HTTP Server
Repo        : installed
Matched from:
Other       : Provides-match:  /etc/httpd/conf/httpd .conf


11、安装包组

    yum groupinstall "GROUP NAME"

1
2
3
4
5
# 常用的包有:
# Desktop Platform Development 开发平台
# Development tools  开发所用的包
 
# 例如:yum groupinstall "Development tools" -y


12、卸载包组

    yum groupremove "GROUP NAME"


四、自制yum仓库

1、如果作为个人使用的话,最简单的办法是,挂载光盘镜像使用。

    以VMware虚拟机为例:

    先关联光盘镜像,挂载光盘镜像就可以使用。

    其中:.repo中的baseurl使用file就可。例如:baseurl=file:///media/centos

2、自建yum仓库服务器

    以ftp为例,步骤:

(1) 安装ftp程序,并启动服务

    # rpm -ivh vsftp-版本号

    或者

    # yum install vsftpd -y

    启动服务

    # service vsftpd start

    # chkconfig vsftpd on

(2) ftp的共享目录为/var/ftp/pub

    创建子目录,存放某相关的所有rpm包(建议)


(3) 为仓库生成元数据文件,以使能够作为仓库使用

    # rpm -ivh createrepo-版本号

    或者

    # yum install createrepo -y

    # createrepo /path/to/rpm_repo/  生成repo的元数据目录 例如:createrepo /var/ftp/pub/Packages   

(4) 配置yum客户端使用此仓库即可


    总结:本文主要介绍yum工具的使用,简单介绍了自制yum服务端的步骤。











本文转自 羊木狼 51CTO博客,原文链接:http://blog.51cto.com/guoting/1440326,如需转载请自行联系原作者
目录
相关文章
|
10天前
|
Linux C语言
linux yum安装ffmpeg 图文详解
linux yum安装ffmpeg 图文详解
28 0
|
10天前
|
Linux
linux yum 安装rar和unrar
linux yum 安装rar和unrar
35 0
|
12天前
|
Ubuntu Linux 编译器
【Linux】4. 开发工具的使用(yum/vim)
【Linux】4. 开发工具的使用(yum/vim)
42 2
|
10天前
|
网络协议 Linux
在Linux中,管理和配置网络接口
在Linux中管理网络接口涉及多个命令,如`ifconfig`(在新版本中被`ip`取代)、`ip`(用于网络设备配置)、`nmcli`(NetworkManager的CLI工具)、`nmtui`(文本界面配置)、`route/ip route`(处理路由表)、`netstat/ss`(显示网络状态)和`hostnamectl/systemctl`(主机名和服务管理)。这些命令帮助用户启动接口、设置IP地址、查看连接和路由信息。不同发行版可能有差异,建议参考相应文档。
19 4
|
4天前
|
消息中间件 监控 Linux
Linux进程和计划任务管理
通过这些命令和工具,你可以有效地管理Linux系统中的进程和计划任务,监控系统的运行状态并保持系统的稳定和可靠性。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
98 2
|
10天前
|
缓存 Linux
linux centos7 挂载本地iso yum源
linux centos7 挂载本地iso yum源
51 0
|
11天前
|
存储 缓存 监控
Linux内存和硬盘空间管理技巧
了解Linux内存和硬盘管理技巧,提升系统性能和稳定性。使用`free`, `top`, `vmstat`监控内存,通过`sync`, `echo 1 > /proc/sys/vm/drop_caches`清理缓存。利用Swap分区释放内存。借助`df`, `du`检查硬盘空间,清理无用文件,使用`clean-old`, `gzip`, `tar`压缩归档。查找大文件用`find`和`du`,确保
32 0
|
18天前
|
存储 固态存储 Unix
Linux中磁盘分区和文件系统管理
在Linux系统中,磁盘是存储数据的物理设备,如HDD或SSD,以文件形式存在于`/dev`目录下,如`sda`、`sdb`等。文件系统定义了如何在磁盘上组织和访问数据,常见的Linux文件系统有ext2、ext3、ext4、xfs等。通过虚拟机软件如VMware,用户可以向Linux虚拟机添加新的硬盘。
|
21天前
|
Linux
linux中服务管理
在Linux服务管理中,从传统的System V init到Upstart,再到广泛采用的systemd,管理方式不断发展。systemd以其强大的功能和依赖解决成为现代Linux的核心。`systemctl`是管理服务的关键命令,如启动(`start`)、停止(`stop`)、重启(`restart`)服务及设置开机启动(`enable`)或取消(`disable`)。了解和服务管理,特别是systemd和`systemctl`的使用,对系统管理员至关重要。其他如xinetd用于控制网络服务,而特定环境下有OpenRC等工具。
17 2
|
22天前
|
Linux
Linux: yum查看、安装、删除软件包
Linux: yum查看、安装、删除软件包
27 0