6
4

CentOS 7 のサポートが終了

CentOS 7のサポートが2024年6月30日でついに終了しちゃいました。
長年愛用されてきたOSですが、もうアップデートも受けられなくなっちゃうんですよね。
セキュリティ面でも心配になってくるので、そろそろ移行を考えないといけない時期かもしれません。

CI/CD で使っているイメージで yum install がコケるように・・・

サポート終了したのをうっかり忘れていて、ジョブを実行したら以下のようになりました。
Dockerイメージで adoptopenjdk/openjdk11:jdk-11.0.10_9-centos つかっていて、これがCentOS 7でした。

$ yum install -y wget
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container 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.centos.org に接続するように対応

vault.centos.org って聞いたことありますか?
これはCentOSの過去のパッケージを保管しているアーカイブサイトです。
サポートが終了したバージョンのパッケージもここに保存されているので、急にyumがエラーを吐いた時の救世主という感じですね。

ただし、ここにアクセスするには設定を少し変更する必要があります。
しかし、これさえ設定すれば、しばらくの間は古いCentOSでもパッケージのインストールが可能です。
ただ、あくまで一時的な対処なので、本格的な移行を検討することをおすすめします。

私は複数のジョブで同じような設定をしなければならないので、以下のようなシェルスクリプトを作りました。

#!/bin/bash

# リポジトリ設定のバックアップ
cp -ip /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

# リポジトリ設定の書き換え
cat <<EOL > /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-\$releasever - Base
baseurl=http://vault.centos.org/centos/\$releasever/os/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-\$releasever - Updates
baseurl=http://vault.centos.org/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-\$releasever - Extras
baseurl=http://vault.centos.org/centos/\$releasever/extras/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS-\$releasever - Plus
baseurl=http://vault.centos.org/centos/\$releasever/centosplus/\$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOL

# yumのキャッシュクリア
yum clean all

各ジョブでこのスクリプトを最初に実行することで無事yumが実行できるようになりました。

まとめ

vault.centos.org はあくまで一時的な対処であることを強調しておきます。
今後のシステム運用を安定させるためにも、計画的に新しいOS環境への移行を進めましょう。

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4