一、yum 简介

  yum,是Yellow dog Updater, Modified 的简称,是杜克大学为了提高RPM 软件包安装性而开发的一种软件包管理器。起初是由yellow dog 这一发行版的开发者Terra Soft 研发,用python 写成,那时还叫做yup(yellow dog updater),后经杜克大学的Linux@Duke 开发团队进行改进,遂有此名。yum 的宗旨是自动化地升级,安装/移除rpm 包,收集rpm 包的相关信息,检查依赖性并自动提示用户解决。yum 的关键之处是要有可靠的repository,顾名思义,这是软件的仓库,它可以是http 或ftp 站点,也可以是本地软件池,但必须包含rpm 的header,header 包括了rpm 包的各种信息,包括描述,功能,提供的文件,依赖性等。正是收集了这些header 并加以分析,才能自动化地完成余下的任务。

  yum 的理念是使用一个中心仓库(repository)管理一部分甚至一个distribution 的应用程序相互关系,根据计算出来的软件依赖关系进行相关的升级、安装、删除等等操作,减少了Linux 用户一直头痛的dependencies 的问题。这一点上,yum 和apt 相同。apt 原为debian 的deb 类型软件管理所使用,但是现在也能用到RedHat 门下的rpm 了。

  yum 主要功能是更方便的添加/删除/更新RPM 包,自动解决包的倚赖性问题,便于管理大量系统的更新问题。

  yum 可以同时配置多个资源库(Repository),简洁的配置文件(/etc/yum.conf),自动解决增加或删除rpm 包时遇到的依赖性问题,保持与RPM 数据库的一致性。

二、yum 安装

CentOS 默认已经安装了yum,不需要另外安装,这里为了实验目的,先将yum 卸载再重新安装。

1、查看系统默认安装的yum

# rpm -qa|grep yum

2、卸载yum

# rpm -e yum-fastestmirror-1.1.16-14.el5.centos.1 yum-metadata-parser-1.1.2-3.el5.centos yum-3.2.22-33.el5.centos

3、重新安装yum

这里可以通过wget 从网上下载相关包安装,也可以挂载系统安装光盘进行安装,这里选择挂载系统安装光盘进行安装。

# mount /dev/cdrom /mnt/cdrom/

# rpm -ivh yum-3.2.22-33.el5.centos.noarch.rpm yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm

# yum -v

yum 的基础安装包包括:

  • yum  //RPM installer/updater
  • yum-fastestmirror  //Yum plugin which chooses fastest repository from a mirrorlist
  • yum-metadata-parser  //A fast metadata parser for yum

其他安装包根据自己需要安装。

三、yum 配置

yum 的配置文件分为两部分:main 和repository

  • main 部分定义了全局配置选项,整个yum 配置文件应该只有一个main。常位于/etc/yum.conf 中。
  • repository 部分定义了每个源/服务器的具体配置,可以有一到多个。常位于/etc/yum.repo.d 目录下的各文件中。

yum.conf 文件一般位于/etc目录下,一般其中只包含main部分的配置选项。

# cat /etc/yum.conf

[main]

cachedir=/var/cache/yum
  //yum 缓存的目录,yum 在此存储下载的rpm 包和数据库,默认设置为/var/cache/yum

keepcache=0
  //安装完成后是否保留软件包,0为不保留(默认为0),1为保留

debuglevel=2
  //Debug 信息输出等级,范围为0-10,缺省为2

logfile=/var/log/yum.log
  //yum 日志文件位置。用户可以到/var/log/yum.log 文件去查询过去所做的更新。

pkgpolicy=newest
  //包的策略。一共有两个选项,newest 和last,这个作用是如果你设置了多个repository,而同一软件在不同的repository中同时存在,yum 应该安装哪一个,如果是newest,则yum 会安装最新的那个版本。如果是last,则yum 会将服务器id 以字母表排序,并选择最后的那个服务器上的软件安装。一般都是选newest。
