日期:2014-05-16  浏览次数:20713 次

linux redhat下配置yum

        最近由于项目需要使用到服务器,就申请了阿里云的云服务器,选择了redhat5,但是阿里云给的是裸系统,除了基本的系统,没有其他库,很多软件安装都不行,提示很多依赖没有,需要先安装依赖库。于是,想到了yum安装,但是总是无法执行,网上查找才发现,其实redhat默认不提供yum库,因为redhat虽然使用免费,但是很多其他服务都是收费的,我的个去了!但是centos是完全免费的,阿里云也提供了切换操作系统的功能,但是又要向注册手机发送验证码,最重要的是,以前的上传到服务器中的软件都会丢失,一想好半天才传上去的东西,不容易啊。于是,坚持使用redhat,肯定有其他办法能把yum运行起来。

 

        网上寻找了半天,终于有哥们跟我一样的问题,他找到了一个yum库地址。而且确实管用,于是把步骤写下来,以备后用,也希望能帮到跟我一样摸索的同仁们!

 

【步骤一:修改yum.cnf 】


yum.cnf是yum程序的配置文件,位于:/etc/yum.cnf,默认配置如下:

[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1

# Note: yum-RHN-plugin doesn't honor this.
metadata_expire=1h

# Default.
# installonly_limit = 3

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

#disable install i386 i686 package and can't update kernel(过滤掉32位的包)
exclude=*.i?86 kernel kernel-xen kernel-debug


其实上面默认可以不改动,唯一要改动的就是最后一句:exclude=*.i?86 kernel kernel-xen kernel-debug
主要作用是忽略 i386等32为内核的系统,我这里的服务器是64位的,所以此语留着,否则在使用yum

install <库名> 会出现32位和64位相同的包,全装会出现两个,导致程序无法启动。如果是32位电脑就

将此行注释掉,前面加上#即可。

【步骤二:修改rhel-debuginfo.repo 】

rhel-debuginfo.repo是yum的库配置文件,位于:/etc/yum.repos.d目录下面。
为了安全,在修改rhel-debuginfo.repo之前,需要先进行备份,命令如下:
-bash-3.2# cd /etc/yum.repos.d/
-bash-3.2# cp rhel-debuginfo.repo rhel-debuginfo.repo.bak
然后
-bash-3.2# vi rhel-debuginfo.repo
将如下配置覆盖到rhel-debuginfo.repo

[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$basearch/Debuginfo/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[base]
name=Red Hat Enterprise Linux $releasever -Base
baseurl=http://ftp.twaren.net/Linux/CentOS/5/os/$basearch/
gpgcheck=1
[update]
name=Red Hat Enterprise Linux $releasever -Updates
baseurl=http://ftp.twaren.net/Linux/CentOS/5/updates/$basearch/
gpgcheck=1
[extras]
name=Red Hat Enterprise Linux $releasever -Extras
baseurl=http://ftp.twaren.net/Linux/CentOS/5/extras/$basearch/
gpgcheck=1
[addons]
name=Red Hat Enterprise Linux $releasever -Addons
baseurl=http://ftp.twaren.net/Linux/CentOS/5/addons/$basearch/
gpgcheck=1

          经过,面两步的设置就可以正确使用yum install <软件名称>命令进行软件安装了。比如,如果要安装mysql,就可以使用:
-bash-3.2# yum install mysql
先从库中查找对应的软件,如果找到就会提示,下载并安装,下面几乎是提示,只要输入Y/N即可。