centos yum 无法安装任何东西或更新系统

centos yum fails installing anything or updating system

我试图在 CentOS 上安装一个软件包,但是当我 运行 "yum" 命令时它抛出错误。互联网连接工作正常。 我尝试 yum clean all 但问题仍然存在。

错误:

[root@dcos-master3 ~]# yum install ntp

Loaded plugins: fastestmirror


     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/$releasever/x86_64

我的 yum repolist 是下一个:

[root@dcos-master3 ~]# yum repolist list
Loaded plugins: fastestmirror
https://yum.dockerproject.org/repo/main/centos/%24releasever/repodata/repomd.xml: [Errno 14] HTTPS Error 403 - Forbidden
Trying other mirror.
To address this issue please refer to the below knowledge base article

https://access.redhat.com/solutions/69319

If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/

repolist: 0

如果我列出 repolist:

[root@dcos-master3 ~]# yum repolist
Loaded plugins: fastestmirror
https://yum.dockerproject.org/repo/main/centos/%24releasever/repodata/repomd.xml: [Errno 14] HTTPS Error 403 - Forbidden
Trying other mirror.
To address this issue please refer to the below knowledge base article

https://access.redhat.com/solutions/69319

If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/

repo id                             repo name                             status
base/$releasever/x86_64             CentOS-$releasever - Base             0
dockerrepo/$releasever              Docker Repository                     0
extras/$releasever/x86_64           CentOS-$releasever - Extras           0
updates/$releasever/x86_64          CentOS-$releasever - Updates          0
repolist: 0

在尝试任何这些之前,请备份您的机器,您可能会损坏您的 OS MORE/COMPLETELY

您的 yum 变量 $releasever 似乎已损坏, 它通常是由于某些不明原因在机器上缺少 centos-release 包造成的。

您可以通过以下方式检查您是否有包裹:

    rpm -qi centos-release

您可能会看到:

    "package centos-release is not installed"

首先通过以 root 身份执行来找出您拥有的确切 centos 版本:

    cat /etc/redhat-release

你会看到这样的东西:

    CentOS Linux release 7.3.1611 (Core)

您可以通过以下方式从回购中获取 centos-release 包:

    wget http://vault.centos.org/centos/7.3.1611/updates/x86_64/Packages/centos-release-7-3.1611.el7.centos.2.5.x86_64.rpm

现在 运行 通过 rpm 重新安装 centos-release 软件包:

    sudo rpm -Uvh --replacepkgs centos-release-7-3.1611.el7.centos.2.5.x86_64.rpm

接下来你可以尝试用 yum 安装一些东西,你可能会得到:

    [root@dcos-master3 ikerlan]# sudo yum install wget
    error: db5 error(-30969) from dbenv->open: BDB0091 DB_VERSION_MISMATCH: Database environment version mismatch
    error: cannot open Packages index using db5 - (-30969)
    error: cannot open Packages database in /var/lib/rpm
    CRITICAL:yum.main:

    Error: rpmdb open failed

现在您可以尝试重启机器或尝试使用以下命令重建 rpm 数据库:

    rpm --rebuilddb

我 运行 在尝试在 CentOS 7 上安装 MariaDB 时遇到了这个问题。我非常沮丧,经过大量搜索后在这个 link 找到了答案。

这是为我解决这个问题的方法。 运行 作为根用户。

# yum --disablerepo "*" --enablerepo epel install [package]
# yum clean all

"epel" 可以是你喜欢的任何 repo,但这个对我有用。按照编写的方式将 [package] 放在命令中,而不是您要安装的包。

在您 运行 上面的操作之后,退出 root 并 运行 无论您在遇到错误之前尝试安装什么。

我注意到在失败的 url 中,您的 $releasever%24releasever,但它应该是 77.14.xx。请检查位于 /etc/yum/var 的 yum 配置文件,或在每个 .repo 文件中搜索,以查看其值。它可能已损坏。

有关如何设置这些变量的详细信息,请参阅 Red Hat 文档。

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/sec-using_yum_variables

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum -y install yum-utils
yum-config-manager --enable remi-php74

然后继续您的 installation/updates/etc

我在centos 7中下载一些包时遇到了同样的问题。经过几天的搜索,我找到了解决方案:

  1. 进入 yum repo 目录。

     cd /etc/yum.repos.d.
    
  2. 复制 CentOS-Base.repo 文件。

     cp CentOS-Base.repo CentOS-Base.repo.old
    
  3. 编辑CentOS-Base.repo文件。注释 mirrorlist 并取消注释 baseurl。

     vi CentOS-Base.repo
    
    [base]
    name=CentOS-$releasever - Base
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
    baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  1. 现在使用 yum 时,请执行以下操作。

     sudo yum --disablerepo=* --enablerepo=base install httpd
    

同样适用于 yum 更新。

  sudo yum --disablerepo=* --enablerepo=base install httpd

现在应该可以了。

始终确保 NAT 在您的 centos7 上处于活动状态。特别是当主机有 VMnet2 时。因为有时 VMNet2 可以代替 NAT 处于活动状态,因此您将无法通过 centos7 连接到互联网。这只是出现该错误的一个原因。