一、更换centos7或者centos8的镜像源

①:查看yum源(及:/etc/yum.repos.d/CentOS-Base.repo)文件。

  1. [greamrod@localhost ~]$ pwd
  2. /home/greamrod
  3. [greamrod@localhost ~]$
  4. [greamrod@localhost ~]$ ll /etc/yum.repos.d/CentOS-Base.repo
  5. -rw-r--r--. 1 root root 1664 10 23 2020 /etc/yum.repos.d/CentOS-Base.repo

②:备份原来的yum源(及:/etc/yum.repos.d/CentOS-Base.repo),这里备份后以后万一错误我们还可以恢复。

  1. [greamrod@localhost ~]$ su root
  2. 密码:
  3. [root@localhost greamrod]#
  4. [root@localhost greamrod]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  5. [root@localhost greamrod]#
  6. [root@localhost greamrod]# ll /etc/yum.repos.d/
  7. -rw-r--r--. 1 root root 1664 6 28 16:25 CentOS-Base.repo
  8. -rw-r--r--. 1 root root 1664 10 23 2020 CentOS-Base.repo.bak
  9. -rw-r--r--. 1 root root 1309 10 23 2020 CentOS-CR.repo
  10. -rw-r--r--. 1 root root 649 10 23 2020 CentOS-Debuginfo.repo
  11. -rw-r--r--. 1 root root 314 10 23 2020 CentOS-fasttrack.repo
  12. -rw-r--r--. 1 root root 630 10 23 2020 CentOS-Media.repo
  13. -rw-r--r--. 1 root root 1331 10 23 2020 CentOS-Sources.repo
  14. -rw-r--r--. 1 root root 8515 10 23 2020 CentOS-Vault.repo
  15. -rw-r--r--. 1 root root 616 10 23 2020 CentOS-x86_64-kernel.repo

③:先安装wget

  1. [root@localhost yum.repos.d]# yum -y install wget
  2. 已加载插件:fastestmirror, langpacks
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.ustc.edu.cn
  5. * extras: mirrors.ustc.edu.cn
  6. * updates: mirrors.ustc.edu.cn
  7. base | 3.6 kB 00:00:00
  8. extras | 2.9 kB 00:00:00
  9. updates | 2.9 kB 00:00:00
  10. 软件包 wget-1.14-18.el7_6.1.x86_64 已安装并且是最新版本
  11. 无须任何处理

④:下载新的CentOS-Base.repo/etc/yum.repos.d/

方式2:

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

  1. - `Centos8`镜像源
  2. ```bash
  3. # 方式1:
  4. wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
  5. # 方式2:
  6. curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

⑤:清除缓存

  1. [root@localhost yum.repos.d]# yum clean all
  2. 已加载插件:fastestmirror, langpacks
  3. 正在清理软件源: base extras updates
  4. Cleaning up list of fastest mirrors

⑥:生成缓存

  1. [root@localhost yum.repos.d]# yum makecache
  2. 已加载插件:fastestmirror, langpacks
  3. Determining fastest mirrors
  4. * base: mirrors.aliyun.com
  5. * extras: mirrors.aliyun.com
  6. * updates: mirrors.aliyun.com
  7. base | 3.6 kB 00:00:00
  8. extras | 2.9 kB 00:00:00
  9. updates | 2.9 kB 00:00:00
  10. (1/10): base/7/x86_64/group_gz | 153 kB 00:00:01
  11. (2/10): extras/7/x86_64/filelists_db | 235 kB 00:00:06
  12. (3/10): extras/7/x86_64/other_db | 143 kB 00:00:00
  13. (4/10): base/7/x86_64/other_db | 2.6 MB 00:00:14
  14. base/7/x86_64/primary_db FAILED ] 444 kB/s | 8.0 MB 00:00:53 ETA
  15. http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6d0c3a488c282fe537794b5946b01e28c7f44db79097bb06826e1c0c88bad5ef-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
  16. 正在尝试其它镜像。
  17. ....
  18. ....

⑦:更新最新yum

  1. yum -y update

二、总结

更换centos7或者centos8系统yum源时,一般情况下拿到服务器之后,不能直接执行yum -y update命令。一般都会用国内的镜像源重新升级最新,这个也是防止系统安全。

三、华为镜像源

华为镜像源:[https://mirrors.huaweicloud.com/home](https://mirrors.huaweicloud.com/home)