redhat7 配置centos yum源及 epel源

2018年7月10日10:05:03redhat7 配置centos yum源及 epel源已关闭评论 16
摘要

由于在默认情况下,RedHat 7的Yum没有源,并且RedHat的Yum源只对注册的用户生效。如果不使用Yum的话,很多软件的彼此依赖关系的确让人心累,所以手动改成Centos的Yum源就行了。

由于在默认情况下,RedHat 7的Yum没有源,并且RedHat的Yum源只对注册的用户生效。如果不使用Yum的话,很多软件的彼此依赖关系的确让人心累,所以手动改成Centos的Yum源就行了。

redhat7 配置centos yum源及 epel源

1.首先配置光盘源

# cd /etc/yum.repos.d/

# vi mycdrom.repo #新建一个repo文件

[Base]

name=RHEL5 ISO Base

baseurl=file:///mnt/Server

enabled=1

gpgcheck=0

:wq

OK!把光盘放进去,然后挂载到服务器

# mount /dev/cdrom /mnt

如提示未安装 yum , 到/mnt/Packages 中安装

# rpm -ivh yum-3.*.rpm yum-metadata-parser-*.rpm

# yum install wget #Yum安装 wget

删除redhat原有的yum ,因为redhat 原本的yum 没有注册为redhat用户是用不了的。

rpm -aq|grep yum|xargs rpm -e --nodeps

2.安装epel源

#wget -c https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

#rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

下载完后本地安装

# rpm -ivh epel-release-7-11.noarch.rpm

导入key:

#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

配置EPEL YUM源

在rhel中执行命令:

#yum repolist

报错:

Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

安装了epel-release-7-11.noarch.rpm以后,会在/etc/yum.repos.d目录下,新增两个文件:

epel.repo   //这是标准的epel源,经过测试,并且比较稳定的

epel-testing.repo  //这是最新的,正在测试阶段。

默认情况下,yum 会搜索/etc/yum.repos.d目录下所有的文件,搜索其中的yum 源。搜索的前提是enable=1,如果是enable=0就不搜索该源了。

打开epel.repo后发现,只有第一项[epel]是enable=1的。其他都是0.说明这项是有问题。可问题在哪里呢?

手工在ie中访问源地址https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch。发现没有问题。

接下来,把这个文件里的http://download.fedoraproject.org/pub替换成https://mirrors.tuna.tsinghua.edu.cn即可。

修改结果如下

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

使用命令测试:

#yum repolist

运行 yum update 测试一下吧。

可以看到,系统成功连接到epel源了。

3.设置CentOS 阿里源163源、Tuna源(清华源)、shu源(上大源)

#配置Tuna源

# cd /etc/yum.repos.d

# vi rhel-source.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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

# sed -i 's/\$releasever/7.5.1804/g' rhel-source.repo

# vi rhel-source.repo

:0,$s/\$releasever/7.5.1804/g

:wq

下载安装KEY

#cd /etc/pki/rpm-gpg/

#wget -c https://mirrors.tuna.tsinghua.edu.cn/centos/7.5.1804/os/x86_64/RPM-GPG-KEY-CentOS-7

导入key:

#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

清理yum缓存

yum clean all

yum makecache #将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度

yum install gcc #测试安装软件

ITBIJI