|
|
CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org; Name or service not known“之解决办法(换源)
9 @+ k+ `$ t" e t& D/ z1 S& U, c2 z2 _' I
6 [, w0 r7 q) L3 V- }+ L5 C9 U
[root@zabbix-server ~]# yum install devtoolset-11-gcc*
5 v1 f6 B7 _# f! G$ z- _1 l. V9 ?Loaded plugins: fastestmirror; n% ` ~% M/ X7 L: V+ e" H
Loading mirror speeds from cached hostfile
* |4 G, d1 |; E( zCould not retrieve mirrorlist http://mirrorlist.centos.org/?re ... =os&infra=stock error was8 N- G+ J3 I2 ^ Z
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
# i B: l" E* E: m! d4 t v' W: @% f, N8 x2 G5 [8 h, {9 [7 V; U
+ E. S& F$ J! c% F# R7 E One of the configured repositories failed (Unknown),, |9 V! D3 i) O. R" k7 e
and yum doesn't have enough cached data to continue. At this point the only
0 i+ x8 V1 x! G! ~, j; h safe thing yum can do is fail. There are a few ways to work "fix" this:
$ j/ b# F2 Y0 W& I" [7 ]6 K! M. u% H8 |0 z6 y1 Z$ b
1. Contact the upstream for the repository and get them to fix the problem.. h$ ~ w& \1 t/ P
; M4 ?" p+ a I2 M; ^ z! _
2. Reconfigure the baseurl/etc. for the repository, to point to a working
4 u( `4 b2 h, I upstream. This is most often useful if you are using a newer
4 z9 a7 ~( [5 ?* }6 g/ ] distribution release than is supported by the repository (and the
! }! G2 R# m. ]5 O packages for the previous distribution release still work).! ]4 @( `" v' U/ n+ W% K0 B
* K5 i% U- r9 v, }9 T( n
3. Run the command with the repository temporarily disabled
% |+ [; J3 _* ]+ Y" A3 m yum --disablerepo=<repoid> ...
- @" L! J4 Z) m( W: l
$ L) {* j V: V' z7 i 4. Disable the repository permanently, so yum won't use it by default. Yum( F8 v1 B& b# l* p3 N; M
will then just ignore the repository until you permanently enable it
3 X3 ^& O7 B( W" x2 w$ b again or use --enablerepo for temporary usage:
3 A/ [2 Z j# ?4 b" `/ j& y* c, W- t! F3 K6 q A i0 l
yum-config-manager --disable <repoid>
; J1 q$ r" g6 e' d- ^ or
3 b% h+ H: S0 h* f4 D/ `# y subscription-manager repos --disable=<repoid>
( P/ _* D8 Y% X0 a/ [+ ]' O; ~) i: @+ C8 }2 y: U$ i7 Y
5. Configure the failing repository to be skipped, if it is unavailable.9 N5 n0 ~2 t% n# D3 N, }/ N) R
Note that yum will try to contact the repo. when it runs most commands,
/ J( ?# ?4 d! f" r so will have to try and fail each time (and thus. yum will be be much
. S& U* O7 G9 Z* i9 D2 ~ slower). If it is a very temporary problem though, this is often a nice$ D* o! k' ?4 Q( Q
compromise:, j% x( }: X0 I) P( O! n
) ?; I6 c$ o; |& M$ e1 m
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
5 w& ?% N3 ^. h X2 q/ _3 N- `, b. ^5 C" [! c
Cannot find a valid baseurl for repo: base/7/x86_64
1 W. e9 J' s' v" ^! T4 I6 q1 [) s+ ?! n- e+ X. G
- b2 }9 S3 W% @0 }0 X' B6 {/ z/ }+ }
3 F* T5 G3 J, j/ f! E【解决办法】. r8 E9 P3 z/ ?' v5 B+ c4 Z5 |
- s6 B& l; ?1 e B
0 ^) B7 @& b% T' D8 b5 |
; t8 T; X) K( K$ c) ? {( O" c看到报错日志中加粗的字体,命令行ping mirrorlist.centos.org 不通。试着ping www.baidu.com是正常的,说明DNS解析没问题。基本确认是yum源的问题。+ C& ~5 q! I% k' ^
8 t3 m9 C4 ]3 r" W: z, z- j3 V- ^/ ^
- i( e% P1 J4 L6 {9 P/ [
$ A7 z2 q# E jCentOS7更换镜像源$ f/ T& G/ {3 |* J$ [$ ~. F
1、先安装wget
3 ?) W" w" B5 I' o: d) b" `$ w3 u$ `7 i" h( j9 n: j
yum install -y wget
2 x# w' ~5 Q6 B# k2 h0 ^, {: u- x! x& q. N/ I
. v6 x: S3 B N# Y$ J4 s) t# h x8 r8 K @; K0 G/ q+ E u
2、打开阿里镜像http://mirrors.aliyun.com/
7 j8 B0 M$ z, K- I' E3 _8 S7 H; N' X: D
点击,帮助,查看详情:: h5 a- v# @3 J: \/ S, Q1 ~
/ O7 k0 |! V8 V7 N( X% q+ P! O* U. ]& w
: T5 ?& T1 e! r0 M# |
3、下载CentOS 7的对应的repo文件& ]/ S& _- |+ d, j$ P! w: q( h
2 Y) ?' y* J( E, Z' t/ X, nwget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
5 n+ {8 }% ?+ ^, o; g4 }" d: P$ f: U6 P. g1 ?5 r+ Z* |
#或者5 D$ I$ u7 Q6 l0 o/ M* U
% O0 w: X0 r8 |( Ocurl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo5 _$ h$ Q9 n9 n) `5 l% H: ?! t# c
) _: Q' `7 }7 a
. w! V& C: B3 H7 Y2 Z, |
) n& ]( q* ~! }, S |
|