当前位置: 首页 > news >正文

CentOS服务器能ping通却无法yum install:指定镜像源解决

文章目录

  • 前言
  • 一、问题记录
  • 二、解决过程
    • 1.修改DNS无效
    • 2.指定镜像源
  • 总结


前言

今天有一个项目现场要在一个远程centos服务器上部署产品服务,发现能ping通百度,但是无法yum install 安装基础软件包,开始以为DNS服务器的问题,结果配置了也不行,最后通过指定镜像源的方式解决,解决过程记录下,方便后面遇到相同的问题快速解决。


一、问题记录

问题如下,能ping通百度,但是无法yum install :

[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (223.109.82.16) 56(84) bytes of data.
64 bytes from 223.109.82.16 (223.109.82.16): icmp_seq=1 ttl=52 time=13.6 ms
64 bytes from 223.109.82.16 (223.109.82.16): icmp_seq=2 ttl=52 time=13.6 ms
64 bytes from 223.109.82.16 (223.109.82.16): icmp_seq=3 ttl=52 time=13.0 ms
64 bytes from 223.109.82.16 (223.109.82.16): icmp_seq=4 ttl=52 time=15.5 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 13.046/13.991/15.574/0.956 ms
[root@localhost ~]# yum install net-tools -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
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=<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

二、解决过程

1.修改DNS无效

vi /etc/resolv.conf:
添加公共 DNS 服务器地址:
nameserver 8.8.8.8

[root@localhost ~]# vi /etc/resolv.conf 
[root@localhost ~]# ping mirrorlist.centos.org
ping: mirrorlist.centos.org: 未知的名称或服务
[root@localhost ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
#nameserver 192.168.1.1
nameserver 8.8.8.8
[root@localhost ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=53 time=46.0 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=53 time=46.2 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=53 time=45.9 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=53 time=46.1 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=53 time=48.9 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=53 time=46.1 ms
^C
--- 8.8.8.8 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5005ms
rtt min/avg/max/mdev = 45.925/46.569/48.998/1.125 ms
[root@localhost ~]# nslookup mirrorlist.centos.org 8.8.8.8
-bash: nslookup: 未找到命令
[root@localhost ~]# yum install bind-utils
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
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; 未知的错误"

可以看到在该环境下添加公共 DNS 服务器地址,虽然能ping通8.8.8.8,但是仍然解决不了在线yum install 安装工具的问题。

2.指定镜像源

由于无法解析 mirrorlist.centos.org,可以直接指定一个可用的镜像源。先备份原来的 CentOS-Base.repo 文件:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

接着从阿里云下载新的 CentOS-Base.repo 文件:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

此处如果简单的用wget 命令也会无法执行:

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
-bash: wget: 未找到命令
[root@localhost yum.repos.d]# yum install wget
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>
[root@localhost yum.repos.d]# ls

直接从windows机器上下载了一个Centos-7.repo,然后放到/etc/yum.repos.d/目录下
在这里插入图片描述

[root@localhost yum.repos.d]# ls -l
总用量 36
-rw-r--r--. 1 root root 2523 414 16:28 Centos-7.repo
-rw-r--r--. 1 root root 1664 1123 2018 CentOS-Base.repo.backup
-rw-r--r--. 1 root root 1309 1123 2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 1123 2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 1123 2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 1123 2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 1123 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 1123 2018 CentOS-Vault.repo

更新缓存:

yum clean all
yum makecache

再次尝试安装:

[root@localhost yum.repos.d]# yum install net-tools -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 net-tools.x86_64.0.2.0-0.25.20131004git.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

==============================================================================================================================================================================================================================================================================
 Package                                                         架构                                                         版本                                                                           源                                                          大小
==============================================================================================================================================================================================================================================================================
正在安装:
 net-tools                                                       x86_64                                                       2.0-0.25.20131004git.el7                                                       base                                                       306 k

事务概要
==============================================================================================================================================================================================================================================================================
安装  1 软件包

总下载量:306 k
安装大小:917 k
Downloading packages:
警告:/var/cache/yum/x86_64/7/base/packages/net-tools-2.0-0.25.20131004git.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY                                                                                               ]  0.0 B/s |    0 B  --:--:-- ETA 
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm 的公钥尚未安装
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm                                                                                                                                                                                                          | 306 kB  00:00:00     
从 http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 来自       : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                                                                                                                                                                 1/1 
  验证中      : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                                                                                                                                                                 1/1 

已安装:
  net-tools.x86_64 0:2.0-0.25.20131004git.el7                                                                                                                                                                                                                                 

完毕!

问题解决!


总结

这就是今天的一次问题解决,虽然是小问题,但是每次记录下,供下次出现问题时参考,能省不少时间,以前解决过很多的问题,当时觉得很清楚,觉得没什么好记录的,但时间长了又忘了,所以不管问题大小,及时总结记录是一个很好的习惯,集少成多。

相关文章:

  • 在思科模拟器show IP route 发现Gateway of last resort is not set没有设置最后的通道
  • One-Hot标签编码方法详解
  • 机器学习概述自用笔记(李宏毅)
  • mysql DQL
  • 「小推桌面官方下载」小推桌面TV版-安卓电视版官方免费下载新版
  • 【KWDB创作者计划】_KWDB部署与使用详细版本
  • 批量将多个文件夹转成压缩包,支持设置压缩密码
  • 【数据库系统概论】第3章 SQL(四)视图(超详细)
  • 5 C 程序全流程解析:编写、预处理、编译、汇编、链接、运行与 GCC 指令详解
  • 【C++ Qt】认识Qt、Qt 项目搭建流程(图文并茂、通俗易懂)
  • 【Spring】IoC详解:方法Bean的存储、Bean重命名、扫描路径@Component(下)
  • 计算机操作系统——存储器管理
  • Android 日志输出模块
  • 现在AI大模型能帮做数据分析吗?
  • ScholarCopilot:“学术副驾驶“
  • 【数据结构】励志大厂版·初阶(复习+刷题):复杂度
  • SpringBoot条件注解全解析:核心作用与使用场景详解
  • STM32 HAL库 ADC+TIM+DMA 3路 1S采样一次电压
  • C++对象池设计:从高频`new/delete`到性能飞跃的工业级解决方案
  • pycharm中调试功能讲解
  • 言短意长|政府食堂、停车场开放的示范效应
  • 从腰缠万贯到债台高筑、官司缠身:尼泊尔保皇新星即将陨落?
  • 【社论】优化限购限行,激发汽车消费潜能
  • 夜读丨庭院春韵
  • 多地征集农村假冒伪劣食品违法线索,全链条整治“三无”产品
  • 5145篇报道中的上海车展:40年,什么变了?