进入/etc/yum.repos.d/中,将原本的几个repo文件备份,之后新建三个repo文件,内容如下:
1.CentOS-Base.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
#mirrorlist=mirrorlist.centos.org/?release=$r…
baseurl=mirrors.ustc.edu.cn/centos/$rel…
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=mirrorlist.centos.org/?release=$r…
baseurl=mirrors.ustc.edu.cn/centos/$rel…
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=mirrorlist.centos.org/?release=$r…
baseurl=mirrors.ustc.edu.cn/centos/$rel…
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
#mirrorlist=mirrorlist.centos.org/?release=$r…
baseurl=mirrors.ustc.edu.cn/centos/$rel…
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
2.epel.repo:
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=mirrors.ustc.edu.cn/epel/7/$bas…
#mirrorlist=mirrors.fedoraproject.org/metalink?re…
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=mirrors.ustc.edu.cn/epel/7/$bas…
#mirrorlist=mirrors.fedoraproject.org/metalink?re…
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=mirrors.ustc.edu.cn/epel/7/SRPM…
#mirrorlist=mirrors.fedoraproject.org/metalink?re…
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
3.epel-testing.repo:
[epel-testing]
name=Extra Packages for Enterprise Linux 7 - Testing - $basearch
baseurl=mirrors.ustc.edu.cn/epel/testin…
#mirrorlist=mirrors.fedoraproject.org/metalink?re…
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-testing-debuginfo]
name=Extra Packages for Enterprise Linux 7 - Testing - $basearch - Debug
baseurl=mirrors.ustc.edu.cn/epel/testin…
#mirrorlist=mirrors.fedoraproject.org/metalink?re…
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-testing-source]
name=Extra Packages for Enterprise Linux 7 - Testing - $basearch - Source
baseurl=mirrors.ustc.edu.cn/epel/testin…
#mirrorlist=mirrors.fedoraproject.org/metalink?re…
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
最后执行yum clean all && makecache
后续遇到的关于yum问题
在使用yum install的时候,偶尔会碰见这样的错误: Couldn’t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
这是因为在你的 /etc/yum.repos.d 目录下有关于yum repository的配置文件中列有如下的GPG key:
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 1 这个配置告诉YUM,这个repository的GPG key存在于磁盘上。而当YUM在路径 /etc/pki/rpm-gpg 下找不到这个GPG key的时候,就会报如上的错误了。
解决方案:
cd /etc/pki/rpm-gpg
wget https://archive.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
然后再次运行 yum 命令就可以成功了。当然,也有些包是需要先安装epel之后才能装上的。安装epel的方法是: yum install -y epel-release