You can use and reference the following built-in variables in yum commands and in all Yum configuration files (that is, /etc/yum.conf and all .repo files in the /etc/yum.repos.d/ directory):
$releasever
You can use this variable to reference the release version of Red Hat Enterprise Linux. Yum obtains the value of $releasever from the distroverpkg=value line in the /etc/yum.conf configuration file. If there is no such line in/etc/yum.conf, then yum infers the correct value by deriving the version number from the redhat-releasepackage. The value of $releasever typically consists of the major release number and the variant of Red Hat Enterprise Linux, for example 6Client, or 6Server.
$arch
You can use this variable to refer to the system's CPU architecture as returned when calling Python's os.uname() function. Valid values for $arch include i686 and x86_64.
$basearch
You can use $basearch to reference the base architecture of the system. For example, i686 machines have a base architecture of i386, and AMD64 and Intel64 machines have a base architecture of x86_64.
$YUM0-9
These ten variables are each replaced with the value of any shell environment variables with the same name. If one of these variables is referenced (in /etc/yum.conf for example) and a shell environment variable with the same name does not exist, then the configuration file variable is not replaced.
To define a custom variable or to override the value of an existing one, create a file with the same name as the variable (without the “$” sign) in the /etc/yum/vars/ directory, and add the desired value on its first line.
For example, repository descriptions often include the operating system name. To define a new variable called $osname, create a new file with “Red Hat Enterprise Linux” on the first line and save it as /etc/yum/vars/osname:
~]# echo "Red Hat Enterprise Linux" > /etc/yum/vars/osname
Instead of “Red Hat Enterprise Linux 6”, you can now use the following in the .repo files:
name=$osname $releasever

CentOS/RHEL系统下yum配置中$releasever的来源

因为要将一个系统从RHEL AS 3升级到CentOS 3,遇到了yum.conf配置中$releasever变量返回3AS的情况。暂时手工更改为3,但后来更新yum之后,$releasever又返回Null。毕竟总是手工更改太麻烦,所以为此特意google了一番,而且没有白费功夫。

参见文献:https://lists.dulug.duke.edu/pipermail/yum/2004-July/004752.html
原文中如此描述:
rpm -q --qf %{version} redhat-release
then look in your yum.conf for what distroverpkg is set to.
于是执行了一下上述命令,返回3AS
然后再看yum.conf中distroverpkg的配置,发现为redhat-release,后来更新后其值变为centos-release。
于是执行rpm -q --qf %{version} centos-release,返回信息为package centos-release is not installed。终于明白是少安装了一个程序包,所以返回Null。下载centos-release-3-9.1.i386.rpm,但是在安装时发现与redhat-release-3AS-7.3冲突。执行rpm -qa |grep redhat-release-3AS,发现系统上确实安装了redhat-release-3AS-7.3,看来就是这二个包起作用,而且变量$releasever就是从包名称中取得。
卸载redhat-release-3AS-7.3,安装centos-release-3-9.1,再执行
rpm -q --qf %{version} centos-release
返回结果为3。

-bash: yum: command not found 问题解决

操作系统是centos5.6 x86_64,不同的机器已安装的包有所区别,关键是掌握方法。

1下载yum的rpm安装包

[root@localhost rpm]# wget http://mirror.centos.org/centos/5.7/os/x86_64/CentOS/yum-3.2.22-37.el5.centos.noarch.rpm

2 [root@localhost rpm]# rpm -qa | grep yum   //确定没有安装yum的rpm包
3 [root@localhost rpm]# rpm -ivh yum-3.2.22-37.el5.centos.noarch.rpm
error: Failed dependencies:
        yum-fastestmirror is needed by yum-3.2.22-37.el5.centos.noarch
        yum-metadata-parser >= 1.1.0 is needed by yum-3.2.22-37.el5.centos.noarch

需要安装依赖的包

4 找第一个依赖

[root@localhost rpm]# wget http://mirror.centos.org/centos/5.7/os/x86_64/CentOS/yum-fastestmirror-1.1.16-16.el5.centos.noarch.rpm

5 安装时发现依赖于yum,这个问题可以两个rpm包一起安装解决,先解决第二个依赖

[root@localhost rpm]# rpm -ivh yum-fastestmirror-1.1.16-16.el5.centos.noarch.rpm


error: Failed dependencies:
        yum >= 3.0 is needed by yum-fastestmirror-1.1.16-16.el5.centos.noarch

6 先解决第二个依赖

[root@localhost rpm]# rpm -ivh yum-metadata-parser-1.1.2-3.el5.centos.x86_64.rpm


error: Failed dependencies:
        libxml2.so.2()(64bit) is needed by yum-metadata-parser-1.1.2-3.el5.centos.x86_64

7 发现依赖,下载安装

[root@localhost rpm]# wget http://mirror.centos.org/centos/5.7/os/x86_64/CentOS/ libxml2-2.6.26-2.1.12.x86_64.rpm


 [root@localhost rpm]# rpm -ivh libxml2-2.6.26-2.1.12.x86_64.rpm
Preparing...                ########################################### [100%]
   1:libxml2                ########################################### [100%]

8 第二个依赖解决,如果还是缺少包,继续下载安装。可以登录http://mirror.centos.org/centos/5.7/os/x86_64/CentOS/ 去找

[root@localhost rpm]# rpm -ivh yum-metadata-parser-1.1.2-3.el5.centos.x86_64.rpm


Preparing...                ########################################### [100%]
   1:yum-metadata-parser    ########################################### [100%]

9 检验一下yum包的依赖情况

[root@localhost rpm]# rpm -ivh yum-fastestmirror-1.1.16-16.el5.centos.noarch.rpm


error: Failed dependencies:
        yum >= 3.0 is needed by yum-fastestmirror-1.1.16-16.el5.centos.noarch
[root@localhost rpm]# rpm -ivh yum-3.2.22-37.el5.centos.noarch.rpm
error: Failed dependencies:
        yum-fastestmirror is needed by yum-3.2.22-37.el5.centos.noarch
10  两个一起安装,解决
[root@localhost rpm]# rpm -ivh yum-3.2.22-37.el5.centos.noarch.rpm yum-fastestmirror-1.1.16-16.el5.centos.noarch.rpm
Preparing...                ########################################### [100%]
   1:yum-fastestmirror      ########################################### [ 50%]

2:yum                    ########################################### [100%]

11 有需要可以yum -y update

Dealing with yum checksum errors

I support a couple of yum repositories, and use the yum repository build instructions documented in my previous post to create my repositories. When I tried to apply the latest CentOS 5.3 updates to one of my servers last week, I noticed that I was getting a number of “Error performing checksum” errors:

yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
Updates | 1.2 kB 00:00
primary.xml.gz | 376 kB 00:00
http://updates/repo/centos/5.3/updates/repodata/primary.xml.gz: [Errno -3] Error performing checksum
Trying other mirror.
primary.xml.gz | 376 kB 00:00
http://updates/repo/centos/5.3/updates/repodata/primary.xml.gz: [Errno -3] Error performing checksum
Trying other mirror.
Error: failure: repodata/primary.xml.gz from Updates: [Errno 256] No more mirrors to try.

After reading through the code in yumRepo.py, I noticed that the error listed above is usually generated when the checksum algorithm specified in the repomd.xml file isn’t supported. The createrepo utility uses the sha256 algorithm by default in Fedora 11 (I created my repositories on a Fedora 11 host), so I decided to create my repository using the sha1 algorithm instead:

$ createrepo -v -s sha1 /var/www/html/repo/centos/5.3/updates

Once I created the repository metadata using the sha1 algorithm, everything worked as expected:

yum clean all
Loaded plugins: fastestmirror
Cleaning up Everything
Cleaning up list of fastest mirrors

yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
Updates | 1.0 kB 00:00
primary.xml.gz | 367 kB 00:00
Updates 634/634
repo id repo name status
Updates Updates enabled : 634
repolist: 634

This debugging experience made me realize two things:

1. Having your package manager written in Python makes debugging super easy

2. Python 2.6 uses hashlib to perform checksums, and Python 2.4 uses the SHA module to perform checksums. The version of the SHA module that ships with CentOS 5.3 doesn’t support sha256, which is why we get the checksum error listed above.

I had a h00t debugging this issue, and am glad everything is working correctly now! Nice!

CentOS yum之$releasever和$basearch

查看关于yum的配置

ls /etc/yum* -ld:

查看/etc/yum.repos.d下的文件

查看CentOS-Base.repo内容:

部分内容:

[base]
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-pgg/RPM-GPG-KEY-CentOS-6
[update]
baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

我们看出来里面包含大量的变量:

$releasever和$basearch

$releasever的值,这个表示当前系统的发行版本,可以通过如下命令查看:

rpm -qi centos-release

结果如下:

其中的Version:6就是我们系统的版本号

$basearch是我们的系统硬件架构(CPU指令集),就是我们常说的i386\i486\i586\i686\...

使用如下命令即可:

arch

输出如下:

我这个处理器是i686,现在所有的intel 32位体系(包括AMD等兼容CPU)都叫i386体系,包括P4。i686仍然属于i386体系,不过对CPU(相对于386)的特性作了指令优化。 GNU/Linux分为i386、alpha、PowerPC、Sun等各个不同版本,所有从Intel386-P4都用i386版本,但i386版本中
有几个内核(i386,i486,i586,i686),安装时安装程序检测到你得CPU级别后,自动为你安装相应内核。

在Linux中使用命令arch可以初步查看出当前系统所识别出来的机器CPU类型,如"i386",
"i486","i586", "alpha", "sparc", "arm", "m68k","mips","ppc","ia64","x86_64"等;ia64和x86_64就说明这台机器是64位的;

