通过ISO镜像简单搭建本地yum仓库
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过ISO镜像简单搭建本地yum仓库相关的知识,希望对你有一定的参考价值。
在一次安装软件过程中,需要依赖包,但是这个依赖包没有在原先的ISO源里面。因为下载的系统包有CD1跟CD2,检查后发现所需的rpm包在CD2里面,直接配置CD2为yum源时缺需要CD1里面的rpm包。最后想了个办法,用软连接把两个ISO的包合并后得到一个完整的安装源。
在一台机器上配置后,可以在这台服务器上搭建http服务器,把它当作一个内网的yum仓库使用。通过目录区分不同版本的yum源,简化并统一内网服务器的yum源配置。
一、原始的yum配置。
[[email protected] ~]# cat /etc/yum.repos.d/cd.repo [iso] name=iso baseurl=file:///mnt/iso/ enabled=1 gpgcheck=0 [[email protected] ~]# mount /dev/cdrom /mnt/iso/ mount: block device /dev/sr0 is write-protected, mounting read-only #### 安装rrdtool-perl时候报错 #### [[email protected] ~]# yum install rrdtool-perl -y ...... Error Downloading Packages: rrdtool-perl-1.3.8-6.el6.x86_64: failure: Packages/rrdtool-perl-1.3.8-6.el6.x86_64.rpm from iso: [Errno 256] No more mirrors to try. #### 查看ISO目录下,未发现rpm包 #### [[email protected] ~]# ls /mnt/iso/Packages/ |grep rrdtool-perl #### 挂载CD2,并查看发现该rpm包在CD2上面 #### [[email protected] yum.repos.d]# umount /mnt/iso/ [[email protected] ~]# mount -o loop /vm/iso/CentOS-6.5-x86_64-bin-DVD2.iso /mnt/iso [[email protected] ~]# grep *rrdtool-perl* #### 再次安装时找不到其他依赖包 #### [[email protected] ~]# yum install rrdtool-perl -y Error Downloading Packages: rrdtool-1.3.8-6.el6.x86_64: failure: Packages/rrdtool-1.3.8-6.el6.x86_64.rpm from iso: [Errno 256] No more mirrors to try. dejavu-sans-mono-fonts-2.30-2.el6.noarch: failure: Packages/dejavu-sans-mono-fonts-2.30-2.el6.noarch.rpm from iso: [Errno 256] No more mirrors to try. dejavu-fonts-common-2.30-2.el6.noarch: failure: Packages/dejavu-fonts-common-2.30-2.el6.noarch.rpm from iso: [Errno 256] No more mirrors to try. dejavu-lgc-sans-mono-fonts-2.30-2.el6.noarch: failure: Packages/dejavu-lgc-sans-mono-fonts-2.30-2.el6.noarch.rpm from iso: [Errno 256] No more mirrors to try.
二、卸载当前ISO,将两个ISO分别挂载到/mnt/cd1,/mnt/cd2上,然后通过软链接的形式合并两个ISO的rpm包。
[[email protected] ~]#umount /mnt/iso/ [[email protected] ~]#mkdir -p /mnt/iso/6.5/Packages [[email protected] ~]#mkdir /mnt/cd1 [[email protected] ~]#mkdir /mnt/cd2 [[email protected] ~]#ln -s /mnt/cd1/Packages/* /mnt/iso/6.5/Packages/ [[email protected] ~]#ln -s /mnt/cd2/Packages/* /mnt/iso/6.5/Packages/ [[email protected] ~]#rm -f /mnt/iso/6.5/Packages/TRANS.TBL [[email protected] ~]#cat /mnt/cd1/Packages/TRANS.TBL /mnt/cd2/Packages/TRANS.TBL |sort > /mnt/iso/6.5/Packages/TRANS.TBL [[email protected] ~]#ln -s /mnt/cd1/repodata/ /mnt/iso/6.5/ [[email protected] ~]#
三、修改yum配置,并测试安装。
#### 由于新建立的目录修改为/mnt/iso/6.5/,需要对原先的yum源进行修改 #### [[email protected] /]# cat /etc/yum.repos.d/cd.repo |grep baseurl baseurl=file:///mnt/iso/6.5/ [[email protected] ~]#yum clean all [[email protected] ~]#yum list all #### 整合后能够成功安装rrdtool-perl #### [[email protected] ~]#yum install rrdtool-perl -y ...... Installed: rrdtool-perl.x86_64 0:1.3.8-6.el6 Dependency Installed: dejavu-fonts-common.noarch 0:2.30-2.el6 dejavu-lgc-sans-mono-fonts.noarch 0:2.30-2.el6 dejavu-sans-mono-fonts.noarch 0:2.30-2.el6 rrdtool.x86_64 0:1.3.8-6.el6 Complete!
四、接下来部署apache服务搭建本地的yum源,将/mnt/iso/目录以http的方式发布出去。
#### 安装apache #### [[email protected] ~]#yum install httpd -y #### 发布yum仓库 #### [[email protected] ~]#cat /etc/httpd/conf.d/yum.conf NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /mnt/iso/ </VirtualHost> <Directory "/mnt/iso/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> [[email protected] ~]# chkconfig httpd --level 345 on [[email protected] ~]#/etc/init.d/httpd restart #### 添加ISO盘开机自动挂载。直接将挂载写在rc.local文件里。 #### #### 此处不建议修改/etc/fstab,以避免移除ISO导致系统启动失败。#### [[email protected] ~]# cat /etc/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don‘t # want to do the full Sys V style init stuff. touch /var/lock/subsys/local mount -o loop /vm/iso/CentOS-6.5-x86_64-bin-DVD1.iso /mnt/cd1 mount -o loop /vm/iso/CentOS-6.5-x86_64-bin-DVD2.iso /mnt/cd2
如果内网有其他版本的系统,只需要在/mnt/iso下面新建相应的目录,将镜像链接到该目录下即可,无需修改apache的配置。如需要搭建centos7.2的源,只需把7.2的镜像链接到/mnt/iso/7.2/这个目录底下。
五、在另一台服务器配置yum源测试。
[[email protected] ~]# cat /etc/yum.repos.d/http243.repo [http243] name=http243 baseurl=http://192.168.175.243/6.5/ enabled=1 gpgcheck=0 [[email protected] ~]# yum clean all [[email protected] ~]# yum list all [[email protected] ~]# yum install rrdtool-perl -y
在内网的其他服务器上,只需将/etc/yum.repos.d/http243.repo这个配置文件放上去,然后修改对应的目录,就可以完成配置了,在多台服务器要安装基础包的时候可以简化很多操作。
本文出自 “一年后回头看看” 博客,请务必保留此出处http://cubix.blog.51cto.com/7251166/1852065
以上是关于通过ISO镜像简单搭建本地yum仓库的主要内容,如果未能解决你的问题,请参考以下文章