其实一般都是yum源的问题
因为CentOS 7 官方镜像源已停止维护,导致无法通过默认配置访问仓库。
解决方案
1. 检查网络与 DNS 配置
测试网络连通性
ping www.baidu.com若不通,检查网卡配置(如 ONBOOT=yes)并重启网络服务:
service network restart修正 DNS 配置:
编辑 /etc/resolv.conf,添加公共 DNS
nameserver 8.8.8.8 # Google DNS
nameserver 223.5.5.5 # 阿里云 DNS2. 更换阿里云镜像源备份原有配置
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup下载阿里云镜像源:
使用 curl 命令(无需依赖 wget):
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo清理旧缓存并生成新缓存:
yum clean all
yum makecache3. 验证镜像源并安装 wget安装测试
yum install -y wget4. 若仍失败(备选方案)手动下载 RPM 包安装
从阿里云镜像站下载 wget 的 RPM 包(需浏览器访问):
# 示例 URL(根据实际架构调整)
rpm -ivh http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm