centos7 yum fastestmirror不能使用

本文介绍了解决在CentOS系统上安装lrzsz软件包时遇到的问题,包括禁用fastestmirror插件、配置resolv.conf文件等步骤,并提供详细的命令行操作指南。

[root@localhost ~]# yum install lrzsz
Loaded plugins: fastestmirror
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; Unknown error"

===============================================================================

第一步:

[root@localhost ~]# vi  /etc/yum/pluginconf.d/fastestmirror.conf 
[main]
enabled=1//把1改为0  
verbose=0
always_print_best_host = true
socket_timeout=3
#  Relative paths are relative to the cachedir (and so works for users as well
# as root).
hostfilepath=timedhosts.txt
maxhostfileage=10
maxthreads=15
#exclude=.gov, facebook
#include_only=.nl,.de,.uk,.ie

===============================================================================

第二步:

[root@localhost ~]# vi /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1//将plugins的值修改为0
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

===============================================================================

继续运行,出现如下错误

[root@localhost ~]# yum install lrzsz
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; 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

===============================================================================

原因:没有配置resolv.conf
解决方法:
到/etc目录下配置resolv.conf加入nameserver IP,如:
[root@localhost ~]# vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
search localdomain
保存再次运行命令就可以



### 解决方法 在 CentOS 7 中,如果遇到 `yum` 命令执行失败的问题,可以尝试以下几种解决方法: 1. **清理缓存并重建**: - 清理现有的 YUM 缓存文件,这有助于解决由于缓存损坏导致的问题。 ```bash sudo yum clean all ``` - 重新创建元数据缓存,以确保 YUM 可以正确访问仓库信息。 ```bash sudo yum makecache ``` 2. **检查网络连接**: - 确保系统能够正常访问互联网。可以通过 `ping` 命令测试网络连通性,例如: ```bash ping -c 4 google.com ``` - 如果网络不通,需要检查网络配置,特别是网卡设置是否正确。例如,确保 `/etc/sysconfig/network-scripts/ifcfg-<interface>` 文件中的 `ONBOOT=yes`,以便在启动时激活网络接口[^4]。 3. **重装 YUM 软件包**: - 如果 `yum` 命令本身出现问题,可能需要重新安装相关软件包。首先下载所需的 RPM 包,然后使用 `rpm` 命令进行安装。例如: ```bash rpm -ivh yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm yum-3.4.3-163.el7.centos.noarch.rpm ``` 4. **检查仓库配置**: - 进入 `/etc/yum.repos.d/` 目录,检查仓库配置文件是否存在错误。可以尝试备份当前的仓库文件,并从官方或其他可信源获取新的仓库文件。 ```bash cd /etc/yum.repos.d/ ls -a ``` 5. **更新系统**: - 有时,系统上的某些组件可能已过时,导致与 YUM 不兼容。尝试运行系统更新来解决此类问题。 ```bash sudo yum -y update ``` 6. **检查 SELinux 和防火墙设置**: - SELinux 或防火墙规则可能会阻止 YUM 访问外部资源。临时禁用这些安全措施,看是否能解决问题。 ```bash sudo setenforce 0 # 临时关闭 SELinux sudo systemctl stop firewalld # 停止防火墙服务 ``` 7. **查看日志文件**: - 如果以上方法都无法解决问题,建议查看系统日志文件,如 `/var/log/yum.log` 和 `/var/log/messages`,以获取更多详细的错误信息。 ```bash tail -n 100 /var/log/yum.log tail -n 100 /var/log/messages ``` 通过上述步骤,通常可以解决大多数 `yum` 命令无法使用的情况。如果问题仍然存在,可能需要进一步检查系统环境或联系技术支持寻求帮助。
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值