1、配置网络源(此处使用阿里源为例)
#备份原有yum配置文件
cp /etc/yum.repo.d
mkdir back
cp CentOS* pe* back
#下载阿里云的镜像到/etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2、创建文件夹,挂载本地光盘,拷贝rpm包到/mnt/yum
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
cp /mnt/cdrom/Packages/* /mnt/yum
3、创建yum仓库
createrepo -v /mnt/yum
4、编辑/etc/yum.repo.d/CentOS-Base.repo文件设置本地源
#在网络源前面添加
[base-local]
name=Centos
baseurl=file:///mnt/yum
enable=1
gpgckeck=0
5、使用yum repolist 查看仓库
yum repolist
已加载插件:fastestmirror, langpacks
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,097
base-local Centos 4,021
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 307
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1,010
repolist: 15,435