79
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CentOS 7/8でyum/dnfに失敗! Failed to download metadata for repo 'AppStream'

79
Last updated at Posted at 2022-02-17

2026年11月追記
本記事の対処法(リポジトリをvault.centos.orgに向ける)は現在も有効で、CentOS 7とCentOS Stream 8でも同じ手順が使える。ただし、いずれもサポート終了済みでセキュリティ修正は提供されない。vaultへの切り替えは「移行作業のために一時的にパッケージを入れる」ための応急処置と考え、「6. 移行先について(追記)」の方法で早めに移行してほしい。

  • CentOS 8:2021年12月31日EOL
  • CentOS Stream 8:2024年5月31日EOL
  • CentOS 7:2024年6月30日EOL。あわせてmirrorlist.centos.orgが2024年7月に停止したため、CentOS 7では Could not resolve host: mirrorlist.centos.org のようなエラーになる

1. 突然のdnf/yumエラー

昨年(2021年)に構築したCentOS 8でyum/dnfを実行しようとしたところ、次のエラーが発生した。

# dnf install nc
CentOS-8 - AppStream                            105  B/s |  38  B     00:00
Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal
 mirrorlist: No URLs in mirrorlist

あれ、yum/dnfが効かない!

CentOS 8が2021年末にサポート切れになったのは記憶も新しい。筆者もCentOS 8ネタを何本か書いていたにもかかわらず、パッケージのインストールに失敗して焦ってしまった。この対処法を説明したい。

1-1. 対象環境

  • CentOS 8
  • CentOS 7、CentOS Stream 8(2026年追記。同じ対処が使える。「5. CentOS 7 / CentOS Stream 8の場合」を参照)

2. 原因は何か?

このようなエラーが発生した原因は、サポート切れでミラーサイトが停止したからだ。エラーメッセージにも「No URLs in mirrorlist」と表示されている。つまり 「CentOS 8のサポート停止」 は次の2つのことを意味している。

  • 今後新しいアップデートパッケージを提供しない
  • ミラーサイトが停止する

3. 暫定対処に失敗

それならCentOS Streamリポジトリからwgetしちゃえと思ったら、wgetが入っていない。うーむ。

$ wget http://hogehoge
bash: wget: command not found...

残された選択肢は、次の2つ。

  1. wgetなど最低限必要なパッケージを他サーバからscpで送り込み、以降はwgetで取得する
  2. CentOS Streamに移行するか、AlmaLinuxやRocky Linux、Oracle LinuxなどのRHELクローンに移行する

1の方法は力技。自力で依存性を解決しなければならず、パッケージ数が多くなるとしんどい。

趣味で使っている環境だったこともあり、

いっそのことCentOS Streamに移行してしまおう

と、公開されている次の移行手順を実行すると、これまたエラーで実行できず。

CentOS-Streamへの移行手順
# dnf install centos-release-stream
# dnf swap centos-linux-repos centos-stream-repos
# dnf distro-sync

リポジトリにアクセスできないので、この手順通りでは無理なことはわかるだろう。だけれどcentos-release-streamパッケージをwgetして、ローカルインストールすればいいと思っていたら、依存関係でcentos-release-streamをインストールできず。クー。

2026年11月追記
CentOS Stream 8も2024年5月にEOLとなったため、現在はCentOS 8からCentOS Stream 8に移行する意味はない。CentOS Stream 9/10へのインプレース移行もサポートされていないので、CentOS Streamを使うなら新規インストールになる。

4. 根本解決策は?

解決策は、参照先のリポジトリをミラーサイトからhttp://vault.centos.orgに変更すること。つまり/etc/yum.repos.d/CentOS*repoファイルの以下のように変更する。

一か所目
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
↓ コメントアウト
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
二か所目
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
↓ baseurlのコメントを外して、mirrorをvaultに置換
baseurl=http://vault.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/

修正後のファイル全体の内容は次のとおり。

修正後:/etc/yum.repos.d/CentOS-Base.repo
[BaseOS]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
baseurl=http://vault.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
修正後:/etc/yum.repos.d/CentOS-AppStream.repo
[AppStream]
name=CentOS-$releasever - AppStream
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
baseurl=http://vault.centos.org/$contentdir/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

手で修正するのが面倒な人は、次のコマンドで一括置換できる。

sed -i -e 's/^mirrorlist/#mirrorlist/g' -e 's/^#baseurl=http:\/\/mirror/baseurl=http:\/\/vault/g' /etc/yum.repos.d/CentOS-*repo

まあ「根本解決か」と聞かれると微妙で、根本解決はAlmaLinuxやRocky Linux、CentOS Stream、Oracle Linuxなどに移行することなのだけれど...。今回は、CentOS 8のサポート切れは痛いほどわかっていたのに戸惑ったという話でした。

2026年11月追記
http:// のままでも動くが、vault.centos.orgはHTTPSに対応しているので、sedの置換先を https:\/\/vault にしてもよい。また、vaultは単一サイトでミラーがないため、dnf makecache に時間がかかることがある。

5. CentOS 7 / CentOS Stream 8の場合(2026年追記)

CentOS 7とCentOS Stream 8も、EOLとmirrorlist.centos.orgの停止によって同じ状況になっている。vault.centos.orgには centos/7/、centos/8-stream/ のディレクトリが残っているので、対処法は同じだ。

CentOS 7
repoファイルは/etc/yum.repos.d/CentOS-Base.repoで、$releaseverは7になる。CentOS 8と同じsedで置換できる。

sed -i -e 's/^mirrorlist/#mirrorlist/g' -e 's/^#baseurl=http:\/\/mirror/baseurl=http:\/\/vault/g' /etc/yum.repos.d/CentOS-*.repo

置換後の[base]セクションは次のようになる。

/etc/yum.repos.d/CentOS-Base.repo(CentOS 7)
[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-7

CentOS Stream 8
repoファイルは/etc/yum.repos.d/CentOS-Stream-*.repoで、パスに$stream(=8-stream)が使われている。こちらも同じsedで置換できる。

/etc/yum.repos.d/CentOS-Stream-BaseOS.repo(置換後)
[baseos]
name=CentOS Stream $releasever - BaseOS
#mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo=BaseOS&infra=$infra
baseurl=http://vault.centos.org/$contentdir/$stream/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

※ EPELも併用している場合は、EPEL 7がアーカイブに移動しているので/etc/yum.repos.d/epel.repoの修正も必要になる。手順は「あらためてEPELリポジトリの使い方をまとめてみた」の5-3を参照。

6. 移行先について(2026年追記)

執筆時に「根本解決は移行」と書いたとおりだが、その後、移行ツールが出そろった。vaultに向けてパッケージを入れられる状態にしたら、次のいずれかで移行するのがよい。いずれもインターネット接続が前提で、実行前にバックアップは必須だ。

移行元 移行先 ツール
CentOS 8 / Stream 8 AlmaLinux 8 almalinux-deploy(-fオプションでvault切替も自動)
CentOS 8 / Stream 8 Rocky Linux 8 migrate2rocky
CentOS 7 / 8 Oracle Linux 7 / 8 centos2ol
CentOS 7 / 8 RHEL 7 / 8 convert2rhel(Developer Subscriptionでも可)
CentOS 7 AlmaLinux/Rocky/OL/RHEL 8以降 ELevate(メジャーバージョンを跨ぐ移行)

関連記事

79
32
2

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
79
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?