centos7.9 更换默认源为阿里源

 

1、查看系统

[root@centos7pc1 test]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@centos7pc1 test]# hostnamectl
   Static hostname: centos7pc1
         Icon name: computer-vm
           Chassis: vm
        Machine ID: d44b8799f26a411a87bb728b10e24a41
           Boot ID: 3ce29e0ab14f40cfbb2f47c98d1bc248
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1160.62.1.el7.x86_64
      Architecture: x86-64

 

2、查看当前源

[root@centos7pc1 test]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo          epel.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  CentOS-x86_64-kernel.repo  epel-testing.repo

 

3、备份当前源

[root@centos7pc1 test]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
[root@centos7pc1 test]# ls /etc/yum.repos.d/
CentOS-Base.repo_bak  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo          epel.repo
CentOS-CR.repo        CentOS-fasttrack.repo  CentOS-Sources.repo  CentOS-x86_64-kernel.repo  epel-testing.repo

 

4、下载阿里源

[root@centos7pc1 test]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2022-05-02 19:34:37--  https://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 111.63.55.248, 111.63.55.242, 111.63.55.244, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|111.63.55.248|:443... 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

2022-05-02 19:34:37 (1.20 GB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]

[root@centos7pc1 test]# ls /etc/yum.repos.d/
CentOS-Base.repo      CentOS-Debuginfo.repo  CentOS-Sources.repo        epel.repo
CentOS-Base.repo_bak  CentOS-fasttrack.repo  CentOS-Vault.repo          epel-testing.repo
CentOS-CR.repo        CentOS-Media.repo      CentOS-x86_64-kernel.repo

 

5、清空缓存、生成缓存

[root@centos7pc1 test]# yum clean all            ## 清空缓存
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base epel extras updates
Cleaning up list of fastest mirrors
[root@centos7pc1 test]# yum makecache            ## 生成缓存
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
epel/x86_64/metalink                                                                                          | 7.5 kB  00:00:00
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                          | 3.6 kB  00:00:00
epel                                                                                                          | 4.7 kB  00:00:00
extras                                                                                                        | 2.9 kB  00:00:00
updates                                                                                                       | 2.9 kB  00:00:00
(1/16): base/7/x86_64/group_gz                                                                                | 153 kB  00:00:00
(2/16): base/7/x86_64/filelists_db                                                                            | 7.2 MB  00:00:00
(3/16): epel/x86_64/group_gz                                                                                  |  96 kB  00:00:00
(4/16): base/7/x86_64/primary_db                                                                              | 6.1 MB  00:00:00
(5/16): base/7/x86_64/other_db                                                                                | 2.6 MB  00:00:00
(6/16): epel/x86_64/filelists_db                                                                              |  12 MB  00:00:00
(7/16): epel/x86_64/updateinfo                                                                                | 1.0 MB  00:00:00
(8/16): epel/x86_64/prestodelta                                                                               |  553 B  00:00:00
(9/16): epel/x86_64/primary_db                                                                                | 7.0 MB  00:00:00
(10/16): epel/x86_64/other_db                                                                                 | 3.4 MB  00:00:00
(11/16): extras/7/x86_64/filelists_db                                                                         | 277 kB  00:00:00
(12/16): extras/7/x86_64/primary_db                                                                           | 246 kB  00:00:00
(13/16): extras/7/x86_64/other_db                                                                             | 147 kB  00:00:00
(14/16): updates/7/x86_64/primary_db                                                                          |  15 MB  00:00:00
(15/16): updates/7/x86_64/filelists_db                                                                        | 8.2 MB  00:00:00
(16/16): updates/7/x86_64/other_db                                                                            | 1.0 MB  00:00:00
Metadata Cache Created

 

6、测试

[root@centos7pc1 test]# yum reinstall httpd -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-97.el7.centos.5 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================
 Package                   Arch                       Version                                      Repository                   Size
=====================================================================================================================================
Reinstalling:
 httpd                     x86_64                     2.4.6-97.el7.centos.5                        updates                     2.7 M

Transaction Summary
=====================================================================================================================================
Reinstall  1 Package

Total download size: 2.7 M
Installed size: 9.4 M
Downloading packages:
httpd-2.4.6-97.el7.centos.5.x86_64.rpm                                                                        | 2.7 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : httpd-2.4.6-97.el7.centos.5.x86_64                                                                                1/1
  Verifying  : httpd-2.4.6-97.el7.centos.5.x86_64                                                                                1/1

Installed:
  httpd.x86_64 0:2.4.6-97.el7.centos.5

Complete!

没有问题。

 

posted @ 2022-05-02 19:38  小鲨鱼2018  阅读(3329)  评论(0编辑  收藏  举报