La foret rouge

EOL 된 CentOS의 yum repo 미러 변경하기

Published on
Published on
Authors
  • avatar
    Name
    신주용

CentOS와 같은 운영체제도 버전이 있고 오래된 버전은 EOL(End of Life, 서비스 종료)이 됩니다. 하지만 현실적으로 운영 중인 모든 시스템을 최신 버전으로 즉시 업그레이드 하는 것은 쉽지 않습니다. 그래서 OS가 EOL이 되더라도 당분간은 계속 사용하는 경우가 많습니다. 그런데 이런 시스템에서는 패키지 관리자인 yum도 사용할 수 없는 경우가 생깁니다. OS가 EOL이 되면서 공식 repository도 서비스를 종료하기 때문입니다. (심지어 CentOS 7.0 버전은 기본 Python 버전이 2.7인데 yum으로 python3 설치를 할 수가 없다는 말입니다..!!)

> yum update
Loaded plugins: fastestmirror
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again

그러면 EOL 된 버전의 운영체제를 사용할 때는 더이상 아무것도 설치하지 못하는 것일까요? 아닙니다. 공식 repository는 아니지만 아직 서비스를 하고 있는 다른 repository로 변경하면 됩니다. 흔히들 '미러(Mirror)'라고 하는 것입니다. 이번 글에서는 CentOS의 패키지 관리자인 yum이 공식 repo가 아닌 다른 mirror repo에서 패키지 정보를 받아오도록 설정을 변경해봅니다.

참고로 이 내용은 CentOS 뿐만 아니라 yum 패키지 매니저를 사용하는 Red Hat family의 모든 OS에서 활용 가능합니다. apt를 사용하는 Debian 계열도 유사한 방법을 사용하고 있습니다.

현재 repo 주소 확인

먼저 지금은 어떻게 설정되어 있는지 확인해봅시다. 테스트에는 CentOS 6.4 버전을 사용했습니다.

yum 패키지 관리자는 repo 정보를 /etc/yum.repos.d 디렉터리에 둡니다. 해당 디렉터리로 이동해보면 몇 개 파일이 있습니다.

> cd /etc/yum.repos.d
> ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-Vault.repo

그 중 CentOS-Base.repo라는 파일에는 어떤 내용이 있는지 한 번 확인해봅시다.

> cat CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

... 

아까 글 처음에 나왔던 로그를 보면 14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'" 이런 내용이 있었습니다. 못 찾는다는 mirrorlist.centos.org 주소가 이 설정 파일에 있었네요. 이 사이트 자체가 사라져버려 더이상 여기서 패키지를 가져올 수 없는 것이 원인이었습니다.

미러 url 변경

그러면 아직 CentOS에서 사용 가능한 패키지를 제공하는 다른 미러 사이트의 주소를 넣으면 되지 않을까요? kernel.org에서 제공하는 아카이브 사이트 주소 https://archive.kernel.org/centos-vault/를 사용해서 패키지 정보를 받아오도록 만들어봅시다.

혹시 모를 상황에 대비해 기존 파일을 백업하는 것부터 시작합니다.

> cp CentOS-Base.repo CentOS-Base.repo.bak.20250214

이제부터 해야될 작업은 (1) mirrorlist 대신 baseurl을 사용하도록 변경하고 (2) baseurl의 주소를 mirror.centos.org가 아니라 archive.kernel.org로 변경하는 것입니다. 그런데 수십 줄 짜리 파일에서 일일이 찾아가며 값을 바꾸기는 너무 귀찮죠. sed 명령어로 텍스트 대치를 손쉽게 할 수 있습니다.

# mirrorlist 주석처리
> sed -i "s/^mirrorlist/#mirrorlist/g" CentOS-Base.repo

# baseurl 주석 해제
> sed -i "s/^#baseurl/baseurl/g" CentOS-Base.repo

