サポートが終了したCentOS6でyumでパッケージを更新する

サポートが終了したCentOS6でyumでパッケージを更新する

サポートが終了したCentOS6でyumでパッケージを更新する

サポートが終了したCentOS6でyumでパッケージを更新する
最終更新日:2021.01.26

CentOS6のサポートが終了しyumが動かなくなってしまいました。
古いboxですが、更新作業があるので使わないことには…必要…困った。

エラー内容

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

yum install -y centos-release

Stdout from the command:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt

Stderr from the command:

Error: Cannot find a valid baseurl for repo: base

解決方法

CentOS-Base.repo内のURLを書き換えて簡易的に動かしてあげます。

vagrant sshで中に入ります。

ターミナル

コピー

vagrant ssh

管理権限でCentOS-Base.repoを編集モードで開きます。

sudoを付けずに開くとRead Onlyで開けません。

ターミナル

コピー

sudo vi /etc/yum.repos.d/CentOS-Base.repo

書き込む時は【i】閉じる時は【esc】、上書きする時は閉じたあと【:wq】でOKです。
開いたファイルのURLを『http://mirrorlist.centos.org/』→『http://vault.centos.org/』書き換えてあげます。
またmirror部分をコメントアウトしてあげます!

一括置換のほうがミスも無く楽なので以下の方法で置換をします。

『mirrorlist』→『#mirrorlist』に変更

ターミナル

コピー

sudo sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\/mirrorlist.centos.org/g" /etc/yum.repos.d/CentOS-Base.repo

『#baseurl』→『baseurl』に変更し
『http://mirrorlist.centos.org/』→『http://vault.centos.org/』に変更

ターミナル

コピー

sudo sed -i -e "s/^#baseurl=http:\/\/mirror.centos.org/baseurl=http:\/\/vault.centos.org/g" /etc/yum.repos.d/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&infra=$infra
baseurl=http://vault.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&infra=$infra
baseurl=http://vault.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=http://vault.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=http://vault.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib – packages by Centos Users
[contrib]
name=CentOS-$releasever – Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
baseurl=http://vault.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

編集完了後vagrant reloadすると…動きました!良かった。