找回密码
 注册
查看: 25|回复: 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 h4 k( ]2 G% B% U2 Z& X

7 X- Z- b* M1 c4 `/ ~: e. t0 \; x
[root@zabbix-server ~]# yum install devtoolset-11-gcc*7 U& x/ p8 n! v% A0 }  P6 Z
Loaded plugins: fastestmirror5 l$ y. E/ F2 K& t$ @7 j
Loading mirror speeds from cached hostfile
" o, @* i( W4 j3 K) zCould not retrieve mirrorlist http://mirrorlist.centos.org/?re ... =os&infra=stock error was
; f( L& ]1 S- _6 g7 c3 f14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"  ?2 c) r( J/ v1 H+ V% F. g
* A( B! `; f) a$ O0 Z
3 N. ^% G4 s3 y; [1 A
One of the configured repositories failed (Unknown),! L1 d( M" }* y# l2 N% S" j
and yum doesn't have enough cached data to continue. At this point the only8 _3 R' y0 L& v) E; t
safe thing yum can do is fail. There are a few ways to work "fix" this:; v9 j9 w" N: @& Q
  a6 ~) h& W; l5 N' h
     1. Contact the upstream for the repository and get them to fix the problem.+ r6 J) d& }7 H3 I7 P( u. U, \
- s( B" w: V' b; u
     2. Reconfigure the baseurl/etc. for the repository, to point to a working/ Y- q( w# i" G0 N- F3 t# c
        upstream. This is most often useful if you are using a newer
, F; f3 p/ j- J7 H; Q5 s( J& f1 T        distribution release than is supported by the repository (and the' u7 L3 |( G- L5 h; }( q
        packages for the previous distribution release still work).% B% q. A( U% f  V  x- ~

$ ?: B4 Y5 O2 z7 L9 I     3. Run the command with the repository temporarily disabled
( T# Z7 }$ @' z( ]            yum --disablerepo=<repoid> ...
5 _8 a1 u3 L- ^& ~: m- ?  ?2 q% O! X' A& S1 l& M$ y# [
     4. Disable the repository permanently, so yum won't use it by default. Yum/ ]5 C1 m# E' Z9 K5 r
        will then just ignore the repository until you permanently enable it
4 p% k  l7 z" z1 R" r  ]        again or use --enablerepo for temporary usage:
* J# w& U: {8 |' h. `9 j+ \
! g$ w5 L# c2 ^. V; _& J            yum-config-manager --disable <repoid>
& s# @3 ~4 i+ Y3 X0 h: R' m" d        or
- z- |, _- q" p            subscription-manager repos --disable=<repoid>- p% q3 g7 t4 o; Q
+ S/ K' i+ `( P# L3 P  A5 t
     5. Configure the failing repository to be skipped, if it is unavailable.% Q9 c+ u2 k  w3 L
        Note that yum will try to contact the repo. when it runs most commands,
! G  ?1 m' F6 }1 j" I        so will have to try and fail each time (and thus. yum will be be much' n3 e( y% F3 _9 G7 c0 [
        slower). If it is a very temporary problem though, this is often a nice# k" _# U0 u) _% ~
        compromise:8 W3 U: t: Z7 O% }4 O

" Q* R5 U7 ^8 [$ E% B& D6 S            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true( v7 u2 o3 D; R! S8 l

0 Y# ~( o  u. [8 V: |Cannot find a valid baseurl for repo: base/7/x86_64' H# S7 ]5 ]% Y3 t6 r% g$ q( o
6 ]! `! Y0 `- F) S: J* }9 w
6 M! @! {# m, V8 a" `2 d3 k' \
$ \+ z: U0 C, F7 h6 h4 ~7 w8 A
【解决办法】6 B7 V, d; K3 _0 v; G* E

. x# z% {, z" H+ u9 O3 K2 e) g% b* @! _- b) \

5 l# B- i8 E. K* @看到报错日志中加粗的字体,命令行ping mirrorlist.centos.org 不通。试着ping www.baidu.com是正常的,说明DNS解析没问题。基本确认是yum源的问题。
; v6 j) P5 A1 i( S: A( r- e) q2 w& V! Q5 v
: T# \: G" n" `! Q& p

: ^! D0 {  X9 ^. D1 f$ h4 l8 qCentOS7更换镜像源$ Z; v: s# l! v4 q4 `6 Q3 |
1、先安装wget/ A5 c: P1 P. h& c7 \+ J
) G( n6 V& @  p, L' e6 W
yum install -y wget7 u( ^' Q; y8 o; A
" \% ]+ D6 f/ \3 A) U

: m$ a" ?! z3 N3 |
5 s0 t  l, X5 {. Q. k& r: F3 \2、打开阿里镜像http://mirrors.aliyun.com/9 y7 s) y1 ^& r# h
; v) I, J+ e' i$ j7 W/ V
点击,帮助,查看详情:
! x  [" n: [# Z$ J6 J3 R$ P
7 P# j! {+ X3 E, v7 I6 c0 i
8 |; y3 V) J% o- D! G0 {9 J' M: M2 L$ B- k3 k5 e. I$ u6 w! u2 K9 x
3、下载CentOS 7的对应的repo文件
& f) E, P- d, f" J( P1 N$ ~* x( q7 G9 {( e4 X+ Q
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo+ T( }1 {5 H. r
1 B  B- c$ Q; W% p
#或者
: O5 A! ^: W& O( h* z# z8 \' u7 r" O0 A4 |$ w. S( D# I/ N4 `
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
( a. e$ Z/ q; H- N, S3 }0 P) i8 S: h/ Q* n
! ?* g8 _" U1 T- [$ R# [
* Q" |: ~0 Q, G" V3 ?0 P' ]! o+ [$ E# e
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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