创建挂载路径
sudo mkdir /mnt/iso
挂载ISO镜像到目录
sudo mount -o loop CentOS-***.iso /mnt/iso
验证挂载
df -h
修改文件名
进入/etc/yum.repos.d/路径下,把除CentOS-Media.repo文件外都加上old后缀
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.old
mv /etc/yum.repos.d/CentOS-CR.repo /etc/yum.repos.d/CentOS-CR.repo.old
mv /etc/yum.repos.d/CentOS-Debuginfo.repo /etc/yum.repos.d/CentOS-Debuginfo.repo.old
mv /etc/yum.repos.d/CentOS-fasttrack.repo /etc/yum.repos.d/CentOS-fasttrack.repo.old
mv /etc/yum.repos.d/CentOS-Sources.repo /etc/yum.repos.d/CentOS-Sources.repo.old
mv /etc/yum.repos.d/CentOS-Vault.repo /etc/yum.repos.d/CentOS-Vault.repo.old
编辑文件内容
执行命令vi /etc/yum.repos.d/CentOS-Media.repo,把红框内内容改成如下内容:
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/iso
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
更新yum源
yum clean all
yum makecache
验证
使用yum安装:yum install -y perl-DBD-MySQL,命令正常执行,证明配置成功