CentOS 使用本地镜像做 yum 源


:Mr.zhou  阅读: 3,194 次

演示系统:CentOS release 6.5 (Final)

一、使用光盘通过光驱做 yum 源安装软件

  1、查看系统 yum 源的本地配置文件默认的挂载点

[root@localhost ~]# cat /etc/yum.repos.d/CentOS-Media.repo
# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  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:///media/CentOS/
        file:///media/cdrom/
        file:///media/cdrecorder/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[root@localhost ~]#

  默认的 baserul 为/media/CentOS/ /media/cdrom/ /media/cdrecorder/ 将光盘挂载至任一目录均可

  2、将光盘放入光驱中,登录到系统,执行以下操作

[root@localhost ~]# mkdir -p /media/CentOS/  (新建光盘挂载目录)
[root@localhost ~]# mount /dev/cdrom /media/CentOS/  (挂载光盘)
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6  (安装证书)
[root@localhost ~]# yum clean all  (清理 yum)
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors

  3、使用本地yum源安装软件

[root@localhost ~]# yum --disablerepo=\* --enablerepo=c6-media install ntp  (使用光盘安装软件)
Loaded plugins: fastestmirror
Determining fastest mirrors
 * c6-media:
c6-media                                                 | 4.0 kB     00:00 ...
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ntp.i686 0:4.2.6p5-1.el6.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package     Arch         Version                        Repository        Size
================================================================================
Installing:
 ntp         i686         4.2.6p5-1.el6.centos           c6-media         586 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 586 k
Installed size: 1.6 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : ntp-4.2.6p5-1.el6.centos.i686                                1/1
  Verifying  : ntp-4.2.6p5-1.el6.centos.i686                                1/1

Installed:
  ntp.i686 0:4.2.6p5-1.el6.centos

Complete!
[root@localhost ~]#

二、使用镜像文件做 yum 源

[root@localhost src]# pwd
/usr/local/src
[root@localhost src]# ls
CentOS-6.5-i386-bin-DVD1.iso  linux  linux-0.11  linux-0.11.tar.gz
[root@localhost src]# mkdir -p /media/CentOS/
[root@localhost src]# mount -t iso9660 -o loop CentOS-6.5-i386-bin-DVD1.iso /media/CentOS/
[root@localhost src]# yum --disablerepo=\* --enablerepo=c6-media clean all
Loaded plugins: fastestmirror
Cleaning repos: c6-media
Cleaning up Everything
[root@localhost src]# yum --disablerepo=\* --enablerepo=c6-media makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
 * c6-media:
c6-media                                                 | 4.0 kB     00:00 ...
c6-media/group_gz                                        | 212 kB     00:00 ...
c6-media/filelists_db                                    | 4.9 MB     00:00 ...
c6-media/primary_db                                      | 3.4 MB     00:00 ...
c6-media/other_db                                        | 2.1 MB     00:00 ...
Metadata Cache Created
[root@localhost src]# yum --disablerepo=\* --enablerepo=c6-media install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * c6-media:
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.i686 0:2.2.15-29.el6.centos will be installed
--> Processing Dependency: httpd-tools = 2.2.15-29.el6.centos for package: httpd-2.2.15-29.el6.centos.i686
--> Processing Dependency: libaprutil-1.so.0 for package: httpd-2.2.15-29.el6.centos.i686
--> Processing Dependency: libapr-1.so.0 for package: httpd-2.2.15-29.el6.centos.i686
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-29.el6.centos.i686
--> Processing Dependency: /etc/mime.types for package: httpd-2.2.15-29.el6.centos.i686
--> Running transaction check
---> Package apr.i686 0:1.3.9-5.el6_2 will be installed
---> Package apr-util.i686 0:1.3.9-3.el6_0.1 will be installed
---> Package apr-util-ldap.i686 0:1.3.9-3.el6_0.1 will be installed
---> Package httpd-tools.i686 0:2.2.15-29.el6.centos will be installed
---> Package mailcap.noarch 0:2.1.31-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch        Version                     Repository     Size
================================================================================
Installing:
 httpd              i686        2.2.15-29.el6.centos        c6-media      828 k
Installing for dependencies:
 apr                i686        1.3.9-5.el6_2               c6-media      129 k
 apr-util           i686        1.3.9-3.el6_0.1             c6-media       89 k
 apr-util-ldap      i686        1.3.9-3.el6_0.1             c6-media       15 k
 httpd-tools        i686        2.2.15-29.el6.centos        c6-media       73 k
 mailcap            noarch      2.1.31-2.el6                c6-media       27 k

Transaction Summary
================================================================================
Install       6 Package(s)

Total download size: 1.1 M
Installed size: 3.4 M
Is this ok [y/N]:n

  开机自动挂载镜像文件

[root@localhost ~]# vi /etc/fstab
在文档末尾添加下行
/usr/local/src/CentOS-6.5-i386-bin-DVD1.iso     /media/CentOS   iso9660 defaults,ro,loop        0 0

转载请注明原文链接:http://www.z-dig.com/yum-use-local-source.html



正文部分到此结束