1.首先进入/etc/yum.repos.d/目录下,新建一个repo_bak目录,用于保存系统中原来的repo文件
[root@bogon ~]# cd /etc/yum.repos.d/[root@bogon yum.repos.d]# mkdir repo_bak[root@bogon yum.repos.d]# mv *.repo repo_bak/
2.在CentOS中配置使用网易和阿里的开源镜像
到网易和阿里开源镜像站点下载系统对应版本的repo文件
[root@bogon yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo[root@bogon yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo[root@bogon yum.repos.d]# lsCentos-7.repo CentOS-Base-163.repo repo.bak
或者手动下载repo文件并上传到/etc/yum.repos.d/目录
3.清除系统yum缓存并生成新的yum缓存
[root@bogon yum.repos.d]#ls# 列出/etc/yum.repos.d/目录下的文件Centos-7.repoCentOS-Base-163.reporepo.bak[root@bogon yum.repos.d]#yumcleanall# 清除系统所有的yum缓存Loadedplugins:fastestmirror,langpacksRepositorybaseislistedmorethanonceintheconfigurationRepositoryupdatesislistedmorethanonceintheconfigurationRepositoryextrasislistedmorethanonceintheconfigurationRepositorycentosplusislistedmorethanonceintheconfigurationCleaningrepos:baseextrasupdatesCleaningupeverythingCleaninguplistoffastestmirrors[root@bogon yum.repos.d]#yummakecache# 生成yum缓存Loadedplugins:fastestmirror,langpacksRepositorybaseislistedmorethanonceintheconfigurationRepositoryupdatesislistedmorethanonceintheconfigurationRepositoryextrasislistedmorethanonceintheconfigurationRepositorycentosplusislistedmorethanonceintheconfigurationbase|3.6kB00:00:00extras|3.4kB00:00:00updates|3.4kB00:00:00(1/12):base/7/x86_64/filelists_db|6.7MB00:00:02(2/12):base/7/x86_64/group_gz|156kB00:00:02(3/12):base/7/x86_64/other_db|2.5MB00:00:01(4/12):base/7/x86_64/primary_db|5.7MB00:00:02(5/12):extras/7/x86_64/prestodelta|51kB00:00:01(6/12):extras/7/x86_64/filelists_db|494kB00:00:02(7/12):extras/7/x86_64/other_db|86kB00:00:00(8/12):extras/7/x86_64/primary_db|130kB00:00:01(9/12):updates/7/x86_64/prestodelta|406kB00:00:01(10/12):updates/7/x86_64/filelists_db|2.1MB00:00:01(11/12):updates/7/x86_64/other_db|354kB00:00:00(12/12):updates/7/x86_64/primary_db|3.6MB00:00:01DeterminingfastestmirrorsMetadataCacheCreated
4.安装epel源
[root@bogon yum.repos.d]# yum list | grep epel-releaseRepository baseislisted more than onceintheconfigurationRepository updatesislisted more than onceintheconfigurationRepository extrasislisted more than onceintheconfigurationRepository centosplusislisted more than onceintheconfigurationepel-release.noarch7-9extras [root@bogon yum.repos.d]# yum install -y epel-releaseLoaded plugins: fastestmirror, langpacksRepository baseislisted more than onceintheconfigurationRepository updatesislisted more than onceintheconfigurationRepository extrasislisted more than onceintheconfigurationRepository centosplusislisted more than onceintheconfigurationLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package epel-release.noarch 0:7-9 will be installed--> Finished Dependency ResolutionDependencies Resolved=============================================================================================================PackageArch Version Repository Size=============================================================================================================Installing: epel-releasenoarch7-9extras14kTransaction Summary=============================================================================================================Install1PackageTotal download size:14kInstalled size:24kDownloading packages:epel-release-7-9.noarch.rpm |14kB00:00:00Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : epel-release-7-9.noarch1/1Verifying : epel-release-7-9.noarch1/1Installed: epel-release.noarch0:7-9Complete![root@bogon yum.repos.d]# ls # epel源安装成功,比原来多了一个epel.repo和epel-testing.repo文件Centos-7.repo CentOS-Base-163.repo epel.repo epel-testing.repo repo.bak
5.使用阿里开源镜像提供的epel源
[root@bogon yum.repos.d]#wget-O/etc/yum.repos.d/epel-7.repohttp://mirrors.aliyun.com/repo/epel-7.repo # 下载阿里开源镜像的epel源文件--2018-03-0820:22:14--http://mirrors.aliyun.com/repo/epel-7.repoResolvingmirrors.aliyun.com(mirrors.aliyun.com)...183.2.199.237,113.96.109.95,113.96.109.93, ...Connectingtomirrors.aliyun.com(mirrors.aliyun.com)|183.2.199.237|:80...connected.HTTPrequestsent,awaitingresponse...200OKLength:1084(1.1K)[application/octet-stream]Savingto: ‘/etc/yum.repos.d/epel-7.repo’100%[=================================================================================================>]1,084--.-K/sin0s2018-03-0820:22:14(130MB/s)-‘/etc/yum.repos.d/epel-7.repo’saved[1084/1084][root@bogon yum.repos.d]#lsCentOS7-Base-163.repoCentos-7.repoepel-7.repoepel.repoepel-testing.reporepo_bak
6.再次清除系统yum缓存,并重新生成新的yum缓存
[root@bogon yum.repos.d]#yumcleanallLoadedplugins:fastestmirror,langpacksRepositorybaseislistedmorethanonceintheconfigurationRepositoryupdatesislistedmorethanonceintheconfigurationRepositoryextrasislistedmorethanonceintheconfigurationRepositorycentosplusislistedmorethanonceintheconfigurationRepositoryepelislistedmorethanonceintheconfigurationRepositoryepel-debuginfoislistedmorethanonceintheconfigurationRepositoryepel-sourceislistedmorethanonceintheconfigurationCleaningrepos:baseepelextrasupdatesCleaningupeverythingCleaninguplistoffastestmirrors[root@bogon yum.repos.d]#yummakecacheLoadedplugins:fastestmirror,langpacksRepositorybaseislistedmorethanonceintheconfigurationRepositoryupdatesislistedmorethanonceintheconfigurationRepositoryextrasislistedmorethanonceintheconfigurationRepositorycentosplusislistedmorethanonceintheconfigurationRepositoryepelislistedmorethanonceintheconfigurationRepositoryepel-debuginfoislistedmorethanonceintheconfigurationRepositoryepel-sourceislistedmorethanonceintheconfigurationbase|3.6kB00:00:00epel|4.7kB00:00:00extras|3.4kB00:00:00updates|3.4kB00:00:00(1/18):base/7/x86_64/group_gz|156kB00:00:01(2/18):base/7/x86_64/filelists_db|6.7MB00:00:07(3/18):base/7/x86_64/primary_db|5.7MB00:00:06(4/18):epel/x86_64/group_gz|266kB00:00:01(5/18):epel/x86_64/updateinfo|899kB00:00:02(6/18):epel/x86_64/prestodelta|7.1kB00:00:00(7/18):base/7/x86_64/other_db|2.5MB00:00:05(8/18):epel/x86_64/primary_db|6.3MB00:00:04(9/18):extras/7/x86_64/filelists_db|636kB00:00:00(10/18):extras/7/x86_64/primary_db|166kB00:00:00(11/18):extras/7/x86_64/other_db|108kB00:00:00(12/18):extras/7/x86_64/prestodelta|102kB00:00:01(13/18):epel/x86_64/other_db|3.0MB00:00:01(14/18):epel/x86_64/filelists_db|10MB00:00:09(15/18):updates/7/x86_64/filelists_db|3.5MB00:00:02(16/18):updates/7/x86_64/prestodelta|771kB00:00:02(17/18):updates/7/x86_64/other_db|621kB00:00:00(18/18):updates/7/x86_64/primary_db|6.0MB00:00:03Determiningfastestmirrors*epel:mirrors.aliyun.comMetadataCacheCreated
7.查看系统可用的yum源和所有的yum源
[root@bogon yum.repos.d]# yum repolist enabledLoaded plugins: fastestmirror, langpacksRepository baseislisted more than onceintheconfigurationRepository updatesislisted more than onceintheconfigurationRepository extrasislisted more than onceintheconfigurationRepository centosplusislisted more than onceintheconfigurationRepository epelislisted more than onceintheconfigurationRepository epel-debuginfoislisted more than onceintheconfigurationRepository epel-sourceislisted more than onceintheconfigurationLoading mirror speeds from cached hostfile * epel: mirrors.aliyun.comrepo id repo name statusbase/7/x86_64 CentOS-7- Base -163.com9,591epel/x86_64 Extra PackagesforEnterprise Linux7- x86_6412,382extras/7/x86_64 CentOS-7- Extras -163.com390updates/7/x86_64 CentOS-7- Updates -163.com1,941repolist:24,304[root@bogon yum.repos.d]# yum repolistallLoaded plugins: fastestmirror, langpacksRepository baseislisted more than onceintheconfigurationRepository updatesislisted more than onceintheconfigurationRepository extrasislisted more than onceintheconfigurationRepository centosplusislisted more than onceintheconfigurationRepository epelislisted more than onceintheconfigurationRepository epel-debuginfoislisted more than onceintheconfigurationRepository epel-sourceislisted more than onceintheconfigurationLoading mirror speeds from cached hostfile * epel: mirrors.aliyun.comrepo id repo name statusbase/7/x86_64 CentOS-7- Base -163.com enabled:9,591centosplus/7/x86_64 CentOS-7- Plus -163.com disabledcontrib/7/x86_64 CentOS-7- Contrib - mirrors.aliyun.com disabledepel/x86_64 Extra PackagesforEnterprise Linux7- x86_64 enabled:12,382epel-debuginfo/x86_64 Extra PackagesforEnterprise Linux7- x86_64 - Debug disabledepel-source Extra PackagesforEnterprise Linux7- x86_64 - Source disabledepel-testing/x86_64 Extra PackagesforEnterprise Linux7- Testing - x86_64 disabledepel-testing-debuginfo/x86_64 Extra PackagesforEnterprise Linux7- Testing - x86_64 - Debug disabledepel-testing-source/x86_64 Extra PackagesforEnterprise Linux7- Testing - x86_64 - Source disabledextras/7/x86_64 CentOS-7- Extras -163.com enabled:390updates/7/x86_64 CentOS-7- Updates -163.com enabled:1,941repolist:24,304