linux本地關盤做yum源

dotaddjj發表於2012-08-20

Linux下可以用本地光碟做yum源,這在有些網路環境無法連線網際網路的伺服器下很有幫助,特別是對於安裝oracle資料庫那些繁瑣的依賴包,不過如果是oel的那就另當別論了。

新建一個目錄,掛載光碟映象,需要以只讀方式掛載。

[root@localhost ~]# mkdir /media/mnt

[root@localhost ~]# mount /dev/cdrom /media/mnt

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@localhost ~]# mount -o r /dev/cdrom /media/mnt

mount: block device /dev/cdrom is write-protected, mounting read-only

mount: /dev/cdrom already mounted or /media/mnt busy

mount: according to mtab, /dev/hdc is already mounted on /media/mnt

此時已經掛載關盤了

[root@localhost ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda1 12G 5.1G 6.1G 46% /

/dev/sda2 1.9G 36M 1.8G 2% /home

tmpfs 385M 0 385M 0% /dev/shm

/dev/hdc 3.7G 3.7G 0 100% /media/mnt

修改/etc/yum.repos.d下的檔案,不啟用網路的yum源,linux預設使用的網路的yum

[root@localhost ~]# cd /etc/yum.repos.d/

[root@localhost yum.repos.d]# ll

total 12

-rw-r--r-- 1 root root 2323 Mar 16 2009 CentOS-Base.repo

-rw-r--r-- 1 root root 562 Aug 20 04:31 CentOS-Media.repo

[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repobak

[root@localhost yum.repos.d]# vi CentOS-Media.repo

# CentOS-Media.repo

#

# This repo is used to mount the default locations for a CDROM / DVD on

# CentOS-5. 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=c5-media [command]

#

# or for ONLY the media repo, do this:

#

# yum --disablerepo=* --enablerepo=c5-media [command]

[c5-media]

name=CentOS-$releasever - Media

baseurl=file:///media/mnt –這個改成你mount光碟的目錄

gpgcheck=1

enabled=1—原來的enable=0,改為enable=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

~

~

"CentOS-Media.repo" 19L, 559C written

檢視是否能正常使用yum源,可能會遇到如下的錯誤,找到相應的程式kill掉即可。

[root@localhost yum.repos.d]# yum list

Loaded plugins: fastestmirror

Existing lock /var/run/yum.pid: another copy is running as pid 8101.

Another app is currently holding the yum lock; waiting for it to exit...

Another app is currently holding the yum lock; waiting for it to exit...

[root@localhost yum.repos.d]# ps -ef|grep yum

root 8101 2778 0 04:35 pts/2 00:00:00 /usr/bin/python /usr/bin/yum list

root 8120 2778 0 04:38 pts/2 00:00:00 grep yum

[root@localhost yum.repos.d]# kill -9 8101

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25362835/viewspace-1059220/,如需轉載,請註明出處,否則將追究法律責任。

相關文章