配置使用yum安装升级linux系统和软件

来源:互联网 发布:ubuntu写c语言 编辑:程序博客网 时间:2024/06/05 06:44

使用yum安装升级特定系统和软件:

该文包括yum配置文件和repo文件详解,以及将redhat5.1升级到redhat5.11两部分



一、yum的安装查看

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

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

题,保持与RPM数据库的一致性。


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

[root@localhostyum.repos.d]# rpm -qa|grep yum

PackageKit-yum-0.5.8-26.el6.x86_64

anaconda-yum-plugins-1.0-5.1.el6.noarch

yum-metadata-parser-1.1.2-16.el6.x86_64

yum-3.2.29-40.el6.centos.noarch

yum-plugin-security-1.1.30-14.el6.noarch

yum-utils-1.1.30-14.el6.noarch

yum-plugin-fastestmirror-1.1.30-14.el6.noarch

PackageKit-yum-plugin-0.5.8-26.el6.x86_64


yum的基础安装包包括:

yum  //RPMinstaller/updater

yum-fastestmirror  //Yumplugin which chooses fastest repository from a mirrorlist

yum-metadata-parser  //Afast metadata parser for yum


2、安装yum

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

[root@localhost/] # mount /dev/cdrom /mnt/cdrom/

[root@localhost/]# rpm -ivh yum-3.2.22-33.el5.centos.noarch.rpmyum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpmyum-metadata-parser-

1.1.2-3.el5.centos.i386.rpm

[root@localhost/]# yum –v


二、yum配置

1、说明:

yum的配置文件分为两部分:mainrepository

main部分定义了全局配置选项,整个yum配置文件应该只有一个main。常位于/etc/yum.conf中。

repository部分定义了每个源/服务器的具体配置,可以有一到多个。常位于/etc/yum.repo.d目录下的各文件中。

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

其中:

repo文件是Linuxyum源(软件仓库)的配置文件,通常一个repo文件定义了一个或者多个软件仓库的细节内容,例如我们将从哪里

下载需要安装或者升级的软件包,repo文件中的设置内容将被yum读取和应用!

YUM的工作原理并不复杂,每一个RPM软件的头(header)里面都会纪录该软件的依赖关系,那么如果可以将该头的内容纪录下来并

且进行分析,可以知道每个软件在安装之前需要额外安装哪些基础软件。也就是说,在服务器上面先以分析工具将所有的RPM档案进

行分析,然后将该分析纪录下来,只要在进行安装或升级时先查询该纪录的文件,就可以知道所有相关联的软件。所以YUM的基本

工作流程如下:

服务器端:在服务器上面存放了所有的RPM软件包,然后以相关的功能去分析每个RPM文件的依赖性关系,将这些数据记录成文件存

放在服务器的某特定目录内。

客户端:如果需要安装某个软件时,先下载服务器上面记录的依赖性关系文件(可通过WWWFTP方式),通过对服务器端下载的纪录

数据进行分析,然后取得所有相关的软件,一次全部下载下来进行安装。


2yum.conf文件详解

[root@localhost~]# vi /etc/yum.conf

[main]

cachedir=/var/cache/yum/$basearch/$releasever

#cachediryum缓存的目录,yum在此存储下载的rpm包和数据库,一般是/var/cache/yum/$basearch/$releasever

keepcache=0

#设置keepcache=1yum在成功安装软件包之后保留缓存的头文件(headers)和软件包。默认值为keepcache=0不保存

debuglevel=2

#debuglevel:除错级别,0──10,缺省为2

logfile=/var/log/yum.log

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

pkgpolicy=newest

#pkgpolicy:包的策略。一共有两个选项,newestlast,这个作用是如果你设置了多个repository,而同一软件在不同的repository中同

时存在,yum应该安装哪一个,如果是newest,则yum会安装最新的那个版本。如果是last,则yum会将服务器id以字母表排序,并选

择最后的那个服务器上的软件安装。一般都是选newest

tolerant=1

#tolerent,也有10两个选项,表示yum是否容忍命令行发生与软件包有关的错误,比如你要安装1,2,3三个包,而其中3此前已经安

装了,如果你设为1,yum不会出现错误信息。默认是0

exactarch=1

#exactarch,有两个选项10,代表是否只升级和你安装软件包cpu体系一致的包,如果设置为1,则yum只会安装和系统架构匹配的软

件包,例如,yum不会将i686的软件包安装在适合i386的系统中。默认为1

obsoletes=1

#相当于upgrade,允许更新陈旧的RPM

retries=20

#retries,网络连接发生错误后的重试次数,如果设为0,则会无限重试

gpgcheck=1

#gpgchkeck=10两个选择,分别代表是否是否进行gpg校验,如果没有这一项,默认是检查的

plugins=1

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

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


