CentOS进行yum操作时不能访问国外镜像的解决方案
Posted zhoushiya
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS进行yum操作时不能访问国外镜像的解决方案相关的知识,希望对你有一定的参考价值。
1. 例如执行yum update,经常报错“Cound not resolve host: xxxxx”,一般都是yum源是使用的国外镜像,国内访问很不好。这时可以将源手动替换为国内的清华大学源,或者阿里云源之类的。
详细使用方法可以参考https://mirrors.tuna.tsinghua.edu.cn/help/centos/,镜像站使用帮助,选择自己的版本即可。
下面贴出CentOS 7版本下,清华源的配置
1 # CentOS-Base.repo 2 # 3 # The mirror system uses the connecting IP address of the client and the 4 # update status of each mirror to pick mirrors that are updated to and 5 # geographically close to the client. You should use this for CentOS updates 6 # unless you are manually picking other mirrors. 7 # 8 # If the mirrorlist= does not work for you, as a fall back you can try the 9 # remarked out baseurl= line instead. 10 # 11 # 12 13 [base] 14 name=CentOS-$releasever - Base 15 baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/ 16 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os 17 gpgcheck=1 18 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 19 20 #released updates 21 [updates] 22 name=CentOS-$releasever - Updates 23 baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/ 24 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates 25 gpgcheck=1 26 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 27 28 #additional packages that may be useful 29 [extras] 30 name=CentOS-$releasever - Extras 31 baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/ 32 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras 33 gpgcheck=1 34 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 35 36 #additional packages that extend functionality of existing packages 37 [centosplus] 38 name=CentOS-$releasever - Plus 39 baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/ 40 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus 41 gpgcheck=1 42 enabled=0 43 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
PS 如果觉得命令行使用不方便,可以直接用SFTP连上之后进行文件编辑。
2. 另外内核升级时可能用到/etc/yum.repos.d/elrepo.repo文件,也同样可以将其修改为清华大学的源。
同样贴出清华大学elrepo.repo源配置
### Name: 清华大学开源镜像 ### URL: https://mirrors.tuna.tsinghua.edu.cn/elrepo/ [elrepo] name=ELRepo.org Community Enterprise Linux Repository - el7 baseurl=https://mirrors.tuna.tsinghua.edu.cn/elrepo/elrepo/el7/$basearch/ #mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo.el7 enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org protect=0 [elrepo-testing] name=ELRepo.org Community Enterprise Linux Testing Repository - el7 baseurl=https://mirrors.tuna.tsinghua.edu.cn/elrepo/testing/el7/$basearch/ #mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-testing.el7 enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org protect=0 [elrepo-kernel] name=ELRepo.org Community Enterprise Linux Kernel Repository - el7 baseurl=https://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el7/$basearch/ #mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-kernel.el7 enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org protect=0 [elrepo-extras] name=ELRepo.org Community Enterprise Linux Extras Repository - el7 baseurl=https://mirrors.tuna.tsinghua.edu.cn/elrepo/extras/el7/$basearch/ #mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-extras.el7 enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org protect=0
以上是关于CentOS进行yum操作时不能访问国外镜像的解决方案的主要内容,如果未能解决你的问题,请参考以下文章