使用centos镜像作为yum源

挂载iso镜像至mnt目录

# mount -o loop /root/CentOS-7-x86_64-Everything-2009.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
# ll /mnt/
total 1668
-rw-r--r--. 1 root root 14 Oct 30 05:14 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 Oct 27 00:25 EFI
-rw-rw-r--. 17 root root 227 Aug 30 2017 EULA
-rw-rw-r--. 17 root root 18009 Dec 10 2015 GPL
drwxr-xr-x. 3 root root 2048 Oct 27 00:26 images
drwxr-xr-x. 2 root root 2048 Oct 27 00:25 isolinux
drwxr-xr-x. 2 root root 2048 Oct 27 00:25 LiveOS
drwxr-xr-x. 2 root root 1669120 Oct 29 22:39 Packages
drwxr-xr-x. 2 root root 4096 Oct 30 04:03 repodata
-rw-rw-r--. 17 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 15 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 Nov 2 23:15 TRANS.TBL

备份现有镜像repo源

# mkdir /etc/yum.repos.d/bak -p && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/

创建yum源repo文件

# vim /etc/yum.repos.d/local.repo
[Centos-7.9]
name=local-repo
baseurl=file:///mnt
gpgcheck=0
enabled=1
# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: Centos-7.9

ftp配置yum源

安装ftp

# yum install -y vsftpd

挂载iso镜像至ftp共享目录

# mkdir /var/ftp/centos7.9
# cp -rf /mnt/* /var/ftp/centos7.9/

启动ftp

# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
# systemctl start vsftpd

卸载mnt目录

# umount /mnt

配置yum源repo文件

[Centos-7.9]
name=local-repo
baseurl=ftp://192.168.1.100/centos7.9
gpgcheck=0
enabled=1
gpgkey=ftp://192.168.1.100/centos7.9/RPM-GPG-KEY-CentOS-7

验证yum源

# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Centos-7.9 | 3.6 kB 00:00:00
(1/2): Centos-7.9/group_gz | 153 kB 00:00:00
(2/2): Centos-7.9/primary_db | 6.1 MB 00:00:00
repo id repo name status
Centos-7.9 local-repo 10,072
repolist: 10,072