reposdir=/etc/yy.rm

#默认是/etc/yum.repos.d/低下的xx.repo后缀文件

#reposdir=[包含.repo文件的目录的绝对路径]

该选项用户指定.repo文件的绝对路径。.repo文件包含软件仓库的信息(作用与/etc/yum.conf文件中的[repository]片段相同)

默认都会被include进来 也就是说/etc/yum.repos.d/xx.repo无论配置文件有多少个每个里面有多少个[name]最后其实都被整合到一个里

面看就是了 重复的[name]后面的覆盖前面的

exclude=xxx

#exclude排除某些软件在升级名单之外,可以用通配符,列表中各个项目要用空格隔开,这个对于安装了诸如美化包,中文补丁时特

别有用。

distroverpkg=centos-release

#指定一个软件包,yum会根据这个包判断你的发行版本,默认是redhat-release,也可以是安装的任何针对自己发行版的rpm包。



# This is the default, if you make this bigger yum won't see if themetadata

#is newer on the remote and so you'll "gain" the bandwidthof not having to

#download the new metadata and "pay" for it by yum nothaving correct

#information.

# It is esp. important, to have correct metadata, for distributionslike

#Fedora which don't keep old packages around. If you don't like thischecking

#interupting your command line usage, it's much better to havesomething

#manually check the metadata once an hour (yum-updatesd will do this).

#metadata_expire=90m


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

#in /etc/yum.repos.d


3repo文件详解:

[root@localhostetc]# cd /etc/yum.repos.d/

[root@localhostyum.repos.d]# ls

adobe-linux-x86_64.repo CentOS6.5-Media.repo CentOS-Debuginfo.repo CentOS-Vault.repo

backup CentOS-Base.repo CentOS-Media.repo

[root@localhostyum.repos.d]# vim CentOS-Base.repo


#CentOS-Base.repo

#

#The mirror system uses the connecting IP address of the client andthe

#update status of each mirror to pick mirrors that are updated to and

#geographically close to the client. You should use this for CentOSupdates

#unless you are manually picking other mirrors.

#

#If the mirrorlist= does not work for you, as a fall back you can trythe

#remarked out baseurl= line instead.

#

#


[base]

name=CentOS-$releasever– Base

#name=Some name for this server

name,是对repository的描述,支持像$releasever$basearch这样的变量;

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

#mirrorlist指定一个镜像服务器的地址列表,通常是开启的,将$releasever$basearch替换成自己对应的版本和架构,例如

i386,在浏览器中打开,就能看到一长串镜可用的镜像服务器地址列表。

#变量说明:$releasever,发行版的版本,从[main]部分的distroverpkg获取,如果没有,则根据redhat-release包进行判断。

$archcpu体系,如i686,athlon

$basearchcpu的基本体系组,如i686athlon同属i386alphaalphaev6同属alpha


baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

#baseurl=url://path/to/repository/

#baseurl事从服务器获取软件的路径,只有设置正确,才能从上面获取软件。基本格式是:

baseurl=url://server1/path/to/repository/

url://server2/path/to/repository/

url://server3/path/to/repository/

其中url支持的协议有http://ftp://file://三种。baseurl后可以跟多个url,你可以自己改为速度比较快的镜像站,但baseurl只能有一个,

其中url指向的目录必须是这个repositoryheader目录的上一级,它也支持$releasever$basearch这样的变量。


gpgcheck=1

#设置是否进行包检测

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

#导入每个reposityGPGkeyyum可以使用gpg对包进行校验,确保下载包的完整性,所以我们先要到各个repository站点找到

gpgkey,一般都会放在首页的醒目位置,一些名字诸如RPM-GPG-KEY.txt之类的纯文本文件,把它们下载,然后用rpm--import xxx.txt

令将它们导入,最好把发行版自带GPG-KEY也导入,rpm--import /usr/share/doc/redhat-release-*/RPM-GPG-KEY 官方软件升级用的上。


#releasedupdates

[updates]

name=CentOS-$releasever- Updates

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/

gpgcheck=1

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


#additionalpackages that may be useful

[extras]

name=CentOS-$releasever- Extras

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/

gpgcheck=1

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


#

#


[base]

name=CentOS-$releasever- Base

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

gpgcheck=1

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


#releasedupdates

[updates]

name=CentOS-$releasever- Updates

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/

gpgcheck=1

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


#additionalpackages that may be useful

[extras]

name=CentOS-$releasever- Extras

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/

gpgcheck=1

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


#additionalpackages that extend functionality of existing packages


4、使用光盘文件做本地yum源:

[root@localhostyum.repos.d]# vim CentOS6.5-Media.repo


[c6-media]

name=CentOS-$releasever- Media

#本地yum源名称(可随意修改)

baseurl=file:///mnt/iso