distroverpkg=redhat-release
  //指定一个软件包,yum 会根据这个包判断你的发行版本,默认是redhat-release,也可以是安装的任何针对自己发行版的rpm包。

tolerant=1
  //有1和0两个选项,表示yum 是否容忍命令行发生与软件包有关的错误,比如你要安装1,2,3三个包,而其中3此前已经安装了,如果你设为1,则yum 不会出现错误信息。默认是0。

exactarch=1
  //有1和0两个选项,设置为1,则yum 只会安装和系统架构匹配的软件包,例如,yum 不会将i686的软件包安装在适合i386的系统中。默认为1。

retries=6
  //网络连接发生错误后的重试次数,如果设为0,则会无限重试。默认值为6.
obsoletes=1
  //这是一个update 的参数,具体请参阅yum(8),简单的说就是相当于upgrade,允许更新陈旧的RPM包。

plugins=1
  //是否启用插件,默认1为允许,0表示不允许。我们一般会用yum-fastestmirror这个插件。

bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum

# Note: yum-RHN-plugin doesn't honor this.

metadata_expire=1h

installonly_limit = 5

# PUT YOUR REPOS HERE OR IN separate files named file.repo

# in /etc/yum.repos.d

除了上述之外,还有一些可以添加的选项,如:

  exclude=selinux*  // 排除某些软件在升级名单之外,可以用通配符,列表中各个项目要用空格隔开,这个对于安装了诸如美化包,中文补丁的朋友特别有用。
  gpgcheck=1  // 有1和0两个选择,分别代表是否是否进行gpg(GNU Private Guard) 校验,以确定rpm 包的来源是有效和安全的。这个选项如果设置在[main]部分,则对每个repository 都有效。默认值为0。

四、配置本地yum源

1、挂载系统安装光盘

# mount /dev/cdrom /mnt/cdrom/

2、配置本地yum源

# cd /etc/yum.repos.d/

# ls

会看到四个repo 文件

CentOS-Base.repo 是yum 网络源的配置文件

CentOS-Media.repo 是yum 本地源的配置文件

修改CentOS-Media.repo

# cat CentOS-Media.repo

# CentOS-Media.repo

#

# This repo is used to mount the default locations for a CDROM / DVD on

#  CentOS-5.  You can use this repo and yum to install items directly off the

#  DVD ISO that we release.

#

# To use this repo, put in your DVD and use it with the other repos too:

#  yum --enablerepo=c5-media [command]

#

# or for ONLY the media repo, do this:

#

#  yum --disablerepo=\* --enablerepo=c5-media [command]

[c5-media]

name=CentOS-$releasever - Media

baseurl=file:///media/CentOS/

file:///mnt/cdrom/

file:///media/cdrecorder/

gpgcheck=1

enabled=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

在baseurl 中修改第2个路径为/mnt/cdrom(即为光盘挂载点)

将enabled=0改为1

3、禁用默认的yum 网络源

将yum 网络源配置文件改名为CentOS-Base.repo.bak,否则会先在网络源中寻找适合的包,改名之后直接从本地源读取。

4、执行yum 命令

# yum install postgresql

其他国内yum源列表如下:

1. 企业贡献:
搜狐开源镜像站:http://mirrors.sohu.com/
网易开源镜像站:http://mirrors.163.com/

2. 大学教学:
北京理工大学:
http://mirror.bit.edu.cn (IPv4 only)
http://mirror.bit6.edu.cn (IPv6 only)
北京交通大学:
http://mirror.bjtu.edu.cn (IPv4 only)
http://mirror6.bjtu.edu.cn (IPv6 only)
http://debian.bjtu.edu.cn (IPv4+IPv6)
兰州大学:http://mirror.lzu.edu.cn/
厦门大学:http://mirrors.xmu.edu.cn/
清华大学:
http://mirrors.tuna.tsinghua.edu.cn/ (IPv4+IPv6)
http://mirrors.6.tuna.tsinghua.edu.cn/ (IPv6 only)
http://mirrors.4.tuna.tsinghua.edu.cn/ (IPv4 only)
天津大学:http://mirror.tju.edu.cn/
中国科学技术大学:
http://mirrors.ustc.edu.cn/ (IPv4+IPv6)
http://mirrors4.ustc.edu.cn/
http://mirrors6.ustc.edu.cn/
东北大学:
http://mirror.neu.edu.cn/ (IPv4 only)
http://mirror.neu6.edu.cn/ (IPv6 only)
电子科技大学:http://ubuntu.uestc.edu.cn/

实战演习:

第一步:查看yum 源配置文件配置阿里云的yum源

#ls /etc/yum.repos.d/

第二布:修改yum配置文件

#vi /etc/yum.repos.d/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

baseurl=http://mirrors.aliyun.com/centos/releasever/os/releasever/os/basearch/     #配置为阿里云的yum源

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=releasever&arch=basearch&repo=updates&infra=$infra   #注释掉原来的默认配置
baseurl=http://mirrors.aliyun.com/centos/releasever/updates/releasever/updates/basearch/         #配置为阿里云的yum源
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=releasever&arch=basearch&repo=extras&infra=$infra     #注释掉原来的默认配置
baseurl=http://mirrors.aliyun.com/centos/releasever/extras/releasever/extras/basearch/    #配置为阿里云的yum源
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=releasever&arch=basearch&repo=centosplus&infra=$infra    #注释掉原来的默认配置
baseurl=http://mirrors.aliyun.com/centos/releasever/centosplus/releasever/centosplus/basearch/   #配置为阿里云的yum源  

现在我们的yum配置好了

我们安装一个工具,我刚下好的系统连一个查看网卡的工具都没安装我们安装一个net-tools  和 openssh 工具,否则我们很难操作我刚安装好的这一台原始机。

第四步:运行yum命令

#yum install net-tools

输入:y

看到Complete!

OK net-tools 安装完毕

第五步:检测net-tools安装情况 

工具正常我们yum到此就安装结束。

现在我们的系统还不能远程登陆

因为系统缺少ssh服务插件,我们要安装一个远程服务的插件我们使用 openssh 这个远程插件

输入:y

到此ssh 服务就安装完毕

检测一下是否安装了ssh 服务软件

使用命令

#rpm -qa | grep ssh

我们看到这里ssh服务安装好了。

O啦!!!

注:内容转载至博客:https://www.cnblogs.com/qianxiaoruofeng/p/5762204.html

最新文章

  1. 防DDOS攻击SHELL脚本
  2. css3的@media媒体查询
  3. SQL--表分区
  4. 【jmeter】JMeter函数学习
  5. cnblog评价以及团队软件的部分改善
  6. eclipse加入git工具
  7. ONVIF Event消息解析(How to work with gSoap)
  8. 数据库DQL操作(重点)
  9. Dapper一个和petapoco差不多的轻量级ORM框架
  10. localStorage学习总结
  11. DOM-based XSS Test Cases
  12. sql sever 2012重装数据库时,出现cannot find one or more components, Please reinstall the application.解决方法
  13. vue实现原理
  14. java 开发 websocket 网页端聊天室
  15. SQL 本地数据库
  16. case功能菜单选项
  17. python 中 使用sys模块 获取运行脚本时在命令行输入的参数
  18. [Virus Analysis]恶意软件分析(二)玩出花的批处理(中)
  19. Pig安装与应用
  20. 51 Nod 1042 数位dp

热门文章

  1. Spring boot项目集成Sharding Jdbc
  2. win7右下角的同步中心怎么去除
  3. Win7剪贴板粘贴汉字显示为乱码的解决办法
  4. 【CF739E】Gosha is hunting(动态规划,凸优化)
  5. 51nod 1471 小S的兴趣 | 分块 链表
  6. 《剑指offer》— JavaScript(23)二叉搜索树的后序遍历序列
  7. c++ 顶层const与底层const
  8. pg中删除的页是否仍被访问
  9. ZeroMQ API(三) 消息
  10. Java并发编程原理与实战二十六:闭锁 CountDownLatch