利用CentOS镜像文件制作yum 软件仓库

CentOS安装文件包含两个ISO文件,如6.5:

CentOS-6.5-x86_64-bin-DVD1.iso
CentOS-6.5-x86_64-bin-DVD2.iso

在安装系统系统时,只需要用到DVD1就可以了,DVD2中则包含了其他一些软件包。可以将两个ISO文件挂载到系统,并制作yum的本地仓库

制作软件仓库

  1. 挂载镜像文件

    mkdir /mnt/cdrom1
    mkdir /mnt/cdrom2
    
    mount -o loop  /opt/CentOS-6.5-x86_64-bin-DVD1.iso /mnt/cdrom1/
    mount -o loop  /opt/CentOS-6.5-x86_64-bin-DVD2.iso /mnt/cdrom2/
    

    如果是虚拟机,并且已经将镜像文件加载到DVD中,则使用以下命令挂载DVD

    mount /dev/cdrom  /mnt/cdrom1/
    mount /dev/cdrom1 /mnt/cdrom2/
    
  2. 增加软件仓库配置文件,在/etc/yum.repos.d/目录下新建centos_isos.repo文件,并输入以下信息,然后就完成了

    [centos_isos]
    name=CentOS-$releasever - isos
    baseurl=file:///mnt/cdrom1
            file:///mnt/cdrom2
    enabled=1
    gpgcheck=0
    gpgkey=
    

    以下为完整操作日志

    
    [root@centos-6 ~]# mkdir /mnt/cdrom1
    [root@centos-6 ~]# mkdir /mnt/cdrom2
    [root@centos-6 ~]# mount -o loop /opt/CentOS-6.5-x86_64-bin-DVD1.iso /mnt/cdrom1
    [root@centos-6 ~]# mount -o loop /opt/CentOS-6.5-x86_64-bin-DVD2.iso /mnt/cdrom2
    [root@centos-6 ~]# ll /mnt/cdrom2
    total 400
    -r--r--r--. 1 root root     14 Nov 29  2013 CentOS_BuildTag
    -r--r--r--. 1 root root    212 Nov 28  2013 EULA
    dr-xr-xr-x. 2 root root 397312 Nov 29  2013 Packages
    -r--r--r--. 1 root root   1706 Nov 28  2013 RPM-GPG-KEY-CentOS-6
    -r--r--r--. 1 root root   1730 Nov 28  2013 RPM-GPG-KEY-CentOS-Debug-6
    -r--r--r--. 1 root root   1730 Nov 28  2013 RPM-GPG-KEY-CentOS-Security-6
    -r--r--r--. 1 root root   1734 Nov 28  2013 RPM-GPG-KEY-CentOS-Testing-6
    -r--r--r--. 1 root root   2056 Nov 29  2013 TRANS.TBL
    [root@centos-6 ~]# ll /mnt/cdrom1
    total 682
    -r--r--r--. 2 root root     14 Nov 29  2013 CentOS_BuildTag
    dr-xr-xr-x. 3 root root   2048 Nov 29  2013 EFI
    -r--r--r--. 2 root root    212 Nov 28  2013 EULA
    -r--r--r--. 2 root root  18009 Nov 28  2013 GPL
    dr-xr-xr-x. 2 root root 655360 Nov 29  2013 Packages
    -r--r--r--. 2 root root   1354 Nov 28  2013 RELEASE-NOTES-en-US.html
    -r--r--r--. 2 root root   1706 Nov 28  2013 RPM-GPG-KEY-CentOS-6
    -r--r--r--. 2 root root   1730 Nov 28  2013 RPM-GPG-KEY-CentOS-Debug-6
    -r--r--r--. 2 root root   1730 Nov 28  2013 RPM-GPG-KEY-CentOS-Security-6
    -r--r--r--. 2 root root   1734 Nov 28  2013 RPM-GPG-KEY-CentOS-Testing-6
    -r--r--r--. 1 root root   3380 Nov 29  2013 TRANS.TBL
    dr-xr-xr-x. 3 root root   2048 Nov 29  2013 images
    dr-xr-xr-x. 2 root root   2048 Nov 29  2013 isolinux
    dr-xr-xr-x. 2 root root   4096 Nov 29  2013 repodata
    [root@centos-6 ~]#
    [root@centos-6 ~]#
    [root@centos-6 ~]# cd /etc/yum.repos.d/
    [root@centos-6 yum.repos.d]# ll
    total 24
    -rw-r--r--. 1 root root 1991 Oct 23  2014 CentOS-Base.repo
    -rw-r--r--. 1 root root  647 Oct 23  2014 CentOS-Debuginfo.repo
    -rw-r--r--. 1 root root  630 Oct 23  2014 CentOS-Media.repo
    -rw-r--r--. 1 root root 5394 Oct 23  2014 CentOS-Vault.repo
    -rw-r--r--. 1 root root  289 Oct 23  2014 CentOS-fasttrack.repo
    [root@centos-6 yum.repos.d]# mkdir centos
    [root@centos-6 yum.repos.d]# mv CentOS-* centos/
    [root@centos-6 yum.repos.d]# vi centos_isos.repo
    [root@centos-6 yum.repos.d]# ll
    total 8
    drwxr-xr-x. 2 root root 4096 May 20 10:14 centos
    -rw-r--r--. 1 root root  112 May 20 10:34 centos_isos.repo
    [root@centos-6 yum.repos.d]#
    [root@centos-6 yum.repos.d]# yum clean all
    Failed to set locale, defaulting to C
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Cleaning repos: centos_isos
    Cleaning up Everything
    Cleaning up list of fastest mirrors
    [root@centos-6 yum.repos.d]#
    

