一、更换centos7或者centos8的镜像源
①:查看yum源(及:/etc/yum.repos.d/CentOS-Base.repo)文件。
[greamrod@localhost ~]$ pwd/home/greamrod[greamrod@localhost ~]$[greamrod@localhost ~]$ ll /etc/yum.repos.d/CentOS-Base.repo-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),这里备份后以后万一错误我们还可以恢复。
[greamrod@localhost ~]$ su root密码:[root@localhost greamrod]#[root@localhost greamrod]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak[root@localhost greamrod]#[root@localhost greamrod]# ll /etc/yum.repos.d/-rw-r--r--. 1 root root 1664 6月 28 16:25 CentOS-Base.repo-rw-r--r--. 1 root root 1664 10月 23 2020 CentOS-Base.repo.bak-rw-r--r--. 1 root root 1309 10月 23 2020 CentOS-CR.repo-rw-r--r--. 1 root root 649 10月 23 2020 CentOS-Debuginfo.repo-rw-r--r--. 1 root root 314 10月 23 2020 CentOS-fasttrack.repo-rw-r--r--. 1 root root 630 10月 23 2020 CentOS-Media.repo-rw-r--r--. 1 root root 1331 10月 23 2020 CentOS-Sources.repo-rw-r--r--. 1 root root 8515 10月 23 2020 CentOS-Vault.repo-rw-r--r--. 1 root root 616 10月 23 2020 CentOS-x86_64-kernel.repo
③:先安装wget
[root@localhost yum.repos.d]# yum -y install wget已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile* base: mirrors.ustc.edu.cn* extras: mirrors.ustc.edu.cn* updates: mirrors.ustc.edu.cnbase | 3.6 kB 00:00:00extras | 2.9 kB 00:00:00updates | 2.9 kB 00:00:00软件包 wget-1.14-18.el7_6.1.x86_64 已安装并且是最新版本无须任何处理
④:下载新的CentOS-Base.repo到/etc/yum.repos.d/
Centos7镜像源 ```bash方式1:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
方式2:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
- `Centos8`镜像源```bash# 方式1:wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo# 方式2:curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
⑤:清除缓存
[root@localhost yum.repos.d]# yum clean all已加载插件:fastestmirror, langpacks正在清理软件源: base extras updatesCleaning up list of fastest mirrors
⑥:生成缓存
[root@localhost yum.repos.d]# yum makecache已加载插件:fastestmirror, langpacksDetermining fastest mirrors* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.combase | 3.6 kB 00:00:00extras | 2.9 kB 00:00:00updates | 2.9 kB 00:00:00(1/10): base/7/x86_64/group_gz | 153 kB 00:00:01(2/10): extras/7/x86_64/filelists_db | 235 kB 00:00:06(3/10): extras/7/x86_64/other_db | 143 kB 00:00:00(4/10): base/7/x86_64/other_db | 2.6 MB 00:00:14base/7/x86_64/primary_db FAILED ] 444 kB/s | 8.0 MB 00:00:53 ETAhttp://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"正在尝试其它镜像。........
⑦:更新最新yum源
yum -y update
二、总结
更换centos7或者centos8系统yum源时,一般情况下拿到服务器之后,不能直接执行yum -y update命令。一般都会用国内的镜像源重新升级最新,这个也是防止系统安全。
三、华为镜像源
华为镜像源:[https://mirrors.huaweicloud.com/home](https://mirrors.huaweicloud.com/home)
