centos7的yum命令无法使用解决方案

news/2024/7/8 4:25:03 标签: linux, 运维

文章目录

  • 问题
  • 排查流程
  • 解决方案
  • 总结


问题

今天新建了个centos7的虚拟机发现yum无法正常使用

在这里插入图片描述

已加载插件:fastestmirror Determining fastest mirrors 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;
未知的错误”

One of the configured repositories failed (未知), 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= …

  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
    or
    subscription-manager repos --disable=

  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=.skip_if_unavailable=true

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


排查流程

当出现这个问题后首先想到了网络问题

1.通过ip addr检查了一下网络接口发现没问题
2.resolv.conf中手动配置了一下DNS也无法解决
3.检查了一下虚拟机的网络设置也没问题
4.ip route检查路由表发现没问题
5.关了一下防火墙也无法解决问题

经过一系列网络的排查基本可以判断不是网络的问题,既然不是网络的问题那大概率就是yum源的问题于是我换了阿里和清华的镜像问题就解决了

解决方案

  1. 打开CentOS-Base.repo
sudo vi /etc/yum.repos.d/CentOS-Base.repo
  1. 将CentOS-Base.repo里的内容全部替换为:
# CentOS-Base.repo  
#  
# 这里配置了CentOS的yum源,使用了阿里云和清华大学的镜像点。  
#  
  
[base]  
name=CentOS-$releasever - Base  
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/  
        http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
  
#released updates   
[updates]  
name=CentOS-$releasever - Updates  
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/  
        http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
  
#additional packages that may be useful  
[extras]  
name=CentOS-$releasever - Extras  
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/  
        http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
  
#additional packages that extend functionality of existing packages  
[centosplus]  
name=CentOS-$releasever - Plus  
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/  
        http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/  
gpgcheck=1  
enabled=0  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
  
#contrib - packages by Centos Users  
[contrib]  
name=CentOS-$releasever - Contrib  
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/  
        http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/contrib/$basearch/  
gpgcheck=1  
enabled=0  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
  
# 使用failovermethod指定优先级,这里设置为随机(roundrobin),也可以改为priority并指定每个URL的优先级  
failovermethod=roundrobin
  1. 清理YUM缓存并更新
sudo yum clean all

sudo yum makecache

sudo yum update

总结

之前也遇到过这种情况大多是网络的问题所以一开始以为和往常一样,排查半天发现网络没问题才开始怀疑是yum源的问题,总结下来经验固然重要但也不要被经验束缚。


http://www.niftyadmin.cn/n/5537043.html

相关文章

7.1作业6

uart4.h #ifndef __UART4_H__ #define __UART4_H__ #include "stm32mp1xx_gpio.h" #include "stm32mp1xx_rcc.h" #include "stm32mp1xx_uart.h" //rcc/gpio/uart4初始化 void hal_uart4_init(); //发送一个字符 void hal_put_char(const char s…

[Go 微服务] Kratos 使用的简单总结

文章目录 1.Kratos 简介2.传输协议3.日志4.错误处理5.配置管理6.wire 1.Kratos 简介 Kratos并不绑定于特定的基础设施,不限定于某种注册中心,或数据库ORM等,所以您可以十分轻松地将任意库集成进项目里,与Kratos共同运作。 API -&…

ETCD 基本介绍与常见命令的使用

转载请标明出处:https://blog.csdn.net/donkor_/article/details/140171610 文章目录 一、基本介绍1.1 参考1.2 什么是ETCD1.3 ETCD的特点1.4 ETCD的主要功能1.5 ETCD的整体架构1.6 什么时候用ETCD,什么时候用redis 二、安装三、使用3.1 etcdctl3.2 常用…

k8s-第八节-Helm

Helm & 命名空间 介绍 Helm类似 npm,pip,docker hub, 可以理解为是一个软件库,可以方便快速的为我们的集群安装一些第三方软件。使用 Helm 我们可以非常方便的就搭建出来 MongoDB / MySQL 副本集群,YAML 文件别人都给我们写好了,直接使用。官网 https://helm.sh/zh/ …

Vue2中跨组件共享公共属性的方法、优缺点与实现

一、vuex(最常用) 优缺点 优点:集中管理状态,组件间解耦,易于调试和测试。缺点:学习成本较高,对于小项目可能过于复杂。 适用场景 大型、复杂的单页面应用(SPA)。需要全局…

【等保2.0是什么意思?等保2.0的基本要求有哪些? 】

一、等保2.0是什么意思? 等保2.0又称“网络安全等级保护2.0”体系,它是国家的一项基本国策和基本制度。在1.0版本的基础上,等级保护标准以主动防御为重点,由被动防守转向安全可信,动态感知,以及事前、事中…

《昇思25天学习打卡营第7天|函数式自动微分》

文章目录 今日所学:一、函数与计算图二、微分函数与梯度计算三、Stop Gradient四、Auxiliary data五、神经网络梯度计算总结 今日所学: 今天我学习了神经网络训练的核心原理,主要是反向传播算法。这个过程包括将模型预测值(logit…

【抽代复习笔记】25-群(十九):一个关于循环群的重要定理以及三道证明例题

定理:G (a)是n阶循环群,则: (1)|a^r| n/(r,n)((r,n)是r和n的最大公因数); (2)当(r,n) 1时,a^r也是一个生成元; (3&a…