当前位置:   article > 正文

CentOS中使用yum命令产生报错_centos gpgkey

centos gpgkey
之前想使用yum命令进行一个网络扫描命令nmap的安装,发现系统进行相关报错。输入yum -y install nmap后发现
  • 1
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=i386&repo=os error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot find a valid baseurl for repo: base
  • 1
  • 2
  • 3
  • 4
  • 5

报错内容

然后想进行网络yum源的配置文件的检查,查看问题所在。键入vi /etc/yum.repos.d/CentOS-Base.repo
  • 1
# vi /etc/yum.repos.d/CentOS-Base.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
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

这里写图片描述

发现网络yum源配置文件没有问题,这里对于配置文件中的一些参数进行简要解释:
  • 1
  • [base] 容器名称
  • name 容器说明,可以自己随便写
  • mirrorlist 镜像站点,这个可以注释掉
  • baseurl yum源服务器的地址
  • enabled 此容器是否生效,如果不写或者写成enable=1都是生效,写成enable=0就是不生效
  • gpgcheck 如果是1是指RPM的数字证书生效,如果是0则不生效
  • gpgkey 数字证书的公钥文件保存位置,不用修改

    检查网络yum源配置没有问题之后,查看光盘yum源是否挂载
    mount /dev/cdrom /mnt/cdrom

# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
mount: /dev/sr0 already mounted or /mnt/cdrom busy
mount: according to mtab, /dev/sr0 is already mounted on /mnt/cdrom
  • 1
  • 2
  • 3
  • 4

这里写图片描述

如若挂载正常,常理光盘yum源是可以使用的,此时出现报错,检查yum源文件目录
  • 1
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo
  • 1
  • 2
  • 3
发现目录中的网络yum源文件与光盘yum源都是调用格式,产生冲突,导致无法使用yum命令,此时选择将网络yum源文件失效,保留CentOS-Media.repo文件名不变
  • 1
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost yum.repos.d]# mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo.bak
[root@localhost yum.repos.d]# mv CentOS-Vault.repo CentOS-Vault.repo.bak
[root@localhost yum.repos.d]# ls
CentOS-Base.repo.bak  CentOS-Debuginfo.repo.bak  CentOS-Media.repo  CentOS-Vault.repo.bak
  • 1
  • 2
  • 3
  • 4
  • 5

这里写图片描述

名称修改后即可将网络yum源文件失效,接着进行光盘yum源文件的修改,注意将地址改为自己的光盘挂载地址,注释掉两个不存在的地址以及将文件中的enabled=0改为enabled=1,让这个yum源配置文件生效
  • 1
[root@localhost yum.repos.d]# vim CentOS-Media.repo 
# CentOS-Media.repo
#
# This repo is used to mount the default locations for a CDROM / DVD on
#  CentOS-6.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c6-media [command]
#
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c6-media [command]

[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/cdrom
#file:///media/CentOS/
#        file:///media/cdrom/
#       file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

这里写图片描述

上述操作完成后,重新试一下yum命令是否可用,输入 yum -y install nmap
  • 1
[root@localhost ~]# yum install nmap
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
c6-media                                                                                                                     | 4.0 kB     00:00 ... 
Setting up Install Process
Package 2:nmap-5.51-2.el6.i686 already installed and latest version
Nothing to do
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

这里写图片描述

提示nmap命令已经下载且为最新版本,没有产生报错,则yum命令此时正确可用。
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/790654
推荐阅读
相关标签
  

闽ICP备14008679号