0%

CentOS7搭建本地yum源

加载光盘iso

首先在VMware里面,把CentOS-7-x86_64-Everything-1908.iso镜像文件加载到CD/DVD设备中。

加载成功后,查看状态:

1
2
ll /dev/cdrom 
lrwxrwxrwx. 1 root root 3 Jan 7 09:54 /dev/cdrom -> sr0

创建挂载目录

此目录用于显示光盘内容

1
mkdir /mnt/cdrom

挂载

查看挂载类型

1
2
3
4
5
6
7
8
cat /proc/filesystems
nodev sysfs
nodev rootfs
nodev ramfs
...
nodev selinuxfs
xfs
iso9660

我们看到类型有iso9660

1
mount -t iso9660 -o ro /dev/cdrom /mnt/cdrom

把参数-t省略也是可以的,即:

1
mount /dev/cdrom /mnt/cdrom/

系统会提示按只读方式挂载。

查看挂载状态:

1
2
3
4
5
df -h
Filesystem Size Used Avail Use% Mounted on
...
/dev/sr0 11G 11G 0 100% /mnt/cdrom
...

添加yum配置文件

备份CentOS-Base.repo文件

1
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

创建文件/etc/yum.repos.d/CentOS-Base-Local.repo

内容如下:

1
2
3
4
5
6
[base-local]
name=CentOS-$releasever - Base-Local
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

清理yum缓存

1
yum clean all

查看本地yum源是否生效

1
2
3
4
5
6
yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
base-local CentOS-7 - Base-Local 10,097
repolist: 10,097

到此,我们就可以通过yum install安装软件了。