CentOS 7更换阿里或者163 yum源和epel源

#备份默认的yum源
#下载国内的yum源
–163源
–阿里源
#清理缓存文件 //可以不用执行
#生成新源的元文件 //可以不用执行
#安装epel源
#查看yum源和epel源

#备份默认的yum源
[root@localhost ~]# cd /etc/yum.repos.d/ //进入yum文件目录
[root@localhost yum.repos.d]# ls //查看目录下文件
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@localhost yum.repos.d]# mv *.repo /tmp //将所有文件移动到tmp目录

#下载国内的yum源 //二者任意选一个
–163源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo //下载163 yum源文件到当前目录
–阿里源
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo //下载阿里yum源文件到当前目录
–2020-05-15 10:17:49-- http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)… 202.104.186.227, 119.147.156.227, 113.96.181.211, …
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|202.104.186.227|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ?etc/yum.repos.d/CentOS-Base.repo?

100%[===================================================>] 2,523 --.-K/s in 0s

2020-05-15 10:17:50 (6.18 MB/s) - ?etc/yum.repos.d/CentOS-Base.repo?saved [2523/2523]
[root@localhost yum.repos.d]# sed -i s/\$basearch/x86_64/g CentOS-Base.repo //将下载的文件中$basearch替换成x86_64
[root@localhost yum.repos.d]# sed -i s/\$releasever/7/g CentOS-Base.repo //将下载的文件中$releasever替换成7

#清理缓存文件
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors

#生成新源的元文件
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors

  • base: mirrors.aliyun.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: (28, ‘Connection timed out after 30002 milliseconds’)
    Trying other mirror.
    http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - “Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error”
    Trying other mirror.
    base | 3.6 kB 00:00:00
    extras | 2.9 kB 00:00:00
    updates | 2.9 kB 00:00:00
    (1/10): base/group_gz | 153 kB 00:00:00
    (2/10): base/filelists_db | 7.1 MB 00:00:02
    (3/10): base/primary_db | 6.1 MB 00:00:02
    (4/10): base/other_db | 2.6 MB 00:00:00
    (5/10): extras/primary_db | 194 kB 00:00:00
    (6/10): extras/filelists_db | 205 kB 00:00:00
    (7/10): extras/other_db | 122 kB 00:00:00
    (8/10): updates/primary_db | 1.3 MB 00:00:00
    (9/10): updates/other_db | 192 kB 00:00:00
    (10/10): updates/filelists_db | 997 kB 00:00:00
    Metadata Cache Created

#安装epel源
[root@localhost yum.repos.d]# yum list|grep epel-release //查看epel文件
epel-release.noarch 7-11 extras

[root@localhost yum.repos.d]# yum install epel-release -y //安装epel源
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

  • base: mirrors.aliyun.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    Resolving Dependencies
    –> Running transaction check
    —> Package epel-release.noarch 0:7-11 will be installed
    –> Finished Dependency Resolution

    Installing:
    epel-release noarch 7-11 extras 15 k

    Install 1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
epel-release-7-11.noarch.rpm | 15 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-11.noarch 1/1
Verifying : epel-release-7-11.noarch 1/1

Installed:
epel-release.noarch 0:7-11

Complete!

#查看yum源和epel源
[root@localhost yum.repos.d]# yum repolist enabled //所有enable 的源
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

  • base: mirrors.aliyun.com
  • epel: hkg.mirror.rackspace.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    repo id repo name status
    base CentOS-7 - Base - mirrors.aliyun.com 10,070
    epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,306
    extras CentOS-7 - Extras - mirrors.aliyun.com 397
    updates CentOS-7 - Updates - mirrors.aliyun.com 722
    repolist: 24,495

你可能感兴趣的:(linux)