豫鹿图书馆刘老师 發表於 2024-12-20 11:52:00

Centos7, 使用yum工具,出现 Could not resolve host: mirrorlist.centos.org

<p>在 CentOS 7 中使用 yum 工具时,如果出现 "Could not resolve host: mirrorlist.centos.org" 的错误,通常是因为默认的镜像源无法访问。以下是一些常用的解决方法:</p>
<p><strong>检查网络连接</strong>:首先使用 <code class="inlineCode___uUrJ9">ping</code> 命令测试网络连接是否正常。如果 <code class="inlineCode___uUrJ9">ping mirrorlist.centos.org</code> 不通,但 <code class="inlineCode___uUrJ9">ping www.baidu.com</code> 正常,说明 DNS 解析没问题,基本确认是 yum 源的问题</p>
<p><strong>更换镜像源</strong>:可以切换到其他镜像源,如阿里云镜像源。以下是更换为阿里云镜像源的步骤</p>
<p>备份原有的 yum 配置文件</p>
<pre class="language-plaintext highlighter-hljs"><code>mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak</code></pre>
<p>下载新的阿里云 yum 配置文件</p>
<pre class="language-plaintext highlighter-hljs"><code>curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo</code></pre>
<p>清除缓存并生成新的缓存</p>
<pre class="language-plaintext highlighter-hljs"><code>yum clean all
yum makecache</code></pre>
<p>更新系统</p>
<pre class="language-plaintext highlighter-hljs"><code>yum -y update</code></pre>
<p>这样操作后,yum 应该能够正常使用新的镜像源进行软件包的下载和更新</p>
<p><strong>禁用 FastestMirror 插件</strong>:如果更换源后仍然出现问题,可以尝试禁用 FastestMirror 插件:编辑&nbsp;<code class="inlineCode___uUrJ9">/etc/yum/pluginconf.d/fastestmirror.conf</code>&nbsp;文件,将&nbsp;<code class="inlineCode___uUrJ9">enabled=1</code>&nbsp;改为&nbsp;<code class="inlineCode___uUrJ9">enabled=0</code></p>
<p><strong>进行yum源的测试,尝试安装nginx。安装时候如果出现下面的错误:</strong></p>
<pre class="language-plaintext highlighter-hljs"><code># yum -y install nginx
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
没有可用软件包 nginx。
错误:无须任何处理</code></pre>
<p>解决这个问题的步骤如下</p>
<p><strong>检查仓库配置</strong>: 检查 <code class="inlineCode___uUrJ9">/etc/yum.repos.d/</code> 目录下的 <code class="inlineCode___uUrJ9">.repo</code> 文件,确保至少有一个仓库是启用的,并且包含 nginx</p>
<p><strong>启用 EPEL 仓库</strong>: EPEL(Extra Packages for Enterprise Linux)是一个由 Fedora 社区打造,为 RHEL 及其衍生版如 CentOS 提供高质量软件包的项目。Nginx 通常包含在 EPEL 仓库中</p>
<pre class="language-plaintext highlighter-hljs"><code>sudo yum install epel-release -y</code></pre>
<p><strong>清理缓存</strong>: 清理 yum 缓存,确保 yum 重新生成缓存</p>
<pre class="language-plaintext highlighter-hljs"><code>sudo yum clean all</code></pre>
<p><strong>生成缓存</strong>: 生成新的 yum 缓存</p>
<pre class="language-plaintext highlighter-hljs"><code>sudo yum makecache fast</code></pre>
<p><strong>安装 Nginx</strong>: 再次尝试安装 nginx</p>
<pre class="language-plaintext highlighter-hljs"><code>sudo yum install nginx -y</code></pre>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/liuyangjava/p/18619017
頁: [1]
查看完整版本: Centos7, 使用yum工具,出现 Could not resolve host: mirrorlist.centos.org