이제 사이트 url을 바꿀 단계인데, 버전에 따라 url을 다르게 사용해야 합니다. 저는 테스트 환경을 CentOS 6.4 버전을 사용해서 archive.kernel.org/centos-vault/6.4를 사용하려고 합니다. 지금 사용 중인 OS의 버전을 알고 싶다면 /etc/os-release(대부분의 리눅스 배포판에 있음) 또는 /etc/redhat-release(rhel 계열에만 있음)을 확인해봅니다. 다음은 CentOS 7.0 버전 예시입니다.

> cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

> cat /etc/redhat-release 
CentOS Linux release 7.0.1406 (Core) 

이제 mirror.centos.org/centos/$releasever라는 값을 archive.kernel.org/centos-vault/6.4와 같이 변경해야 하는데 여기에는 / 기호가 들어가기 때문에 sed를 실행할 때 위에서 했던 방법처럼 값을 넣으면 에러가 납니다. 그래서 sed의 구분자를 /가 아니라 다른 문자로 바꿔줘야 합니다. $ 기호도 escape 처리해줍니다.

# url 변경
> sed -i "s#mirror.centos.org/centos/\$releasever#archive.kernel.org/centos-vault/6.4#g" CentOS-Base.repo

그리고 다시 파일을 확인해보면 우리가 원하는 대로 모든 url이 바뀌어 있습니다.

> cat CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://archive.kernel.org/centos-vault/6.4/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://archive.kernel.org/centos-vault/6.4/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

...

이제 패키지 업데이트가 가능한지 확인해볼까요?

> yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up Everything

> yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
base                                                                 | 3.7 kB     00:00     
base/primary_db                                                      | 4.4 MB     00:04     
extras                                                               | 2.9 kB     00:00     
extras/primary_db                                                    |  18 kB     00:00     
updates                                                              | 2.9 kB     00:00     
updates/primary_db                                                   | 5.1 MB     00:01     
repo id                              repo name                                        status
base                                 CentOS-6 - Base                                  6,381
extras                               CentOS-6 - Extras                                   13
updates                              CentOS-6 - Updates                               1,555
repolist: 7,949

이제는 이렇게 정보를 가져올 수 있게 되었습니다. 그러면 이 글 처음에 시도했던 update 명령어도 확인해볼까요?

> yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package bash.x86_64 0:4.1.2-14.el6 will be updated
---> Package bash.x86_64 0:4.1.2-15.el6_4 will be an update
---> Package chkconfig.x86_64 0:1.3.49.3-2.el6 will be updated
---> Package chkconfig.x86_64 0:1.3.49.3-2.el6_4.1 will be an update
---> Package coreutils.x86_64 0:8.4-19.el6 will be updated
---> Package coreutils.x86_64 0:8.4-19.el6_4.2 will be an update
...
---> Package xfsprogs.x86_64 0:3.1.1-10.el6 will be updated
---> Package xfsprogs.x86_64 0:3.1.1-10.el6_4.1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================
 Package                          Arch       Version                      Repository   Size
============================================================================================
Installing:
 kernel                           x86_64     2.6.32-358.23.2.el6          updates      26 M
Updating:
 bash                             x86_64     4.1.2-15.el6_4               updates     904 k
 chkconfig                        x86_64     1.3.49.3-2.el6_4.1           updates     159 k
...
 util-linux-ng                    x86_64     2.17.2-12.9.el6_4.3          updates     1.5 M
 xfsprogs                         x86_64     3.1.1-10.el6_4.1             updates     724 k

Transaction Summary
============================================================================================
Install       1 Package(s)
Upgrade      62 Package(s)

Total download size: 88 M
Is this ok [y/N]:

이렇게 잘 받아오는 것을 확인할 수 있습니다.

참고: 이 글에서 언급되었으나 깊게 설명하지 않은 내용입니다.

  • RHEL and its derivatives
  • Mirror (Mirror site, Mirror Server)