1.挂载系统光盘
1.1创建挂载文件
[root@centos7 ~]# mkdir /mnt/cdrom #创建文件
1.2挂载光驱
[root@centos7 ~]# mount /dev/cdrom /mnt/cdrom/ #挂载光驱
mount: /dev/sr0 is write-protected, mounting read-only #挂载成功
[root@centos7 ~]# ll /mnt/cdrom/ #查看挂载的文件夹
total 1550
-rw-r--r--. 1 root root 14 Dec 5 21:02 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 Dec 5 21:20 EFI
-rw-r--r--. 1 root root 215 Dec 10 2015 EULA
-rw-r--r--. 1 root root 18009 Dec 10 2015 GPL
drwxr-xr-x. 3 root root 2048 Dec 5 21:47 images
drwxr-xr-x. 2 root root 2048 Dec 5 21:20 isolinux
drwxr-xr-x. 2 root root 2048 Dec 5 21:20 LiveOS
drwxrwxr-x. 2 root root 1548288 Dec 5 20:59 Packages
drwxrwxr-x. 2 root root 4096 Dec 5 21:42 repodata
-rw-r--r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-r--r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 Dec 5 21:52 TRANS.TBL
2.修改yum文件
2.1 查看yum目录
[root@centos7 ~]# ll /etc/yum.repos.d/
total 28
-rw-r--r--. 1 root root 1664 Nov 30 02:12 CentOS-Base.repo #网络yum源文件
-rw-r--r--. 1 root root 1309 Nov 30 02:12 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Nov 30 02:12 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Nov 30 02:12 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 656 May 18 10:05 CentOS-Media.repo #本地yum源文件
-rw-r--r--. 1 root root 1331 Nov 30 02:12 CentOS-Sources.repo
-rw-r--r--. 1 root root 2893 Nov 30 02:12 CentOS-Vault.repo
2.2 修改yum源文件
[root@centos7 ~]# nano /etc/yum.repos.d/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/ #yum源目录,源地址
file:///media/cdrom/ #这三个是系统的默认本地yum源的地址
file:///media/cdrecorder/
gpgcheck=1 #检查GPG-KEY,0为不检查,1为检查#
enabled=0 #是否用该yum源,0为禁用,1为使用
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #GPG-KEY秘钥,gpgcheck的值为0时不需要配置
修改后
[c7-media]
baseurl=file:///mnt/cdrom/ #在这里加一行我们刚才光盘挂载的路径
file:///media/CentOS/
file:///mdia/cdrom/
file:///media/cdrecorder/
gpgcheck=1
enabled=1 #把enabled的值改为1,启用这个yum源
2.2 修改网络yum源文件
[root@centos7 ~]# mv /etc/yum.repos.d/CentOS-Base.repo{,.bak} #把这个文件后面加上.bak绕过网络yum源
3.验证本地yum源
3.1清除本地缓存
[root@centos7 ~]# yum clean all
3.2查看本机yum源
[root@centos7 ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
c7-media | 3.6 kB 00:00:00
(1/2): c7-media/group_gz | 155 kB 00:00:00
(2/2): c7-media/primary_db | 5.6 MB 00:00:00
Determining fastest mirrors
* c7-media:
repo id repo name status
c7-media CentOS-7 - Media 9,363 #创建的本地yum源已经识别出来了
repolist: 9,363
3.3查看yum源里的安装包
[root@centos7 ~]# yum list
telnet.x86_64 1:0.17-60.el7 c7-media #这些文件的库名可以看到是本地yum源的库名
telnet-server.x86_64 1:0.17-60.el7 c7-media
testng.noarch 6.8.7-3.el7 c7-media
testng-javadoc.noarch 6.8.7-3.el7 c7-media
tex-fonts-hebrew.noarch 0.1-21.el7 c7-media
tex-preview.noarch 11.87-4.el7 c7-media
texi2html.noarch 1.82-10.el7 c7-media
texinfo.x86_64 5.1-4.el7 c7-media
texinfo-tex.x86_64 5.1-4.el7 c7-media
texlive.x86_64 2:2012-38.20130427_r30134.el7 c7-media
texlive-adjustbox.noarch 2:svn26555.0-38.el7 c7-media
texlive-adjustbox-doc.noarch 2:svn26555.0-38.el7 c7-media
texlive-ae.noarch 2:svn15878.1.4-38.el7 c7-media
texlive-ae-doc.noarch 2:svn15878.1.4-38.el7 c7-media
texlive-algorithms.noarch 2:svn15878.0.1-38.el7 c7-media