bloglin99999头像
关注

centos的yum源

问题

centos7 中没有 zip 和 unzip 命令,下载报错如下 [root@hadoop01 opt]# yum install -y unzip 已加载插件:fastestmirror Loading mirror speeds from cached hostfile 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; 未知的错误 " One of the configured repositories failed (未知), 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

报错原因

Could not resolve host: mirrorlist.centos.org 两个核心问题:

  1. DNS 解析失败:服务器无法解析域名,连不上 centos 官方源
  2. CentOS7 官方源已经停止维护 (EOL),mirrorlist.centos.org已经失效,默认源不能用了

环境:CentOS7,yum 安装 unzip 失败

方案一:先改 DNS(解决域名解析)

echo "nameserver 8.8.8.8" >> /etc/resolv.conf
echo "nameserver 223.5.5.5" >> /etc/resolv.conf

临时生效,重启网卡会丢失;如果要永久需要改网卡配置 /etc/sysconfig/network-scripts/ifcfg-eth0

测试网络连通:

ping mirrorlist.centos.org
ping baidu.com
  • ping 不通 baidu:服务器本身不能上网,检查网关、网卡
  • ping 通 baidu,但 ping 不通 mirrorlist:源的问题,CentOS7 官方源下架,需要替换国内归档源

方案二:替换 CentOS7 国内归档 yum 源(重点)

CentOS7 官方源已经迁移到 vault.centos.org,国内很多镜像站也有归档。

1. 备份原有 repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2. 下载阿里云 CentOS7 vault 源

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

如果没有 curl,可以用 wget:

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

3. 清理 yum 缓存,重建缓存

yum clean all
yum makecache

4. 安装 unzip 和 zip

yum install -y unzip zip

如果 curl/wget 也不能用,服务器无法外网访问(离线方案)

服务器不能联网,上面方法无效,需要离线 rpm 包安装

  1. 在一台能上网的同版本 CentOS7 机器下载依赖包
yum install --downloadonly --downloaddir=/tmp/rpms unzip zip
  1. 把 /tmp/rpms 下所有 rpm 传到 hadoop01 服务器
  2. 本地安装
rpm -ivh *.rpm --nodeps

常见踩坑补充

  1. 虚拟机(hadoop 集群):检查网卡模式 NAT / 桥接,看是否能访问外网
  2. 防火墙不影响域名解析,可以临时关闭测试
systemctl stop firewalld
setenforce 0
  1. 如果 curl: command not found,只能手动新建 repo 文件
vi /etc/yum.repos.d/CentOS-Base.repo

粘贴阿里云 CentOS7 vault 内容:

[base]
name=CentOS-7 - Base - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-7 - Updates - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-7 - Extras - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7

保存后再执行 yum clean all && yum makecache

你可以先执行 ping baidu.com,把返回结果发我,我帮你判断是网络不通还是源的问题。

转载自 CSDN-专业IT技术社区

原文链接:https://blog.csdn.net/qq_33043025/article/details/166793791

文章来源转载

评论

赞0

评论列表

微信小程序
QQ小程序

关于作者

点赞数:0
关注数:0
粉丝:0
文章:0
关注标签:0
加入于:--