赞
踩
之前想使用yum命令进行一个网络扫描命令nmap的安装,发现系统进行相关报错。输入yum -y install nmap后发现
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
然后想进行网络yum源的配置文件的检查,查看问题所在。键入vi /etc/yum.repos.d/CentOS-Base.repo
# 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/

发现网络yum源配置文件没有问题,这里对于配置文件中的一些参数进行简要解释:
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
如若挂载正常,常理光盘yum源是可以使用的,此时出现报错,检查yum源文件目录
[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
发现目录中的网络yum源文件与光盘yum源都是调用格式,产生冲突,导致无法使用yum命令,此时选择将网络yum源文件失效,保留CentOS-Media.repo文件名不变
[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
名称修改后即可将网络yum源文件失效,接着进行光盘yum源文件的修改,注意将地址改为自己的光盘挂载地址,注释掉两个不存在的地址以及将文件中的enabled=0改为enabled=1,让这个yum源配置文件生效
[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

上述操作完成后,重新试一下yum命令是否可用,输入 yum -y install nmap
[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
提示nmap命令已经下载且为最新版本,没有产生报错,则yum命令此时正确可用。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。