如果ping baidu.com时可以连接并且onboot已经开启,dns也设置过。排除网络的问题,可能是仓库不可用的原因导致。可以sudo vi /etc/yum.repos.d/CentOS-Base.repo进入后输入i进行insert操作,删除里面的所有信息
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[centos-sclo-rh]
name=CentOS-$releasever - SCLo - RH
baseurl=http://mirrors.aliyun.com/centos/$releasever/sclo/x86_64/rh/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
把上述的代码复制到里面后esc退出insert情况在输入:wq回车,即可成功执行