#光盘挂载目录/mnt/iso

gpgcheck=1

enabled=1

#使用此yum源(等于0为不启用)

gpgkey=file:///mnt/sr0/RPM-GPG-KEY-CentOS-6

#本地yum源密钥


三、使用特定yum源升级redhat系统(此过程仅演示RHEL5.15.6升级到RHEL5.11)

1清除旧的repo文件,此处提供两种方式:

1.a、更改enabled的值为0,确保它没有使用dvd.repo

[root@localhost ~]# cd /etc/yum.repos.d/

[root@localhost yum.repos.d]#grep enabled*.repo

Verifyany "enabled = 1" on *.repo files (except redhat.repo)

[root@localhost yum.repos.d]#vi local.repo

changeenabled = 0

1.b、重命名repo文件

[root@localhost ~]# cd /etc/yum.repos.d/

[root@localhost yum.repos.d]#mvlocal.repo local.repo.bak

[root@localhost yum.repos.d]#rm -fr/var/cache/yum/*

[root@localhost yum.repos.d]#yum clean all


2、创建临时repo文件从特定服务器获取源RPM文件,可以采用不同IP从不同服务器获取远的策略。

[root@localhost yum.repos.d]# vi/etc/yum.repos.d/local.repo

[temp_rhel511_repos]

name=Temporary RHEL5.11 Repos

baseurl=http://xxx.xxx.xxx.xxx/repos

enabled=1

gpgcheck=0


3过去的yum更新,并尝试获取repo更新列表

[root@localhost yum.repos.d]# yum clean all

Loadedplugins: rhnplugin, security

Cleaningup Everything

[root@localhost yum.repos.d]# yum repolist

Loadedplugins: rhnplugin, security

Thissystem is not registered with RHN.

RHNsupport will be disabled.

temp_rhel511_repos | 951 B 00:00

temp_rhel511_repos/primary | 3.4 MB 00:00

temp_rhel511_repos 9664/9664

repoid repo name status

temp_rhel511_repos Temporary RHEL5.11 Repos enabled: 9,664

repolist:9,664


-->Verify the system is pointing to the temporary repository


4、更新系统

[root@localhost yum.repos.d]# yum update

Loadedplugins: rhnplugin, security

Thissystem is not registered with RHN.

RHNsupport will be disabled.

Skippingsecurity plugin, no data

Settingup Update Proces

......

xorg-x11-server-Xorg.x86_640:1.1.1-48.107.el5_11 xorg-x11-server-utils.x86_640:7.1-5.el5_6.2

……

zlib-devel.x86_640:1.2.3-7.el5

zsh.x86_640:4.2.6-10.el5_11


Complete!


5、重启系统

[root@localhost yum.repos.d]# reboot

Broadcastmessage from root (pts/2) (Wed Jan 25 11:22:16 2017):


Thesystem is going down for reboot NOW!

[root@localhost ~]#

Lastlogin: Wed Jan 25 11:10:51 2017 from 172.23.33.204


6、重启完检查系统版本,是否更新到特定版本

[root@localhost ~]# cat /etc/redhat-release

RedHat Enterprise Linux Server release 5.11 (Tikanga)


7安装订阅管理器subscription-manager以便将来更新补丁加入Satellite


[root@localhost ~]# yum install subscription-manager

Loadedplugins: security

Settingup Install Process

……..

Installed:

subscription-manager.i3860:1.11.3-14.el5_11

subscription-manager.x86_640:1.11.3-14.el5_11


DependencyInstalled:

libnl.x86_640:1.0-0.10.pre5.5 python-dateutil.noarch 0:1.2-3.el5

python-ethtool.x86_640:0.6-5.el5 python-rhsm.x86_64 0:1.11.3-5.el5

python-simplejson.x86_640:2.0.9-8.el5 virt-what.x86_64 0:1.11-2.el5


Complete!

[root@localhost ~]# yum list | grep subscription-manager

Loadedplugins: product-id, security, subscription-manager

Thissystem is not registered to Red Hat Subscription Management. You canuse subscription-manager to register.

subscription-manager.i386 1.11.3-14.el5_11 installed

subscription-manager.x86_64 1.11.3-14.el5_11 installed

subscription-manager-firstboot.i386

subscription-manager-firstboot.x86_64

subscription-manager-gnome.i386 0.98.16.3-1.el5_8 temp_rhel511_repos

subscription-manager-gnome.x86_640.98.16.3-1.el5_8 temp_rhel511_repos

subscription-manager-gui.i386 1.11.3-14.el5_11 temp_rhel511_repos

subscription-manager-gui.x86_64 1.11.3-14.el5_11 temp_rhel511_repos

subscription-manager-migration.i386

subscription-manager-migration.x86_64

subscription-manager-migration-data.noarch



0 0
原创粉丝点击