centos_eol에_따른_레포지토리_변경_vault

CentOS EOL에 따른 레포지토리 변경(vault)

이강우 2025/02/07 04:56

CentOS 구버전 (6, 7, 8 등 Stream 이전버전) 은 EOL에 따라서 기존 패키지 레포지토리 저장소가 동작하지 않습니다.

[root@tipadb ~]# yum -y update
Loaded plugins: fastestmirror
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; Unknown error"


 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

Cannot find a valid baseurl for repo: base/7/x86_64

따라서 온라인 레포지토리를 이용하기 위해서는 vault레포지토리로 변경하여야 합니다.

아래 스크립트를 vault_repo_change.sh로 생성하여 실행합니다.

#!/bin/bash
####################
# 작성자 : koovis@gmail.com
# vault_repo_change.sh
# CentOS 6, 7, 8의 EOL로 인해 기존 레포지토리를 vault 레포지토리로 변경하기 위한 스크립트입니다.
# 기존의 mirrorlist 항목은 주석 처리하고, baseurl 항목이 주석 처리되어 있으면 주석 해제한 후 수정합니다.

# 1. CentOS 전체 버전 확인
if [ -f /etc/centos-release ]; then
    # CentOS 7, 8의 경우 "8.5.2111"과 같이 3자리 버전이 있는 패턴을 우선 추출
    FULL_VER=$(grep -oP '[0-9]+\.[0-9]+\.[0-9]+' /etc/centos-release)
    # 만약 추출되지 않으면 CentOS 6와 같이 2자리 버전을 사용
    if [ -z "$FULL_VER" ]; then
        FULL_VER=$(grep -oP '[0-9]+\.[0-9]+' /etc/centos-release)
    fi
else
    echo "/etc/centos-release 파일을 찾을 수 없습니다. 스크립트를 종료합니다."
    exit 1
fi

echo "Detected CentOS version: $FULL_VER"

# 2. 백업 디렉터리 생성 및 기존 레포지토리 파일 백업
BACKUP_DIR="/etc/yum.repos.d/backup_$(date +%F_%T)"
echo "백업 디렉터리: $BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
cp -a /etc/yum.repos.d/*.repo "$BACKUP_DIR"
echo "백업 완료."

# 3. 각 레포지토리 파일 수정
for repo in /etc/yum.repos.d/*.repo; do
    echo "Processing $repo ..."
    # 3-1. mirrorlist= 라인이 있으면 주석 처리
    sed -i 's/^\(mirrorlist=\)/#\1/' "$repo"

    # 3-2. baseurl 항목이 주석 처리되어 있을 경우 주석 해제 (# 및 뒤의 공백 제거)
    sed -i 's/^#\s*\(baseurl=\)/\1/' "$repo"

    # 3-3. baseurl 항목 내의 $releasever 변수를 실제 버전($FULL_VER)으로 변경
    sed -i "s/\\\$releasever/${FULL_VER}/g" "$repo"

    # 3-4. 기존 baseurl의 도메인 변경: mirror.centos.org/centos → vault.centos.org
    sed -i 's|mirror.centos.org/centos|vault.centos.org|g' "$repo"
done

echo "레포지토리 파일 변경 완료."

위 스크립트를 파일(예: vault_repo_change.sh)에 저장합니다.
실행 권한을 부여합니다.

chmod +x vault_repo_change.sh

스크립트를 root 권한(또는 sudo)으로 실행합니다.

sudo ./vault_repo_change.sh

이 스크립트를 사용하면 CentOS 6, 7은 물론 CentOS 8의 레포지토리 파일도 vault 레포지토리로 일괄 변경할 수 있습니다.

로그인하면 댓글을 남길 수 있습니다.
  • centos_eol에_따른_레포지토리_변경_vault.txt
  • 마지막으로 수정됨: 2025/02/07 04:59
  • 저자 admin