找回密码
 注册
查看: 24|回复: 0

CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org; Name or service n

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2024-11-22 17:05:27 | 显示全部楼层 |阅读模式
CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org; Name or service not known“之解决办法(换源)
5 t- C& k$ h" t, \: g  _9 J' X  E; w, y" x  R) w0 A1 A

5 q# m6 s) m$ [+ G5 |5 p. E[root@zabbix-server ~]# yum install devtoolset-11-gcc*
( j  n& J; D- J1 }3 k9 B3 t# T2 uLoaded plugins: fastestmirror+ |1 |  F$ a9 q' I, l0 q9 H- H8 {
Loading mirror speeds from cached hostfile( y& ]" ~! c( P' Q
Could not retrieve mirrorlist http://mirrorlist.centos.org/?re ... =os&infra=stock error was
/ \9 B4 K0 S: h" u3 W14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"8 H( h7 a* S& {, m; {) Z" ^; g
5 n* W1 o1 E7 D1 t; \# D9 K* d( [9 u
2 l( C7 ^6 l" G
One of the configured repositories failed (Unknown),& a9 Q& K. C; z# L& a
and yum doesn't have enough cached data to continue. At this point the only
, o8 |- b# q9 \( ~4 j  Y safe thing yum can do is fail. There are a few ways to work "fix" this:
8 m! V  o7 E/ P
9 Q( R  Y0 @: b0 f) n5 w' p. d     1. Contact the upstream for the repository and get them to fix the problem.
% C* d$ F) l1 q% z$ x$ Z( ^& f/ F: G6 g) ?# J" W
     2. Reconfigure the baseurl/etc. for the repository, to point to a working
0 K( f6 y4 u% h$ W2 p9 I# r1 \" G        upstream. This is most often useful if you are using a newer8 i9 k* p/ K. S" W6 X" R% a
        distribution release than is supported by the repository (and the
  J% T. V* a0 X9 @& A! y4 y* o        packages for the previous distribution release still work).
3 r4 `" b, w. r/ a0 c' e# k* D1 A. }+ @: e/ H/ F9 A
     3. Run the command with the repository temporarily disabled& v% B8 I2 X8 {
            yum --disablerepo=<repoid> ...$ s9 N5 @2 p$ V) B+ T& g, a* r/ C
/ h: D- U0 _) s) w7 x* @4 T
     4. Disable the repository permanently, so yum won't use it by default. Yum
+ _- }$ v7 e* b; b5 R        will then just ignore the repository until you permanently enable it
0 P8 a3 D4 U3 w* J: D8 c        again or use --enablerepo for temporary usage:
5 o8 P$ A" e1 [6 b8 L4 W2 t
# X0 u& p1 _" ]# b1 J: F3 O# {+ A            yum-config-manager --disable <repoid>6 }0 C; R. A+ s' q2 L; J4 H$ i
        or
7 N; U% z* P  ^2 d3 \; L1 o            subscription-manager repos --disable=<repoid>
8 k* m# z$ f8 x1 i
% t/ X0 R7 v) E  M) S! S4 G     5. Configure the failing repository to be skipped, if it is unavailable.
: w, t5 M# p( S# K' c' B: O. Y        Note that yum will try to contact the repo. when it runs most commands,
6 c9 a! X3 N" f# V7 x; `        so will have to try and fail each time (and thus. yum will be be much
: x0 D. e2 n2 m- K2 ]$ E        slower). If it is a very temporary problem though, this is often a nice9 Z7 n# I3 R; Y. w9 D
        compromise:
5 e6 I* |/ Z7 |' d: s& `8 N% d* p
            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true+ R0 |8 i4 x) k. {6 s+ |% ]. @
' g% {. G* I# a6 K
Cannot find a valid baseurl for repo: base/7/x86_64
' D1 j- W+ {: j( A
9 N2 {$ s/ N$ F) H; L0 m, a9 a! N' X: Q" C. R3 @

; F( N2 X- j$ k! E4 ^$ w【解决办法】
) F6 d: R+ o3 A, D( S& w( J2 _7 t. T! I! o/ r

4 [' y3 j( G- H9 V0 ~/ o
! Z$ I* A: y! [1 U! f, q% f看到报错日志中加粗的字体,命令行ping mirrorlist.centos.org 不通。试着ping www.baidu.com是正常的,说明DNS解析没问题。基本确认是yum源的问题。
) \+ t8 S0 J- d7 p" ]6 `7 b
. X9 A: P* U3 |! W% i- i6 g$ J$ F+ N; X6 ~; r$ I* ?! o$ \

2 M4 p+ U/ L8 z9 h* oCentOS7更换镜像源
0 S$ z! P* {" Z3 f3 b8 p1、先安装wget, \1 }9 R3 [+ k& x+ i# [5 [+ B

' r' d! O2 }/ v) @8 `yum install -y wget- R7 A3 O3 l( N4 l& |8 j  H6 C* I
5 X1 `( H# ]9 g, P+ h# s& D" i; E
0 M* C0 Q: y  U2 p' K
; {- ?( F. B3 B( p
2、打开阿里镜像http://mirrors.aliyun.com/
3 L, W; G5 w7 A2 @6 N0 K7 m* j8 }1 v9 V" W( e7 i1 X
点击,帮助,查看详情:
, l, w( i) _7 s- S2 f7 i: X' C9 h% x) ?$ a" T6 z1 Y
0 s+ ?% A; C: s- Z
! a7 l; Z( p! {' [& T* L! S
3、下载CentOS 7的对应的repo文件
, F4 e" e9 J4 Q- H) t
# l* L/ P) G( S8 J9 W. ~wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo8 p3 n0 d4 }0 ?5 m- O
2 w( |' _$ G2 U; s4 t8 \
#或者
% e4 X2 W' {' a5 h7 n8 H+ C
) r! o+ ^# n3 R/ acurl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo8 o: }, L+ X, h  C5 N

; [& Q4 d, w* i4 f- J$ X$ n) o, h( u1 K/ ]0 }
+ q( p5 t8 M0 r" B' ]0 l# g
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 01:57 , Processed in 0.016043 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表