所以我这儿要使用i386作为$basearch的值

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

完整路径便是

baseurl=http://mirror.centos.org/centos/6/os/i386/

顺便提一下,windows下获取系统信息的命令:systeminfo.exe

Using Yum Variables的更多相关文章

  1. Linux: yum配置说明

    下面是利用 man yum.conf 命令获取到的有关yum配置的说明: yum.conf(5) yum configuration file yum.conf(5) NAME yum.conf - ...

  2. CentOS 7.0 使用 yum 安装 MariaDB 与 MariaDB 的简单配置

    1.安装MariaDB 安装命令 yum -y install mariadb mariadb-server 安装完成MariaDB,首先启动MariaDB,两条命令都可以 systemctl sta ...

  3. MySQL5.7安装与配置(YUM)

    安装环境:CentOS7 64位,MySQL5.7 1.配置YUM源 在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/  # ...

  4. 学习 Mysql - 在linux上使用yum安装MySQL

    1.检查已经安装的mysql信息 yum list installed mysql*rpm -qa | grep mysql* 2.列出已安装和可安装的mysql信息 yum list mysql* ...

  5. CentOS下用yum配置php+mysql+apache(LAMP)

    #安装需要的包,有依赖关系,自动帮你解决 yum install httpd mysql mysql-server php php-gd php-mbstring php-mysql #启动httpd ...

  6. Linux下使用yum安装MariaDB

    版本:centos7 Linux下安装MariaDB官方文档参见:https://mariadb.com/kb/zh-cn/installing-mariadb-with-yum/ 1.创建Maria ...

  7. CentOS 7 yum nginx MySQL PHP 简易环境搭建

    用centos自带的yum源来安装nginx,mysql和php,超级方便,省去编译的麻烦,省去自己配置的麻烦,还能节省非常多的时间. 我们先把yum源换成国内的阿里云镜像源(当然不换也可以),先备份 ...

  8. centos用yum安装mysql-server

    1.安装:#yum -y install mysql-server 2.修改配置:#vi /etc/my.cnf 暂时修改一下编码(添加在密码下方添加): default-character-set ...

  9. CentOS环境下yum安装LAMP(Linux+Apache+Mysql+php)

    CentOS下使用yum命令 安装LAMP详细过程.我们使用的软件是CentOS的最新版本CentOS 6.3,其他版本的也基本类似. 第一步:更新系统内核(如果不想更新可以跳过本步). 首先更新系统 ...

随机推荐

  1. poi excel导出,下载

    poi.jar包 public void downExcel(HttpServletResponse response,Page<ShopApply> page) throws Excep ...

  2. [CareerCup] 18.2 Shuffle Cards 洗牌

    18.2 Write a method to shuffle a deck of cards. It must be a perfect shuffle—in other words, each of ...

  3. JAVA6开发WebService (一)

    转载自http://wuhongyu.iteye.com/blog/807470 WebService是SOA的一种较好的实现方式,它将应用程序的不同功能单元通过中立的契约(独立于硬件平台.操作系统和 ...

  4. Oracle rac集群环境中的特殊问题

    备注:本文摘抄于张晓明<大话Oracle RAC:集群 高可用性 备份与恢复> 因为集群环境需要多个计算机协同工作,要达到理想状态,必须要考虑在集群环境下面临的新挑战. 1.并发控制 在集 ...

  5. 管闲事的小明-nyoj51

    描述某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0,1,2,……,L,都种有一棵 ...

  6. BizTalk开发系列(十) ESB Guidance安装笔记

    ESB指导工具包(ESB Guidance)是一个运行于BizTalk Server 2006 R2之上的一个框架.详细信息访问ESB指导工具包社区网站 .源码下载 ESB Guidance的安装过程 ...

  7. 用Scala实现集合中相邻元素间的差值

    欢迎转载,转载请注明出处,徽沪一郎. 概要 代码这东西,不写肯定不行,新学Scala不久,将实际遇到的一些问题记录下来,日后也好查找. 今天讲的是如何计算同一集合中元素两两之间的差值,即求开始集合(a ...

  8. python - socket - server

    网络上关于socket的介绍文章数不胜数.自己记录下学习的点点滴滴.以供将来复习学习使用. socket中文的翻译是套接字,总感觉词不达意.简单的理解就是ip+port形成的一个管理单元.也是程序中应 ...

  9. 分割excel sheet

    Sub split_sheet() '输入用户想要拆分的工作表 Dim sheet_name sheet_name = Application.InputBox("请输入拆分工作表的名称:& ...

  10. 纯CSS实现tooltip提示框,CSS箭头及形状之续篇--给整个tooltip提示框加个边框

    在前面一篇中我们介绍了纯CSS实现tooltip提示框,通俗的讲也就是CSS箭头及形状 不过注意一点是,他始终是一个元素,只是通过CSS实现的,今天我们要说的是给这个“tooltip提示框”整体加一个 ...