Centos7配置本地yum源-实测

下载一个镜像:CentOS-7-x86_64-DVD-1804.iso 与系统安装的版本号差距不大应该没问题。
1.创建存储目录(随意),镜像文件上传到服务器上:

2.挂载ISO镜像:
/mnt/cdrom/这个目录在centos上应该默认有的,没有手动创建。

1
mount /media/CentOS-7-x86_64-DVD-1804.iso /mnt/cdrom/

3.备份原yum源配置

1
2
mv /etc/yum.repos.d /etc/yum.repos.d.bak #我是删掉的,保存到了本地。
mkdir /etc/yum.repos.d

4.创建本地yum源配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
vi /etc/yum.repos.d/CentOS-local.repo

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base_local]
name=CentOS-local
baseurl=file:///mnt/cdrom/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

5.更新yum配置

1
2
yum clean all
yum makecache

成功如图,失败检查配置

6.测试命令

1
yum install -y unzip zip

查看是否挂载成功:df -h
可以看到有挂载目录。
7.还原操作
把第3步备份的yum源还原。
卸载镜像(可选):umount /mnt/cdrom/

问题:重启后挂载点会消失.

ˆ Back To Top