CentOS配置本地yum源(使用镜像iso文件)

时间:2022-06-04 05:43:36

本人在使用yum安装软件的时候,感觉最不爽的是网络不佳时,安装的速度特别慢。所以,个人就上网search了一下如何使用Linux的安装文件作为其yum源。经过几次尝试,已经可以成功的配置了。下面是详细的介绍:

(1)个人的使用环境

本人的CentOS是安装在vmware上的:VMware workstation 7.1.1 + CentOS 5.5

(2)yum使用的相关文件介绍

CentOS使用的yum源是在/etc/yum.repos.d/目录下的两个文件中进行配置的CentOS-Base.repo和CentOS-Media.repo,其中,CentOS-Base.repo是配置网络yum源,CentOS-Media.repo是配置本地yum源。

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

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

total 16

-rw-r--r-- 1 root root 2245 Apr 26  2010 CentOS-Base.repo

-rw-r--r-- 1 root root  626 Apr 26  2010 CentOS-Media.repo

我们可以看看CentOS-Media.repo中的内容:

[root@localhost yum.repos.d]# more 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/CentOS/

file:///media/cdrom/

file:///media/cdrecorder/

gpgcheck=1

enabled=0

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

其中,baseurl是本地yum源的位置,当然,根据我们iso的配置位置,这里是可以进行修改的。不过,我只是将iso文件挂载到/media/CentOS/目录,所以,我也没有做修改。

(3)挂载iso文件
    本人的iso文件是在宿主机上,所以,通过vmware的文件共享,将宿主机上的iso文件挂载到/mnt/hgfs/目录下:
VM->Settings->Options选项卡->Shared Folders->Set Folder sharing as 'Always enabled'
    使用Add button选取本地iso文件的目录,我的CentOS放在D:/Software/os/目录下,所以,添加后的截图如下:
CentOS配置本地yum源(使用镜像iso文件)
    点击'OK',完成共享。
    在CentOS中,我们可以在/mnt/hgfs/目录下发现一个os/子目录,CentOS的iso文件也就在该目录下,本人共享以后,iso文件在CentOS的路径为:/mnt/hgfs/os/CentOS-5.5-i386-bin-DVD.iso
将该镜像文件挂载到/media/CentOS/
[root@localhost yum.repos.d]# mount -o loop /mnt/hgfs/os/CentOS-5.5-i386-bin-DVD.iso /media/CentOS/
(4)使用本地yum源安装软件
使用本地yum源的方法在CentOS-Media.repo中已经描述了:
(4.1)除了使用本地yum源,也会是使用其他的yum源
yum --enablerepo=c5-media [command]
(4.2)只是用本地yum源
yum --disablerepo=/* --enablerepo=c5-media [command]
下面是用本地yum源安装mysql
[root@localhost yum.repos.d]# yum --disablerepo=/* --enablerepo=c5-media install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * c5-media: 
c5-media                                                 | 1.1 kB     00:00     
c5-media/primary                                         | 920 kB     00:00     
c5-media                                                              2599/2599
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.i386 0:5.0.77-4.el5_4.2 set to be updated
--> Processing Dependency: mysql = 5.0.77-4.el5_4.2 for package: mysql-server
--> Processing Dependency: perl(DBI) for package: mysql-server
--> Processing Dependency: libmysqlclient.so.15(libmysqlclient_15) for package: mysql-server
--> Processing Dependency: perl-DBI for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.15(libmysqlclient_15) for package: mysql-server
--> Processing Dependency: libmysqlclient.so.15 for package: mysql-server
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.15 for package: mysql-server
--> Running transaction check
---> Package mysql.i386 0:5.0.77-4.el5_4.2 set to be updated
---> Package perl-DBD-MySQL.i386 0:3.0007-2.el5 set to be updated
---> Package perl-DBI.i386 0:1.52-2.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package              Arch       Version                   Repository      Size
================================================================================
Installing:
 mysql-server         i386       5.0.77-4.el5_4.2          c5-media       9.8 M
Installing for dependencies:
 mysql                i386       5.0.77-4.el5_4.2          c5-media       4.8 M
 perl-DBD-MySQL       i386       3.0007-2.el5              c5-media       148 k
 perl-DBI             i386       1.52-2.el5                c5-media       600 k
Transaction Summary
================================================================================
Install       4 Package(s)
Upgrade       0 Package(s)
Total download size: 15 M
Is this ok [y/N]: y
Downloading Packages:
--------------------------------------------------------------------------------
Total                                           469 MB/s |  15 MB     00:00     
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897
c5-media/gpgkey                                          | 1.5 kB     00:00     
Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <centos-5-key@centos.org>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : perl-DBI                                                 1/4 
  Installing     : mysql                                                    2/4 
  Installing     : perl-DBD-MySQL                                           3/4 
  Installing     : mysql-server                                             4/4 
Installed:
  mysql-server.i386 0:5.0.77-4.el5_4.2                                          
Dependency Installed:
  mysql.i386 0:5.0.77-4.el5_4.2        perl-DBD-MySQL.i386 0:3.0007-2.el5       
  perl-DBI.i386 0:1.52-2.el5          
Complete!
    速度很快,要比使用网络yum源安装快多了!