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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM