1.先查看是否有挂载镜像,若还没挂载,则先挂载好镜像
mkdir /mnt/cdrom
# 不指定文件系统,使用这句
mount /dev/cdrom /mnt/cdrom/
# 如果需要指定文件系统,则使用这句
mount -t iso9660 -o loop /dev/cdrom /mnt/cdrom/
2.若报错“/dev/sr0: 找不到介质”,则返回VMware的配置中,勾选“已连接”
3.df -h查看是否挂载成功
4.创建本地repo文件
删除该目录下所有repo文件(或备份)
cd /etc/yum.repos.d/
//CentOS
vi CentOS-Base.repo
[cattsoft@localhost ~]$ more /etc/yum.repos.d/CentOS-Base.repo
[base]
name=Base
enabled=1
baseurl=file:///mnt/cdrom
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
//RedHat
[root@redhat-centos6 yum.repos.d]# more rhel-source.repo
[rhel-source]
name=Base
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/epm-gpg/RPM-GPG-KEY-redhat-release
# 执行命令
yum clean all
yum makecache
yum repolist
执行结果无报错即可