centos6.5系统-挂载本地镜像作为yum源

1、安装Centos6.5后默认的yum源如下

ll /etc/yum.repos.d/

centos6.5系统-挂载本地镜像作为yum源

2、备份默认的yum源

[[email protected] ~]# mkdir /opt/centos-yum.bak
[[email protected] ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/

centos6.5系统-挂载本地镜像作为yum源

3、将iso镜像上传到服务器上

mkdir /mnt/iso 放到该目录下

mkdir /opt/centos 创建挂载目录

4、然后挂载:

mount -o loop -t iso9660 /mnt/iso/CentOS-6.5-x86_64-bin-DVD1.iso /opt/centos

centos6.5系统-挂载本地镜像作为yum源

5、编写repo文件并指向镜像的挂载目录

[[email protected] ~]# vi /etc/yum.repos.d/local.repo

添加下面的内容:

[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0

centos6.5系统-挂载本地镜像作为yum源

6、清除缓存

# yum clean all

# yum makecache 把Yum源缓存到本地,加快软件的搜索好安装速度

# yum list列出了yum包


[[email protected] iso]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: local
Cleaning up Everything
Cleaning up list of fastest mirrors
[[email protected] iso]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
local                                                                                                   | 4.0 kB     00:00 ... 
local/group_gz                                                                                          | 220 kB     00:00 ... 
local/filelists_db                                                                                      | 5.8 MB     00:00 ... 
local/primary_db                                                                                        | 4.4 MB     00:00 ... 
local/other_db                                                                                          | 2.7 MB     00:00 ... 
Metadata Cache Created
[[email protected] iso]# yum list
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
ConsoleKit.x86_64                                 0.4.1-3.el6                          @anaconda-CentOS-201311272149.x86_64/6.5
ConsoleKit-libs.x86_64                            0.4.1-3.el6                          @anaconda-CentOS-201311272149.x86_64/6.5
ConsoleKit-x11.x86_64                             0.4.1-3.el6                          @anaconda-CentOS-201311272149.x86_64/6.5
GConf2.x86_64                                     2.28.0-6.el6                         @anaconda-CentOS-201311272149.x86_64/6.5
MAKEDEV.x86_64                                    3.24-6.el6                           @anaconda-CentOS-201311272149.x86_64/6.5

centos6.5系统-挂载本地镜像作为yum源

7、查看yum仓库列表

# yum repolist
centos6.5系统-挂载本地镜像作为yum源

8、开机自动挂载

在/etc/fstab表中,添加最后的一行,将iso文件永久挂载到系统中

# vi /etc/fstab

/mnt/iso/CentOS-6.5-x86_64-bin-DVD1.iso /opt/centos iso9660 loop 0 0

9、取消挂载(需要的时候再执行):

卸载挂载目录: # umount /opt/centos