1.下载ISO镜像文件
CentOS-7-x86_64-DVD-2009.iso下载
2.上传刚刚我们下载的ISO镜像文件到服务器上
[root@localhost ~]# ll -h total 5.1G -rw-r--r-- 1 root root 4.3G May 8 15:53 CentOS-7-x86_64-DVD-1708.iso drwxr-xr-x. 3 root root 17 Apr 6 02:27 KSF -rw-------. 1 root root 2.1K Dec 27 03:35 anaconda-ks.cfg -rw-r--r-- 1 root root 827M Apr 27 08:17 zk3.4.10_kafka_2.11-1.0.1_ngapmstat1.0.tar.gz
3.创建ISO镜像文件挂载目录并挂载
[root@localhost ~]# mkdir /mnt/centos7 [root@localhost ~]# mount -o loop CentOS-7-x86_64-DVD-1708.iso /mnt/centos7/ mount: /dev/loop0 is write-protected, mounting read-only [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 252G 0 252G 0% /dev tmpfs 252G 320K 252G 1% /dev/shm tmpfs 252G 21M 252G 1% /run tmpfs 252G 0 252G 0% /sys/fs/cgroup /dev/mapper/centos-root 274G 15G 259G 6% / /dev/sdm1 1014M 151M 864M 15% /boot tmpfs 51G 0 51G 0% /run/user/0 /dev/loop0 4.3G 4.3G 0 100% /mnt/centos7
4.备份原YUM源文件,并创建备份目录
[root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# mkdir repo.bak [root@localhost yum.repos.d]# mv CentOS-* repo.bak/ [root@localhost yum.repos.d]# ll repo.bak/ total 40 -rw-r--r--. 1 root root 1664 Oct 23 2020 CentOS-Base.repo -rw-r--r--. 1 root root 1309 Oct 23 2020 CentOS-CR.repo -rw-r--r--. 1 root root 649 Oct 23 2020 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 630 Oct 23 2020 CentOS-Media.repo -rw-r--r--. 1 root root 1331 Oct 23 2020 CentOS-Sources.repo -rw-r--r--. 1 root root 8515 Oct 23 2020 CentOS-Vault.repo -rw-r--r--. 1 root root 314 Oct 23 2020 CentOS-fasttrack.repo -rw-r--r--. 1 root root 616 Oct 23 2020 CentOS-x86_64-kernel.repo
5.创建新挂载的ISO镜像源YUM文件
[root@localhost yum.repos.d]# cat > centos7.repo << EOF > [centos7-local] > name=Centos7 #YUM源名称,自定义 > baseurl=file:///mnt/centos7/ #本地镜像文件路径 > enabled=1 #1表示启动YUM源,0为禁用 > gpgcheck=0 #1为检查GPG-KEY,0为不检查 > EOF [root@localhost yum.repos.d]# cat centos7.repo [centos7-local] name=Centos7 baseurl=file:///mnt/centos7/ enabled=1 gpgcheck=0
6.清除YUM缓存并测试安装
[root@localhost yum.repos.d]# yum clean all Loaded plugins: fastestmirror Cleaning repos: centos7-local Cleaning up list of fastest mirrors [root@localhost yum.repos.d]# yum makecache #缓存YUM源信息 Loaded plugins: fastestmirror Determining fastest mirrors centos7-local | 3.6 kB 00:00:00 (1/4): centos7-local/group_gz | 156 kB 00:00:00 (2/4): centos7-local/filelists_db | 3.1 MB 00:00:00 (3/4): centos7-local/primary_db | 3.1 MB 00:00:00 (4/4): centos7-local/other_db | 1.2 MB 00:00:00 Metadata Cache Created [root@localhost yum.repos.d]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status centos7-local Centos7 3894 repolist: 3894 [root@localhost yum.repos.d]# yum install net-tools [root@localhost yum.repos.d]# yum search jdk #也可搜素