1、查看已将安装的操作系统版本

[root@min-base ~]#cat /etc/redhat-release

CentOS Linuxrelease 7.2.1511 (Core)

2、下载并挂在iso镜像

接下来就是将iso的光盘镜像进行挂载了

  mount-t iso9660 -o loop CentOS-7-x86_64-DVD-1503-01.iso /mnt

  (如果是挂载插入的光盘,只需要输入命令mount/dev/cdrom /mnt/,其余的操作是相同的)

挂载CentOS-7-x86_64-Everything-1511.iso,把里面所有文件都拷贝到本地目录/yum/yum-iso

[root@min-base ~]#mkdir /mnt/yum-iso

[root@min-base ~]#mount –o loop xx.iso /mnt/yum-iso/

mount: /dev/sr0 is write-protected,mounting read-only

[root@min-base ~]#mkdir /yum/

[root@min-base ~]#cp -a /mnt/yum-iso/ /yum/

[root@min-base ~]#ll /yum/

total 4

dr-xr-xr-x. 8 root root 4096 Dec 10  2015 yum-iso

[root@min-base ~]#ll /yum/yum-iso/

total 640

-r--r--r--. 1 root root     14 Dec 10  2015 CentOS_BuildTag

dr-xr-xr-x. 3 root root     33 Dec 10  2015 EFI

-r--r--r--. 1 root root    215 Dec 10  2015 EULA

-r--r--r--. 1 root root  18009 Dec 10  2015 GPL

dr-xr-xr-x. 3 root root     69 Dec 10  2015 images

dr-xr-xr-x. 2 root root   4096 Dec 10  2015 isolinux

dr-xr-xr-x. 2 root root     41 Dec 10  2015 LiveOS

dr-xr-xr-x. 2 root root 483328 Dec 10  2015 Packages

dr-xr-xr-x. 2 root root   4096 Dec 10  2015 repodata

-r--r--r--. 1 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-7

-r--r--r--. 1 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-Testing-7

-r--r--r--. 1 root root   2883 Dec 10  2015 TRANS.TBL

[root@min-base ~]#

 

3、备份、移除其他repo

[root@min-base ~]#cd /etc/yum.repos.d/

[root@min-base yum.repos.d]# ll

-rw-r--r--. 1 root root 1664 Dec  9  2015CentOS-Base.repo

-rw-r--r--. 1 root root 1309 Dec  9  2015CentOS-CR.repo

-rw-r--r--. 1 root root  649Dec  9  2015CentOS-Debuginfo.repo

-rw-r--r--. 1 root root  290Dec  9  2015 CentOS-fasttrack.repo

-rw-r--r--. 1 root root  630Dec  9  2015 CentOS-Media.repo

-rw-r--r--. 1 root root 1331 Dec  9  2015CentOS-Sources.repo

-rw-r--r--. 1 root root 1952 Dec  9  2015CentOS-Vault.repo

[root@min-base yum.repos.d]# tar zcvf repo-bk.tar.gz CentOS-*

CentOS-Base.repo

CentOS-CR.repo

CentOS-Debuginfo.repo

CentOS-fasttrack.repo

CentOS-Media.repo

CentOS-Sources.repo

CentOS-Vault.repo

[root@min-base yum.repos.d]# rm -f CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-Vault.repo 

4 、配置本地repo

[root@min-base yum.repos.d]# vi CentOS-Media.repo

填入如下内容

[c7-media]

name=CentOS-$releasever- Media

baseurl=file:///yum/yum-iso/

gpgcheck=0

enabled=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

注释:配置repo路径、关闭gbp校验、启用这个repo

 

5、制作cache

[root@min-base yum.repos.d]# yum clean all

Loaded plugins:fastestmirror

Cleaning repos:c7-media

Cleaning upeverything

Cleaning up listof fastest mirrors

[root@min-base yum.repos.d]# yum makecache

Loaded plugins:fastestmirror

c7-media                                                                                                        | 3.6 kB  00:00:00    

(1/4): c7-media/group_gz                                                                                        | 155 kB  00:00:00    

(2/4): c7-media/primary_db                                                                                      | 5.3 MB  00:00:00    

(3/4): c7-media/filelists_db                                                                                    | 6.2 MB  00:00:00    

(4/4): c7-media/other_db                                                                                        | 2.3 MB  00:00:00    

Determiningfastest mirrors

Metadata CacheCreated

[root@min-base yum.repos.d]#  

 

这样就可以使用yum安装软件啦!