实验环境为Centos7.5
[root@localhost ~]# mkdir /mnt/cdrom #创建挂载文件夹
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom #挂载光驱ISO文件
mount: /dev/sr0 写保护,将以只读方式挂载
#[root@localhost ~]# mount /opt/CentOS-7-x86_64-Minimal-1804.iso /mnt/cdrom #挂载本地ISO文件也是相同的#
[root@localhost ~]# ls /mnt/cdrom/ #检查挂载文件
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
[root@localhost ~]# cd /etc/yum.repos.d/ #进入yum配置文件夹
[root@localhost yum.repos.d]# ls #查看yum配置文件
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak #移动网络yum配置文件,无法找到时会转到本地下载。
[root@localhost yum.repos.d]# cp CentOS-Media.repo CentOS-Media.repo.bak #备份本地yum配置文件
[root@localhost yum.repos.d]# vi CentOS-Media.repo #编辑本地yum配置文件
# 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 - Media
baseurl=file:///media/CentOS/
file:///mnt/cdrom/ #将目录改成光盘挂载点
file:///media/cdrecorder/
gpgcheck=1
enabled=1 #将enabled=0改成1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#保存退出
[root@localhost yum.repos.d]# yum install -y net-tools #安装网络工具进行测试
.
.此处省略安装过程
.
完毕!#本地yum可以正常使用了