***此处以更改为aliyun为例
2.1.1 首先在网络上找到aliyun镜像提供网站
#yum源网址
https://mirrors.aliyun.com/centos/7/os/x86_64/
#gpg key路径
https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
2.1.2 创建文件
[root@Centos7 ~]#cd /etc/yum.repos.d/
[root@Centos7 yum.repos.d]#mkdir back
[root@Centos7 yum.repos.d]#mv *.repo back
#确保该文件夹下无repo后缀文件存在,可以通过yum repolist查看
[root@Centos7 yum.repos.d]#yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repolist: 0
[root@Centos7 yum.repos.d]#vim aliyun.repo
#在文件中输入下列内容
[aliyum]
name=aliyum
baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
#执行命令查看是否正常启用
[root@Centos7 yum.repos.d]#yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
aliyun aliyum 10,097
repolist: 10,097
2.2.1 首先在网络上找到aliyun镜像提供网站
#Base yum源路径
https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
#AppStream yum源路径
https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/
2.2.2创建文件
[root@Centos8 ~]#cd /etc/yum.repos.d/
[root@Centos8 yum.repos.d]#mkdir back
[root@Centos8 yum.repos.d]#mv *.repo back
#确保该文件夹下无repo后缀文件存在,可以通过dnf repolist查看
[root@Centos8 yum.repos.d]#dnf repolist
No repositories available
[root@Centos8 yum.repos.d]#vim aliyun.repo
#在文件中输入下列内容
[Base]
name=aliyun base
baseurl=https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
gpgcheck=0
[AppStream]
name=aliyun AppStream
baseurl=https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/
gpgcheck=0
#执行命令查看是否正常启用
[root@Centos8 yum.repos.d]#dnf repolist
Last metadata expiration check: 0:00:21 ago on Sun 29 Dec 2019 02:29:27 PM CST.
repo id repo name status
AppStream aliyun AppStream 5,089
Base aliyun base 2,843
3.1.1 加载本地的磁盘镜像(以centos 7为例)
cd /misc/cd
命令打开磁盘镜像挂载点[root@Centos7 ~]#cd /misc/cd
-bash: cd: /misc/cd: No such file or directory
[root@Centos7 ~]#yum install -y autofs
[root@Centos7 ~]#systemctl start autofs
[root@Centos7 ~]#cd /misc/cd
#查看路径下是否有repodata文件
[root@Centos7 ~]#ls
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
#本地yum源
file:///misc/cd/
#本地gpg key路径
file:///misc/cd/RPM-GPG-KEY-CentOS-7
3.1.2 创建文件
[root@Centos7 ~]#cd /etc/yum.repos.d/
[root@Centos7 yum.repos.d]#mkdir back
[root@Centos7 yum.repos.d]#mv *.repo back
#确保该文件夹下无repo后缀文件存在,可以通过yum repolist查看
[root@Centos7 yum.repos.d]#yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repolist: 0
[root@Centos7 yum.repos.d]#vim local.repo
#在文件中输入下列内容
[local]
name=local
baseurl=file:///misc/cd/
gpgcheck=1
gpgkey=file:///misc/cd/RPM-GPG-KEY-CentOS-7
#执行命令查看是否正常启用
[root@Centos7 yum.repos.d]#yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
local local 10,097
repolist: 10,097
3.2.1 加载本地的磁盘镜像
cd /misc/cd
命令打开磁盘镜像挂载点[root@Centos8 ~]#cd /misc/cd
-bash: cd: /misc/cd: No such file or directory
[root@Centos8 ~]#yum install -y autofs
[root@Centos8 ~]#systemctl start autofs
[root@Centos8 ~]#cd /misc/cd
#分别打开AppStream与BoseOS文件夹查看是否有repodata文件
#本地Base yum源路径
file:///musc.cd/BoseOS/
#本地AppStream yum源路径
file:///misc/cd/AppStream/
3.2.2创建文件
[root@Centos8 ~]#cd /etc/yum.repos.d/
[root@Centos8 yum.repos.d]#mkdir back
[root@Centos8 yum.repos.d]#mv *.repo back
#确保该文件夹下无repo后缀文件存在,可以通过dnf repolist查看
[root@Centos8 yum.repos.d]#dnf repolist
No repositories available
[root@Centos8 yum.repos.d]#vim local.repo
#在文件中输入下列内容
[base]
name=local base
baseurl=file:///misc/cd/BaseOS/
gpgcheck=0
[AppStream]
name=loacl appstream
baseurl=file:///misc/cd/AppStream/
gpgcheck=0
#执行命令查看是否正常启用
[root@Centos8 yum.repos.d]#dnf repolist
Last metadata expiration check: 0:00:06 ago on Sun 29 Dec 2019 03:18:25 PM CST.
repo id repo name status
AppStream loacl appstream 4,681
base local base 1,655