admin管理员组

文章数量:1618708

今天在Linux上面安装PostgreSQL的时候发生了 报错情况 failure: repodata/repomd.xml from xxxxxx: [Errno 256] No more mirrors to try.

#安装postgresql15-server
sudo yum install -y postgresql15-server

 看了一下报错分析貌似是yum源出现了问题,查了一些资料后进行尝试

1、方法一

既然是yum源有问题那么就尝试把yum源文件进行更新试

1.备份一下yum原来的“.repo”文件(CentOS-Base.repo)  一般“.repo”文件都会放在 /etc/yum.repos.d 目录下

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

2.然后下载一个阿里云的yum源 并命名CentOS-Base.repo   根据自己的centos版本去选择自己的yum源

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

3.清理缓存

yum clean all
yum makecache

问题一般解决了,但是上面那种方法还是没有解决我这边的问题,还是一样的报错。

认真看了一下 这个报错  “No more mirrors to try”大体意思就是没有更多的镜像文件可以尝试 然后下面一串url,还报了个“[Errno 14] HTTPS Error 404 - Not Found” 那就是路径错误  http://mirrors.aliyun/centos/7-7.1908.0.el7.centos/os/x86_64/repodata/repomd.xml这是我报错的路径 自己访问了一下 果然就是 404 ,去 http://mirrors.aliyun/centos 看了一下 并没有 7-7.1908.0.el7.centos 目录稍微看了一下,这个路径里的7-7.1908.0.el7.centos 有点怪怪的,那么 这个7-7.1908.0.el7.centos怎么来的呢?于是打开报错的“.repo”文件看一下,以我这边的 CentOS-Base.repo 为例

cat /etc/yum.repos.d/CentOS-Base.repo

 看了一下“.repo”文件的内部结构

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base - mirrors.aliyun
failovermethod=priority
baseurl=http://mirrors.aliyun/centos/7/os/$basearch/
        http://mirrors.aliyuncs/centos/7/os/$basearch/
        http://mirrors.cloud.aliyuncs/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun
failovermethod=priority
baseurl=http://mirrors.aliyun/centos/7/updates/$basearch/
        http://mirrors.aliyuncs/centos/7/updates/$basearch/
        http://mirrors.cloud.aliyuncs/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun
failovermethod=priority
baseurl=http://mirrors.aliyun/centos/7/extras/$basearch/
        http://mirrors.aliyuncs/centos/7/extras/$basearch/
        http://mirrors.cloud.aliyuncs/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun
failovermethod=priority
baseurl=http://mirrors.aliyun/centos/7/centosplus/$basearch/
        http://mirrors.aliyuncs/centos/7/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun
failovermethod=priority
baseurl=http://mirrors.aliyun/centos/7/contrib/$basearch/
        http://mirrors.aliyuncs/centos/7/contrib/$basearch/
        http://mirrors.cloud.aliyuncs/centos/7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7

 大概分析了一下 这些属性都是有什么用的

[base]  #方括号里面的是软件源的名称,将被yum取得并识别
name=CentOS-$releasever - Base - mirrors.aliyun   #仓库的名称 用于识别
failovermethod=priority   #这个属性有两种值可选roundrobin和priority  值为roundrobin会随机选择baseurl  值为priority 会根据顺序一个个来  如果不指定值的话 默认就是roundrobin
baseurl=http://mirrors.aliyun/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs/centos/$releasever/os/$basearch/
        #baseurl为yum源地址 包括HTTP(http://)、本地(file:///)、FTP(ftp://)
gpgcheck=1  #设置此yum源是否校验文件,1为校验,0为不校验
gpgkey=http://mirrors.aliyun/centos/RPM-GPG-KEY-CentOS-7  #若开启gpg校验,此为公钥文件地址
#enabled:1 设置此yum源是否可用,1为可用,0为不可用

可能就是 baseurl 这个参数的路径出现了问题  那路劲里面 没有7-7.1908.0.el7.centos 那是怎么来的呢  大概就是$releasever$basearch这个参数搞的

那就从这两个参数入手,结果发现 .repo文件中$releasever 值是先参考/etc/yum.conf中的distroverpkg的值

#使用 cat 查看yum.conf
$ cat /etc/yum.conf 
 
[main]
cachedir=/var/cache/yum     #yum下载的RPM包的缓存目录
keepcache=0                 #缓存是否保存,1保存,0不保存。
debuglevel=2                #调试级别(0-10),默认为2(具体调试级别的应用,我也不了解)。
logfile=/var/log/yum.log    #yum的日志文件所在的位置
exactarch=1                 #在更新的时候,是否允许更新不同版本的RPM包,
                            #比如是否在i386上更新i686的RPM包。
obsoletes=1                 #这是一个update的参数,具体请参阅yum(8),
                            #简单的说就是相当于upgrade,允许更新陈旧的RPM包。
gpgcheck=1                  #是否检查GPG(GNU Private Guard),一种密钥方式签名。
plugins=1                   #是否允许使用插件,默认是0不允许,
                            #但是我们一般会用yum-fastestmirror这个插件。
installonly_limit=3         #允许保留多少个内核包。
exclude=selinux*            #屏蔽不想更新的RPM包,可用通配符,多个RPM包之间使用空格分离。
distroverpkg=centos-release #将 $releasever设置为centos-release 这个RPM包的版本号 

centos-release是一个rpm包(通过:rpm可以查询到该软件包并没有被安装)

rpm -q centos-release
#结果报出package centos-release is not installed 发现自己没安装centos-release
yum install centos-release
#结果有爆出我已经安装了 但是没办法使用

最后没办法 只能手动把$releasever替换成7也就是我自己centos的版本,然后清空一下缓存

yum clean all
yum makecache

最后再去安装,就没问题了。

本文标签: repomdXMLfailurerepodatamirrors