1 安装createrepo程序包
[root@docker ~]# yum install -y createrepo
2 创建相关目录
[root@docker ~]# mkdir /yum/repo -p
3 上传rpm包文件到repo目录
[root@docker ~]# ls /yum/repo/
cpp-4.8.5-39.el7.x86_64.rpm
gcc-4.8.5-39.el7.x86_64.rpm
gcc-c++-4.8.5-39.el7.x86_64.rpm
gcc-gfortran-4.8.5-39.el7.x86_64.rpm
httpd-2.4.6-93.el7.centos.x86_64.rpm
httpd-tools-2.4.6-93.el7.centos.x86_64.rpm
libgcc-4.8.5-39.el7.x86_64.rpm
libgfortran-4.8.5-39.el7.x86_64.rpm
libgomp-4.8.5-39.el7.x86_64.rpm
libquadmath-4.8.5-39.el7.x86_64.rpm
libquadmath-devel-4.8.5-39.el7.x86_64.rpm
libstdc++-4.8.5-39.el7.x86_64.rpm
libstdc++-devel-4.8.5-39.el7.x86_64.rpm
libzip-0.10.1-8.el7.x86_64.rpm
mailcap-2.1.41-2.el7.noarch.rpm
php-5.4.16-48.el7.x86_64.rpm
php-cli-5.4.16-48.el7.x86_64.rpm
php-common-5.4.16-48.el7.x86_64.rpm
4 创建yum源
[root@docker ~]# cd /yum/repo/
[root@docker repo]# createrepo ./
Spawning worker 0 with 18 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
生成repodata文件夹
[root@docker repodata]# pwd
/yum/repo/repodata
[root@docker repodata]# ls
411324d5e65fa200cd7818637142c4cb3b4fae4790bd707b7184d41d9caa36f9-other.sqlite.bz2
480015a10a4fb7f5a1abf2afccaa1f69ba30c6d681194898b966fdb53bb1f890-filelists.sqlite.bz2
5d22333debc4cb8645c4578b8339c93ae07ed5f07e911b4bf608a3b680839913-other.xml.gz
c1595ece21be832e8ba65c637e26a3f0061f27d048a7d3efad819da61989ab3f-primary.xml.gz
d2cb1f7d673a6c6e0b0e6774693d38ef545cda87d98f646e81389de1f433d8de-primary.sqlite.bz2
edd84585bac34bd1d7e0c5e00206ae8e896eade2840bae3a031cfbc89cfef4b6-filelists.xml.gz
repomd.xml
5 创建yum客户端配置文件(本机演示)
[root@docker ~]# cd /etc/yum.repos.d/
[root@docker yum.repos.d]# vim local-repo.repo
[local-repo]
name = local repo for test
baseurl = file:///yum/repo/
enabled = 1
gpgcheck =0
6 显示仓库列表
[root@docker ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,070
docker-ce-stable/x86_64 Docker CE Stable - x86_64 79
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 397
local-repo local repo for test 18
local-yum local yum for test 3,894
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 884
repolist: 15,342
7 测试yum源是否可用
[root@docker yum.repos.d]# yum install gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-39.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================
Installing:
gcc x86_64 4.8.5-39.el7 local-repo 16 M
Transaction Summary
======================================================================================================================================================
Install 1 Package
Total download size: 16 M
Installed size: 37 M
Is this ok [y/d/N]: