RedHat服務器上[Errno 5] OSError: [Errno 2]的解決方法
cnblogs 發(fā)布時間:2015-10-16 10:21:43 作者:瀟湘隱者
我要評論

這篇文章主要介紹了RedHat服務器上[Errno 5] OSError: [Errno 2]的解決方法,針對RHEL配置本地yum源時出現(xiàn)的錯誤,需要的朋友可以參考下
在Red Hat Enterprise Linux Server release 5.7 上配置YUM本地源時,遇到了"[Errno 5] OSError: [Errno 2] No such file or directory xxxx",花了點時間搞清楚錯誤的來龍去脈。特此記錄一下:
將Redhat 5.7的光盤鏡像拷貝到了/mnt/cdrom/LinuxSrc目錄下,配置了rhel-media.repo文件,如下所示
[root@DB-Server yum.repos.d]# more rhel-media.repo
[media]
name=Red Hat Enterprise Linux 5.7 baseurl=file:///mnt/cdrom/LinuxSrc
enabled=1
gpgcheck=0 gpgkey=file:///mnt/cdrom/LinuxSrc/RPM-GPG-KEY-redhat-release
執(zhí)行yum clean all命令后,執(zhí)行yum makecache遇到了下面錯誤:
[root@DB-Server yum.repos.d]# yum clean all
Loaded plugins: product-id, security, subscription-manager
Updating Red Hat repositories.
Cleaning up Everything
[root@DB-Server yum.repos.d]# yum makecache
Loaded plugins: product-id, security, subscription-manager
Updating Red Hat repositories.
file:///mnt/cdrom/LinuxSrc/repodata/repomd.xml: [Errno 5] OSError: [Errno 2] No such file or directory: '/mnt/cdrom/LinuxSrc/repodata/repomd.xml'
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: media. Please verify its path and try again
[root@DB-Server yum.repos.d]#

出現(xiàn)這個錯誤的根本原因在于RHEL 5.x 版本與RHEL 6.x 版本的rpm包存放路徑不同:
RHEL 5.x : ../Server 例如:我案例環(huán)境位于/mnt/cdrom/LinuxSrc/Server 下。
RHEL 6.x : ../Packages
所以還在于上面的baseurl參數(shù)設置錯誤。那么我們可以通過兩種方法解決這個問題:
方法1:配置正確的baseurl參數(shù)。
[root@DB-Server yum.repos.d]# vi rhel-media.repo
[media]
name=Red Hat Enterprise Linux 5.7 baseurl=file:///mnt/cdrom/LinuxSrc/Server
enabled=1
gpgcheck=0
gpgkey=file:///mnt/cdrom/LinuxSrc/RPM-GPG-KEY-redhat-release

方法2:使用createrepo命令創(chuàng)建本地源目錄,將其指向baseurl指定的目錄
[root@DB-Server Server]# rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm
warning: createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:createrepo ########################################### [100%]
[root@DB-Server Server]# createrepo --update /mnt/cdrom/LinuxSrc
Previous repo file missing: /mnt/cdrom/LinuxSrc/repodata/primary.xml.gz3388/3388 - VT/etherboot-roms-5.4.4-15.el5.x86_64.rpm mm
Saving Primary metadata
Saving file lists metadata
Saving other metadata
You have new mail in /var/spool/mail/root
[root@DB-Server Server]# yum makecacheLoaded plugins: product-id, security, subscription-manager
Updating Red Hat repositories.
media | 951 B 00:00
media/filelists | 3.1 MB 00:00
media/other | 11 MB 00:00
media/primary | 1.1 MB 00:00
media 3388/3388
media 3388/3388
media 3388/3388
Metadata Cache Created[root@DB-Server Server]#
將Redhat 5.7的光盤鏡像拷貝到了/mnt/cdrom/LinuxSrc目錄下,配置了rhel-media.repo文件,如下所示
復制代碼
代碼如下:[root@DB-Server yum.repos.d]# more rhel-media.repo
[media]
name=Red Hat Enterprise Linux 5.7 baseurl=file:///mnt/cdrom/LinuxSrc
enabled=1
gpgcheck=0 gpgkey=file:///mnt/cdrom/LinuxSrc/RPM-GPG-KEY-redhat-release
執(zhí)行yum clean all命令后,執(zhí)行yum makecache遇到了下面錯誤:
復制代碼
代碼如下:[root@DB-Server yum.repos.d]# yum clean all
Loaded plugins: product-id, security, subscription-manager
Updating Red Hat repositories.
Cleaning up Everything
[root@DB-Server yum.repos.d]# yum makecache
Loaded plugins: product-id, security, subscription-manager
Updating Red Hat repositories.
file:///mnt/cdrom/LinuxSrc/repodata/repomd.xml: [Errno 5] OSError: [Errno 2] No such file or directory: '/mnt/cdrom/LinuxSrc/repodata/repomd.xml'
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: media. Please verify its path and try again
[root@DB-Server yum.repos.d]#

出現(xiàn)這個錯誤的根本原因在于RHEL 5.x 版本與RHEL 6.x 版本的rpm包存放路徑不同:
RHEL 5.x : ../Server 例如:我案例環(huán)境位于/mnt/cdrom/LinuxSrc/Server 下。
RHEL 6.x : ../Packages
所以還在于上面的baseurl參數(shù)設置錯誤。那么我們可以通過兩種方法解決這個問題:
方法1:配置正確的baseurl參數(shù)。
復制代碼
代碼如下:[root@DB-Server yum.repos.d]# vi rhel-media.repo
[media]
name=Red Hat Enterprise Linux 5.7 baseurl=file:///mnt/cdrom/LinuxSrc/Server
enabled=1
gpgcheck=0
gpgkey=file:///mnt/cdrom/LinuxSrc/RPM-GPG-KEY-redhat-release

方法2:使用createrepo命令創(chuàng)建本地源目錄,將其指向baseurl指定的目錄
復制代碼
代碼如下:[root@DB-Server Server]# rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm
warning: createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:createrepo ########################################### [100%]
[root@DB-Server Server]# createrepo --update /mnt/cdrom/LinuxSrc
Previous repo file missing: /mnt/cdrom/LinuxSrc/repodata/primary.xml.gz3388/3388 - VT/etherboot-roms-5.4.4-15.el5.x86_64.rpm mm
Saving Primary metadata
Saving file lists metadata
Saving other metadata
You have new mail in /var/spool/mail/root
[root@DB-Server Server]# yum makecacheLoaded plugins: product-id, security, subscription-manager
Updating Red Hat repositories.
media | 951 B 00:00
media/filelists | 3.1 MB 00:00
media/other | 11 MB 00:00
media/primary | 1.1 MB 00:00
media 3388/3388
media 3388/3388
media 3388/3388
Metadata Cache Created[root@DB-Server Server]#
相關文章
CentOS、Redhat中鎖定、解鎖軟件包版本的方法(yum versionlock使用詳
有些時候,我們在對系統(tǒng)進行更新操作時,又不需要對某些軟件包進行升級操作,要把該包鎖定在某個特定版本下。比如mysql-server,為了避免更新遇到不可預知的錯誤,禁止對該2014-04-15- 相信對RedHat Linux或CentOS比較熟悉的人,應該是比較了解yum源的,它比普通的rpm包安裝,要方便的多,為何呢?本文將詳細介紹,有需要的朋友可以參考下2012-11-30
- 第一種方法: yum源來自chinalinuxpub.com,用的是centos包, 下載地址: http://www.chinalinuxpub.com/yum.tgz 安裝: tar zxvf yum.tgz cd yum rpm -ivh *2008-09-08