由于RHEL的yum在线更新是收费的,如果没有注册的话是不能使用的,即不能在线安装软件。在这种情况下,如果我们使用的机器安装的是RHEL系统要是每次安装软件先挂载本地光盘会很繁琐,而且有些软件也是老版本的,这种情况下我们可以借助CentOS的YUM源来满足我们的需求。
一、删除RHEL原有的YUM
1
2
3
4
|
[root@justin ~]
# rpm -qa|grep yum|xargs rpm -e --nodeps
warning:
/etc/yum
.conf saved as
/etc/yum
.conf.rpmsave
[root@justin src]
# yum install php
-
bash
:
/usr/bin/yum
: 没有那个文件或目录
|
二、下载CentOS的yum安装包
python-iniparse:http://mirror.centos.org/centos-6/6.4/os/i386/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
yum-metadata-parser:http://mirror.centos.org/centos-6/6.4/os/i386/Packages/yum-metadata-parser-1.1.2-16.el6.i686.rpm
yum:http://mirror.centos.org/centos-6/6.4/os/i386/Packages/yum-3.2.29-40.el6.centos.noarch.rpm
yum-plugin-fastestmirror:http://mirror.centos.org/centos-6/6.4/os/i386/Packages/yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm
RPM-GPG-KEY:http://mirror.centos.org/centos-6/6.4/os/i386/RPM-GPG-KEY-CentOS-6
或者在此下载:http://url.cn/TBZzqQ
1
2
3
4
5
6
7
8
9
10
|
[root@justin src]
# wget http://mirror.centos.org/centos-6/6.4/os/i386/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
[root@justin src]
# wget http://mirror.centos.org/centos-6/6.4/os/i386/Packages/yum-metadata-parser-1.1.2-16.el6.i686.rpm
[root@justin src]
# wget http://mirror.centos.org/centos-6/6.4/os/i386/Packages/yum-3.2.29-40.el6.centos.noarch.rpm
[root@justin src]
# wget http://mirror.centos.org/centos-6/6.4/os/i386/Packages/yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm
[root@justin src]
# wget http://mirror.centos.org/centos-6/6.4/os/i386/RPM-GPG-KEY-CentOS-6
[root@justin src]
# ls
python-iniparse-0.3.1-2.1.el6.noarch.rpm yum-metadata-parser-1.1.2-16.el6.i686.rpm
RPM-GPG-KEY-CentOS-6 yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm
yum-3.2.29-40.el6.centos.noarch.rpm
[root@justin src]
#
|
三、安装CentOS的YUM安装包
yum和yum-plugin-fastestmirror需要一起安装,这两个包存在依赖关系,分开安装会失败,安装之前先把RPM-GPG-KEY导入系统,否则会出现以下的警告信息
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@justin src]
# rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm
warning: python-iniparse-0.3.1-2.1.el6.noarch.rpm: Header V3 RSA
/SHA256
Signature, key ID c105b9de: NOKEY
Preparing...
########################################### [100%]
package python-iniparse-0.3.1-2.1.el6.noarch is already installed
[root@justin src]
# rpm --import RPM-GPG-KEY-CentOS-6
[root@justin src]
# rpm -ivh yum-metadata-parser-1.1.2-16.el6.i686.rpm
Preparing...
########################################### [100%]
1:yum-metadata-parser
########################################### [100%]
[root@justin src]
# rpm -ivh yum-3.2.29-40.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm
Preparing...
########################################### [100%]
1:yum-plugin-fastestmirro
########################################### [ 50%]
2:yum
########################################### [100%]
[root@justin src]
#
|
至此我们就可以在线使用yum了,
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
|
[root@justin yum.repos.d]
# yum install php
Loaded plugins: fastestmirror, product-
id
, subscription-manager
Updating certificate-based repositories.
Unable to
read
consumer identity
Determining fastest mirrors
rhel-
local
| 4.0 kB 00:00 ...
rhel-
local
/primary_db
| 2.5 MB 00:00 ...
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php.i686 0:5.3.3-3.el6_2.8 will be installed
--> Processing Dependency: php-common = 5.3.3-3.el6_2.8
for
package: php-5.3.3-3.el6_2.8.i686
--> Processing Dependency: php-cli = 5.3.3-3.el6_2.8
for
package: php-5.3.3-3.el6_2.8.i686
--> Running transaction check
---> Package php-cli.i686 0:5.3.3-3.el6_2.8 will be installed
---> Package php-common.i686 0:5.3.3-3.el6_2.8 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================
Installing:
php i686 5.3.3-3.el6_2.8 rhel-
local
1.1 M
Installing
for
dependencies:
php-cli i686 5.3.3-3.el6_2.8 rhel-
local
2.2 M
php-common i686 5.3.3-3.el6_2.8 rhel-
local
523 k
Transaction Summary
===============================================================================================================================
Install 3 Package(s)
Total download size: 3.8 M
Installed size: 12 M
Is this ok [y
/N
]:
|
四、修改yum源
为了使用在线使用Yum安装软件更快,我们可以使用国内的网易Yum源或者其他国内yum源
下载网易Yum源
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
|
[root@justin yum.repos.d]
# pwd
/etc/yum
.repos.d
[root@justin yum.repos.d]
# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
[root@justin yum.repos.d]
# ls
CentOS6-Base-163.repo CentOS-
test
.repo packagekit-media.repo rhel-
local
.repo rhel-
local
.repobak rhel-
source
.repo
[root@justin yum.repos.d]
# cat CentOS6-Base-163.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 - 163.com
baseurl=http:
//mirrors
.163.com
/centos/
$releasever
/os/
$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http:
//mirror
.centos.org
/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
baseurl=http:
//mirrors
.163.com
/centos/
$releasever
/updates/
$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http:
//mirror
.centos.org
/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
baseurl=http:
//mirrors
.163.com
/centos/
$releasever
/extras/
$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http:
//mirror
.centos.org
/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http:
//mirrors
.163.com
/centos/
$releasever
/centosplus/
$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http:
//mirror
.centos.org
/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - 163.com
baseurl=http:
//mirrors
.163.com
/centos/
$releasever
/contrib/
$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http:
//mirror
.centos.org
/centos/RPM-GPG-KEY-CentOS-6
[root@justin yum.repos.d]
#
|
下载好网易yum源后需要修改下整个文件里的$releasever和$basearch;$releasever变量为具体版本号,通过rpm -qi centos-release命令查看;$basearch的取值系统硬件架构(CPU指令集),使用命令arch得到
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
完整路径便是
baseurl=http://mirror.centos.org/centos/6/os/x86_64/
编辑文件CentOS-Base-163.repo,在末行模式下输入:% s/$releasever/6/g替换整个文件下的$releasever为6,替换成功后会提示15 次替换,共 15 行的字样,最后保存退出
1
2
3
4
5
|
[root@justin yum.repos.d]
# vim CentOS6-Base-163.repo
....
baseurl=http:
//mirrors
.163.com
/centos/6/contrib/
$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib
:% s/$releasever
/6/g
|
最后清除缓存,为了使后面使用Yum更效率的管理软件,可以把服务器上的的软件包信息缓存到本地,以提高搜索安装软件的速度
至此,RHEL使用CentOS的YUM完成
EPEL
EPEL的全称叫 Extra Packages for Enterprise Linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源,而且大多数rpm包在官方 repository 中是找不到的,绝大多数rpm包要比官方repository 的rpm包版本要来得新。
不用去换原来yum源,安装后会产生新repo,epel会有很多源地址,如果一个下不到,会去另外一个下,更新时如果下载的包不全,就不会进行安装。这样的话,依赖关系可以保重。
安装epel,centos6选6,5就选5:下载地址:http://dl.fedoraproject.org/pub/epel/
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
导入key:rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
1
2
3
4
5
6
|
[root@localhost yum.repos.d]
# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA
/SHA256
Signature, key ID 0608b895: NOKEY
Preparing...
########################################### [100%]
1:epel-release
########################################### [100%]
[root@localhost yum.repos.d]
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[root@localhost yum.repos.d]
# yum -y install yum-priorities
|