一、查看是否能连接到外网
我们通过ping命令,来查看是否与外网连同

OK,啊,连同外网没问题
- 如果无法解析域名,可能是 DNS 配置问题。
- 如果无法访问 IP 地址,可能是 防火墙或网络代理问题。
解决方法:
- 临时更换 DNS(例如使用 DnsPod DNS):
echo "nameserver 119.29.29.29" > /etc/resolv.conf
- 或者永久修改 DNS 配置(编辑
/etc/resolv.conf
)
二、修改 YUM 镜像源为国内镜像
由于 CentOS 官方镜像源可能访问不稳定,建议更换为国内镜像(如阿里云、清华源)。
步骤:
- 备份原始配置文件:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
- 下载阿里云镜像配置(以 CentOS 7 为例):
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
出现 -bash: wget: 未找到命令 的错误
,说明当前系统中 未安装 wget
工具。以下是解决方法:
使用 curl
替代 wget
因为软件源有问题导致无法安装 wget
,可以直接使用 curl
下载文件(无需安装额外工具):
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3. 验证文件是否下载成功
下载完成后,检查文件内容:cat /etc/yum.repos.d/CentOS-Base.repo
确保内容包含阿里云镜像地址


4. 清理并重建 YUM 缓存
5. 执行更新
最后运行:sudo yum update

暂无评论