본문 바로가기
Operating System/Linux

[CentOS] yum install 시 "Could not retrieve mirrorlist http://mirrorlist.centos.org" 해결방법

by 근육곰돌이 2022. 5. 4.
728x90

 

CentOS에서 yum으로 특정 패키지 설치 시 아래와같이 문제를 ㄱr끔 만나실수 있습니다.

필자는 잘쓰던 yum을 "yum update" 후 install이 갑자기 되지않은 경우 였습니다.

 


증상

# yum install openssh

<< 명령 입력 시 아래와 같은 오류가 발생하였습니다.
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org"


 One of the configured repositories failed (Unknown),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

 


원인

모든 증상을 증상 그대로에서 분석하며, 살며시 살펴보면 늘 답이 있는거 같습니다.

위의 에러로그를 보면 분석해보면
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve hostmirrorlist.centos.org"

yum은 yum 레포지토리에서 RPM패키지 정보들을 불러오는데, 이때 mirrorlist.centos.org 도메인을 resolve 할수 없다는 말이다.

이는 곧
1. Could not resolve host : 서버가 호스트 도메인의 IP를 찾지 못하거나, 
2. mirrorlist.centos.org: 찾은 호스트 도메인 (레포지터리)가 문제가 있거나,
둘 중 하나의 문제일 것이다.

 


 

조치 : /etc/resolv.conf 수정

필자는 위의 원인분석 과정 중 먼저 원인 1 을 먼저 의심하기로 하였습니다.
그 이유는 미러리스트 공식 홈페이지는 문제가 없을것이라는 판단을 먼저 하였습니다.

원인1의 경우 서버가 호스팅을 못찾을때는 도메인 서버 주소가 없을 확률이 가장 높다. (그거 아니라면 인터넷 연결이 안되는 서버일 것이다.)

CentOS에서 도메인서버 주소 설정하는 경로는 "/etc/resolv.conf"입니다. 여기에 네임서버가 넣어주자.

 # vi /etc/resolv.conf

    증상의 원인 (수정전)                         수정 후
nameserver NotIpSetting        ---->        nameserver 8.8.8.8

 

이후 yum이 정상적으로 동작한다.

 

 

간단해보이지만 해결과정의 의식흐름을 좀 더 알려드리고 싶어, 포스팅을 길~~게 늘려서 써보았습니다.
모두들 스트레스 받지 마시고, 오늘도 화이팅입니다.

 

반응형