转载自: https://blog.csdn.net/u010886217/article/details/88647591
一、目的
当集群部署在离线环境下,而系统又是比较纯净的时候,是没有yum源去安装相应依赖的。所以导致,安装程序很多失败。所以,决定自己创建私有的yum源,从而可以在离线环境中使用yum命令安装必备的文件。
二、步骤
1.下载包含yum源的镜像文件(即centos7.4安装文件)
进入下载初始页,选择对应版本7.4.1708
http://vault.centos.org/
选择Europe的第一个
http://vault.centos.org/notonvault.html
选择对应版本,在此选择下载7.4
http://mirror.nsc.liu.se/centos-store/7.4.1708/isos/x86_64/
下载依据需求而定,最好下载everyting版本,但是因为太大,本文下载CentOS-7-x86_64-DVD-1708.iso版本
CentOS-7-x86_64-DVD-1708.iso
2.上传到服务器
/opt/softwares/CentOS-7-x86_64-DVD-1708.iso
3.挂着镜像到服务器
mount /opt/softwares/CentOS-7-x86_64-DVD-1708.iso /mnt/cdrom/
4.将挂在盘内容复制到本地目录
mkdir /media/CentOS/ cp -fr /mnt/cdrom/* /media/CentOS/
5.将Yum源仓库repo备份
mkdir /etc/yum.repos.d/bakmv /etc/yum.repos.d/* /etc/yum.repos.d/bak
备注:一定移除或者重命名/etc/yum.repos.d/CentOS-Base.repo这个文件,因为默认会首先读取这个访问外网源的文件
6.复制CentOS-Media.repo并且编辑
cp /etc/yum.repos.d/bak/CentOS-Media.repo /etc/yum.repos.d/ vi /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-7. 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=c7-media [command]## or for ONLY the media repo, do this:## yum --disablerepo=\* --enablerepo=c7-media [command] [c7-media]name=CentOS-$releasever - Mediabaseurl=file:///media/CentOS/ #(1)-->这一行改成前边我们新建的CentOS目录# file:///media/cdrom/ #(2)-->这一行加#号注释掉# file:///media/cdrecorder/ #(3)-->这一行加#号注释掉gpgcheck=1enabled=1 #(4)-->这一行把0改成1来启用源gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
7.卸载镜像
umount /mnt/cdrom/
8.检测
yum list结果:systemtap-server.x86_64 3.1-3.el7 c7-media t1lib.x86_64 5.1.2-14.el7 c7-media taglib.x86_64 1.8-7.20130218git.el7 c7-media tagsoup.noarch 1.2.1-8.el7 c7-media talk.x86_64 0.17-46.el7 c7-media talk-server.x86_64 0.17-46.el7 c7-media targetcli.noarch 2.1.fb46-1.el7 c7-media targetd.noarch 0.8.6-1.el7 c7-media tbb.x86_64 4.1-9.20130314.el7 c7-media tbb-devel.x86_64 4.1-9.20130314.el7 c7-media tboot.x86_64 1:1.9.5-1.el7 c7-media tcl.x86_64 1:8.5.13-8.el7 c7-media tcl-devel.x86_64 1:8.5.13-8.el7 c7-media tcl-pgtcl.x86_64 2.0.0-5.el7 c7-media tcp_wrappers.x86_64 7.6-77.el7 c7-media tcp_wrappers-devel.x86_64 7.6-77.el7 c7-media tcpdump.x86_64 14:4.9.0-5.el7 c7-media tcsh.x86_64 6.18.01-15.el7 c7-media tdb-tools.x86_64 1.3.12-2.el7 c7-media telepathy-farstream.x86_64 0.6.0-5.el7 c7-media telepathy-filesystem.noarch 0.0.2-6.el7 c7-media telepathy-gabble.x86_64 0.18.1-4.el7 c7-media
(成功部署本地源~)
三、共享yum源
1.在本地yum源配置完成之后安装apache
yum install httpd systemctl start httpdsystemctl enable httpdsystemctl stop firewalldsystemctl disable firewalld
2.创建挂载文件目录
mkdir /var/www/html/source7.4
3.挂载镜像
mount /opt/softwares/CentOS-7-x86_64-DVD-1708.iso /var/www/html/source7.4/
4.开机自动挂载
(1)编辑rc.local写入vim /etc/rc.d/rc.local mount /opt/softwares/CentOS-7-x86_64-DVD-1708.iso /var/www/html/source7.4/(2)修改权限chmod +x /etc/rc.d/rc.local
5.访问
http://IP/source7.4/
结果