由于RHEL的yum在线更新是收费的,如果没有注册的话是不能使用的,即不能在线安装软件。在这种情况下,如果我们使用的机器安装的是RHEL系统要是每次安装软件先挂载本地光盘会很繁琐,而且有些软件也是老版本的,这种情况下我们可以借助CentOS的YUM源来满足我们的需求。
一、删除RHEL原有的YUM
[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
[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导入系统,否则会出现以下的警告信息
[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了,
[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源
[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 行的字样,最后保存退出
[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完成
yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
yum install -y yum-utils device-mapper-persistent-data lvm2
添加docker的源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
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
[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
EPEL (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额外的软件包,适用于RHEL、CentOS和Scientific Linux.
官方网址为:https://fedoraproject.org/wiki/EPEL
EPEL是yum的一个软件源,里面包含了许多基本源里没有的软件。安装上EPEL的源后,就可以直接用yum来安装软件,而且EPEL不会替换原有的源,安装后会产生新repo,省去了不少麻烦。
EPEL包含一个叫做epel-release的包,这个包包含了EPEL源的gpg密钥和软件源信息。通过yum安装到您的企业版Linux发行版上。除了epel-release源,还有一个叫做epel-testing的源,这个源包含最新的测试软件包,其版本很新但是安装有风险
可以下载EPEL软件包后,通过以下命令安装EPEL:
# rpm -ivh epel-release-6-8.noarch.rpm
或者:
# rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release-6-8.noarch.rpm (32位)
# rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm (64位)
如果EPEL已经安装到你的CentOS了,则EPEL源的配置安装文件一般为/etc/yum.repos.d/epel.repo。
查看已经安装的epel: # rpm -qa | grep epel