前提:防火墙关闭、SElinus关闭
1、上传ISO镜像(建议传到home目录下)
[root@localhost home]# ls iso/
CentOS-7.4-x86_64-DVD-.iso
2、挂载目录
[root@localhost home]# mount /home/iso/CentOS-7.4-x86_64-DVD-.iso /mnt/
mount: /dev/loop2 写保护,将以只读方式挂载
3、修改配置文件
3.1 进入目录并备份原始配置文件
[root@localhost opt]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv CentOS-* bak/
3.2 创建yum的repo文件
[root@localhost yum.repos.d]# vi yum.repo
[centos]
name=centos-danji
enabled=
gpgcheck=
baseurl=file:///mnt
4、查看yum配置是否生效
[root@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称 状态
centos centos-danji ,
repolist: ,
5、结束