将软件仓库配置为HTTP访问

当内网中有多台机器时,可以将上面的软件仓库发布为http方式供内网中其他服务器使用。

  1. 首先需要安装httpd服务。

    httpd服务会自动将/var/www/html/目录下的文件发布为网络访问

yum install httpd
  1. 启动httpd服务,并设置开机启动
service httpd start
chkconfig httpd on
  1. 将iso挂载到指定目录下,通过httpd服务自动发布到网络
mkdir /var/www/html/cdrom1
mkdir /var/www/html/cdrom2

mount -o loop  /opt/CentOS-6.5-x86_64-bin-DVD1.iso	/var/www/html/cdrom1/
mount -o loop  /opt/CentOS-6.5-x86_64-bin-DVD2.iso  /var/www/html/cdrom2/

建议将以上两个文件设置为开机自动挂载,可通过在/etc/rc.local文件中增加以下内容开机自动挂载

mount -o loop  /opt/CentOS-6.5-x86_64-bin-DVD1.iso	/var/www/html/cdrom1/
mount -o loop  /opt/CentOS-6.5-x86_64-bin-DVD2.iso  /var/www/html/cdrom2/
  1. 配置软件仓库文件,修改前面建立的/etc/yum.repos.d/centos_isos.repo配置文件为HTTP访问方式
[centos_isos]
name=CentOS-$releasever - isos
baseurl=http://10.37.129.3/cdrom1/
        http://10.37.129.3/cdrom2/
enabled=1
gpgcheck=0
gpgkey=

ok,至此配置完成,其他机器如果需要使用此软件仓库,只需要在/etc/yum.repos.d/目录下新建一个.repo结尾的文件,并且输入以上内容就可以了

  1. 以下为操作日志
[root@centos-6 yum.repos.d]# yum install httpd
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * centos_isos:
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 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.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.2.15-29.el6.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================================
 Package                                   Arch                                 Version                                              Repository                                 Size
=====================================================================================================================================================================================
Installing:
 httpd                                     x86_64                               2.2.15-29.el6.centos                                 centos_isos                               821 k
Installing for dependencies:
 httpd-tools                               x86_64                               2.2.15-29.el6.centos                                 centos_isos                                73 k

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

Total download size: 894 k
Installed size: 3.1 M
Is this ok [y/N]: y
Downloading Packages:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                 27 MB/s | 894 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : httpd-tools-2.2.15-29.el6.centos.x86_64                                                                                                                           1/2
  Installing : httpd-2.2.15-29.el6.centos.x86_64                                                                                                                                 2/2
  Verifying  : httpd-2.2.15-29.el6.centos.x86_64                                                                                                                                 1/2
  Verifying  : httpd-tools-2.2.15-29.el6.centos.x86_64                                                                                                                           2/2

Installed:
  httpd.x86_64 0:2.2.15-29.el6.centos

Dependency Installed:
  httpd-tools.x86_64 0:2.2.15-29.el6.centos

Complete!
[root@centos-6 yum.repos.d]# service httpd start
Starting httpd:                                            [  OK  ]
[root@centos-6 yum.repos.d]# chkconfig httpd on
[root@centos-6 yum.repos.d]#
[root@centos-6 yum.repos.d]# mkdir /var/www/html/cdrom1
[root@centos-6 yum.repos.d]# mkdir /var/www/html/cdrom2
[root@centos-6 yum.repos.d]#
[root@centos-6 yum.repos.d]# mount  /dev/cdrom /var/www/html/cdrom1/
mount: block device /dev/sr1 is write-protected, mounting read-only
[root@centos-6 yum.repos.d]# mount /dev/cdrom1  /var/www/html/cdrom2/
mount: block device /dev/sr0 is write-protected, mounting read-only

你可能感兴趣的:(linux)