2分钟学会使用createrepo制作本地yum仓库

createrepo介绍

  • createrepo 是一个用于创建 RPM 包的工具,它可以帮助你创建一个本地的 YUM 仓库。createrepo 并不是用于运行 YUM 仓库服务的软件,而是用来生成仓库的元数据,使得 YUM 可以理解和使用这个仓库

实验主题

  • 搭建安装docker-ce的本地yum仓库,并安装httpd为其他主机提供内网网络yum源
  • 使用于CentOS7,openEuler等系列的yum仓库

实验前提

  • server端系统之前没有安装过docker-ce软件 ,否则系统中就会存在之前依赖环境,导致通过yum仅下载依赖包不全无法下载所需的全部依赖

实验前的准备

  • 这里我们以openEuler为例,准备两台机子,一台作为服务端,一台作为客户端

在这里插入图片描述

1.server端配置yum网络源(这里以阿里云为主)

[root@yum_server yum.repos.d]# vim wangluo.repo
[docker]
name=docker-ce
baseurl=https://mirrors.aliyun.com/docker-ce/linux/rhel/9/x86_64/stable/
gpgcheck=0

2.server端配置本地yum源(需要挂载本地镜像)

[root@yum_server ~]# mkdir /guangpan
[root@yum_server ~]# mount /dev/cdrom /guangpan/


[root@yum_server ~]# cd /etc/rc.d/
[root@yum_server rc.d]# vim rc.local
[root@yum_server rc.d]# chmod +x rc.local
[root@yum_server ~]# cd /guangpan/
[root@yum_server guangpan]# ls
docs  EFI  images  isolinux  ks  Packages  repodata  RPM-GPG-KEY-openEuler  TRANS.TBL
[root@yum_server yum.repos.d]# vim bendi.repo
[bendi]
name=docker
baseurl=file:///guangpan
gpgcheck=0
[root@yum_server ~]# yum makecache
docker                                                                132 MB/s | 3.4 MB     00:00
docker-ce                                                              14 kB/s | 3.5 kB     00:00
Metadata cache created.

3.关闭selinuxfirewalld

[root@yum_server ~]# getenforce
Disabled
[root@yum_server ~]# systemctl is-active firewalld
inactive

4.安装createrepo

[root@yum_server ~]# yum whatprovides createrepo
Last metadata expiration check: 0:03:54 ago on 2024年08月29日 星期四 17时44分27秒.
createrepo_c-0.17.6-3.oe2203sp4.x86_64 : Creates a common metadata repository
Repo        : bendi
Matched from:
Provide    : createrepo = 0.17.6-3.oe2203sp4
[root@yum_server ~]# yum install createrepo_c-0.17.6-3.oe2203sp4.x86_64 -y


[root@yum_server ~]# createrepo --version
Version: 0.17.6 (Features: DeltaRPM LegacyWeakdeps )

server端实验步骤

1.只下载,不安装

  • yum install docker-ce --downloadonly --downloaddir=/mnt:将有关docker-ce的所有依赖包下载到/mnt下,不安装
[root@yum_server ~]# yum install docker-ce --downloadonly --downloaddir=/mnt
Last metadata expiration check: 0:00:44 ago on 2024年08月29日 星期四 17时59分14秒.
Dependencies resolved.
=============================================================================================================
 Package                          Architecture      Version                          Repository         Size
=============================================================================================================
Installing:
 docker-ce                        x86_64            3:27.2.0-1.el9                   docker             27 M
Installing dependencies:
 container-selinux                noarch            2:2.138-5.oe2203sp4              bendi              33 k
 containerd.io                    x86_64            1.7.21-3.1.el9                   docker             43 M
 docker-ce-cli                    x86_64            1:27.2.0-1.el9                   docker            7.8 M
Installing weak dependencies:
 docker-buildx-plugin             x86_64            0.16.2-1.el9                     docker             14 M
 docker-compose-plugin            x86_64            2.29.2-1.el9                     docker             13 M

Transaction Summary
=============================================================================================================
Install  6 Packages

Total size: 104 M
Total download size: 104 M
Installed size: 407 M
YUM will only download packages for the transaction.
Is this ok [y/N]: y
Downloading Packages:
(1/5): docker-buildx-plugin-0.16.2-1.el9.x86_64.rpm                          2.3 MB/s |  14 MB     00:05
(2/5): docker-ce-cli-27.2.0-1.el9.x86_64.rpm                                 2.3 MB/s | 7.8 MB     00:03
(3/5): docker-ce-27.2.0-1.el9.x86_64.rpm                                     2.3 MB/s |  27 MB     00:11
(4/5): docker-compose-plugin-2.29.2-1.el9.x86_64.rpm                         2.2 MB/s |  13 MB     00:06
(5/5): containerd.io-1.7.21-3.1.el9.x86_64.rpm                               2.3 MB/s |  43 MB     00:18
-------------------------------------------------------------------------------------------------------------
Total                                                                        5.6 MB/s | 104 MB     00:18
Complete!
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
  • 查看,发现全是与docker-ce有关的rpm
[root@yum_server ~]# cd /mnt/
[root@yum_server mnt]# ls
containerd.io-1.7.21-3.1.el9.x86_64.rpm         docker-ce-27.2.0-1.el9.x86_64.rpm
container-selinux-2.138-5.oe2203sp4.noarch.rpm  docker-ce-cli-27.2.0-1.el9.x86_64.rpm
docker-buildx-plugin-0.16.2-1.el9.x86_64.rpm    docker-compose-plugin-2.29.2-1.el9.x86_64.rpm

2.制作本地yum仓库

[root@yum_server mnt]# mkdir docker-ce
[root@yum_server mnt]# ls
containerd.io-1.7.21-3.1.el9.x86_64.rpm         docker-ce-27.2.0-1.el9.x86_64.rpm
container-selinux-2.138-5.oe2203sp4.noarch.rpm  docker-ce-cli-27.2.0-1.el9.x86_64.rpm
docker-buildx-plugin-0.16.2-1.el9.x86_64.rpm    docker-compose-plugin-2.29.2-1.el9.x86_64.rpm
docker-ce


[root@yum_server mnt]# mv *.rpm docker-ce/

[root@yum_server mnt]# ls
docker-ce

[root@yum_server mnt]# cd docker-ce/

[root@yum_server docker-ce]# ls
containerd.io-1.7.21-3.1.el9.x86_64.rpm         docker-ce-27.2.0-1.el9.x86_64.rpm
container-selinux-2.138-5.oe2203sp4.noarch.rpm  docker-ce-cli-27.2.0-1.el9.x86_64.rpm
docker-buildx-plugin-0.16.2-1.el9.x86_64.rpm    docker-compose-plugin-2.29.2-1.el9.x86_64.rpm
  • 此时此docker-ce目录只是一个存放rpm软件包目录,并不是软件仓库
  • 使用createrepo命令制作软件仓库使用createrepo命令将docker-ce目录变成docker-ce的软件仓库
[root@yum_server ~]# createrepo -v /mnt/docker-ce/
[root@yum_server ~]# cd /mnt/docker-ce/
[root@yum_server docker-ce]# ls
containerd.io-1.7.21-3.1.el9.x86_64.rpm         docker-ce-27.2.0-1.el9.x86_64.rpm              repodata
container-selinux-2.138-5.oe2203sp4.noarch.rpm  docker-ce-cli-27.2.0-1.el9.x86_64.rpm
docker-buildx-plugin-0.16.2-1.el9.x86_64.rpm    docker-compose-plugin-2.29.2-1.el9.x86_64.rpm
[root@yum_server docker-ce]# cd repodata/
[root@yum_server repodata]# ls
03b10e6ebfe6c159910990de370a837e198a3c00ecb2e99ec858b058d795e197-other.sqlite.bz2
2e5f1954f4590e9bde861fdc9f090dbd441104252132aa1ea5056beb3bee56f7-other.xml.gz
4b0b15d284e9883da77dce9fe5b95fe16750d92ba14851326d2a0695dbf3e143-primary.sqlite.bz2
9ee298814d084e84e3db9f2562b06969bdabd5c48d312c8e2e0971ca7309c3b4-primary.xml.gz
e287e62e0abaa26175fba50205f2316a5911e326334b1f260ff748d43535204a-filelists.sqlite.bz2
f5e8473f4966cd091a8df973e251bea5a1addb8aaa892f010b297ccf322258d6-filelists.xml.gz
repomd.xml

3.制作安装docker-ce的本地yum源

  • 先将之前能用的yum源全部备份
[root@yum_server docker-ce]# pwd
/mnt/docker-ce
[root@yum_server docker-ce]# cd /etc/yum.repos.d/
[root@yum_server yum.repos.d]# ls
bendi.repo  openEuler.repo.bak  wangluo.repo
[root@yum_server yum.repos.d]# mv bendi.repo bendi.repo.bak
[root@yum_server yum.repos.d]# mv wangluo.repo wangluo.repo.bak
[root@yum_server yum.repos.d]# ls
bendi.repo.bak  openEuler.repo.bak  wangluo.repo.bak
  • 创建docker-ce.repo文件
[root@yum_server yum.repos.d]# vim docker-ce.repo
[docker]
name=docker-ce
baseurl=file:///mnt/docker-ce
gpgcheck=0
[root@yum_server yum.repos.d]# yum makecache
docker-ce                                                                      2.6 MB/s | 4.7 kB     00:00
Metadata cache created.

4.server端测试

[root@yum_server ~]# yum install docker-ce -y
Last metadata expiration check: 0:03:18 ago on 2024年08月29日 星期四 18时17分16秒.
Dependencies resolved.
===============================================================================================================
 Package                           Architecture       Version                         Repository          Size
===============================================================================================================
Installing:
 docker-ce                         x86_64             3:27.2.0-1.el9                  docker              27 M
Installing dependencies:
 container-selinux                 noarch             2:2.138-5.oe2203sp4             docker              33 k
 containerd.io                     x86_64             1.7.21-3.1.el9                  docker              43 M
 docker-ce-cli                     x86_64             1:27.2.0-1.el9                  docker             7.8 M
Installing weak dependencies:
 docker-buildx-plugin              x86_64             0.16.2-1.el9                    docker              14 M
 docker-compose-plugin             x86_64             2.29.2-1.el9                    docker              13 M

Transaction Summary
===============================================================================================================
Install  6 Packages

Total size: 104 M
Installed size: 407 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                       1/1
  Installing       : docker-compose-plugin-2.29.2-1.el9.x86_64                                             1/6
  Running scriptlet: docker-compose-plugin-2.29.2-1.el9.x86_64                                             1/6
  Installing       : container-selinux-2:2.138-5.oe2203sp4.noarch                                          2/6
  Running scriptlet: container-selinux-2:2.138-5.oe2203sp4.noarch                                          2/6
  Installing       : containerd.io-1.7.21-3.1.el9.x86_64                                                   3/6
  Running scriptlet: containerd.io-1.7.21-3.1.el9.x86_64                                                   3/6
  Installing       : docker-buildx-plugin-0.16.2-1.el9.x86_64                                              4/6
  Running scriptlet: docker-buildx-plugin-0.16.2-1.el9.x86_64                                              4/6
  Installing       : docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6
  Running scriptlet: docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6
  Installing       : docker-ce-3:27.2.0-1.el9.x86_64                                                       6/6
  Running scriptlet: docker-ce-3:27.2.0-1.el9.x86_64                                                       6/6
  Verifying        : container-selinux-2:2.138-5.oe2203sp4.noarch                                          1/6
  Verifying        : containerd.io-1.7.21-3.1.el9.x86_64                                                   2/6
  Verifying        : docker-buildx-plugin-0.16.2-1.el9.x86_64                                              3/6
  Verifying        : docker-ce-3:27.2.0-1.el9.x86_64                                                       4/6
  Verifying        : docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6
  Verifying        : docker-compose-plugin-2.29.2-1.el9.x86_64                                             6/6

Installed:
  container-selinux-2:2.138-5.oe2203sp4.noarch            containerd.io-1.7.21-3.1.el9.x86_64
  docker-buildx-plugin-0.16.2-1.el9.x86_64                docker-ce-3:27.2.0-1.el9.x86_64
  docker-ce-cli-1:27.2.0-1.el9.x86_64                     docker-compose-plugin-2.29.2-1.el9.x86_64

Complete!
  • 发现docker-ce安装成功

5.安装httpd

  • 先打开bendi.repo这个本地yum源
[root@yum_server ~]# cd /etc/yum.repos.d/
[root@yum_server yum.repos.d]# mv bendi.repo.bak bendi.repo
  • 安装httpd
[root@yum_server yum.repos.d]# yum install httpd -y
Last metadata expiration check: 0:06:47 ago on 2024年08月29日 星期四 18时17分16秒.
Dependencies resolved.
===============================================================================================================
 Package                           Architecture       Version                          Repository         Size
===============================================================================================================
Installing:
 httpd                             x86_64             2.4.51-21.oe2203sp4              bendi             1.3 M
Installing dependencies:
 apr                               x86_64             1.7.0-6.oe2203sp4                bendi             106 k
 apr-util                          x86_64             1.6.1-14.oe2203sp4               bendi             105 k
 httpd-filesystem                  noarch             2.4.51-21.oe2203sp4              bendi             6.8 k
 httpd-tools                       x86_64             2.4.51-21.oe2203sp4              bendi              67 k
 mariadb-connector-c               x86_64             3.1.13-4.oe2203sp4               bendi             174 k
 mod_http2                         x86_64             1.15.25-3.oe2203sp4              bendi             122 k
 openEuler-logos-httpd             noarch             1.0-9.oe2203sp4                  bendi             6.6 k

Transaction Summary
===============================================================================================================
Install  8 Packages

Total size: 1.9 M
Installed size: 6.2 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Running scriptlet: mariadb-connector-c-3.1.13-4.oe2203sp4.x86_64                                         1/1
  Preparing        :                                                                                       1/1
  Running scriptlet: apr-1.7.0-6.oe2203sp4.x86_64                                                          1/8
  Installing       : apr-1.7.0-6.oe2203sp4.x86_64                                                          1/8
  Running scriptlet: apr-1.7.0-6.oe2203sp4.x86_64                                                          1/8
  Installing       : openEuler-logos-httpd-1.0-9.oe2203sp4.noarch                                          2/8
  Installing       : mariadb-connector-c-3.1.13-4.oe2203sp4.x86_64                                         3/8
  Running scriptlet: apr-util-1.6.1-14.oe2203sp4.x86_64                                                    4/8
  Installing       : apr-util-1.6.1-14.oe2203sp4.x86_64                                                    4/8
  Running scriptlet: apr-util-1.6.1-14.oe2203sp4.x86_64                                                    4/8
  Installing       : httpd-tools-2.4.51-21.oe2203sp4.x86_64                                                5/8
  Running scriptlet: httpd-filesystem-2.4.51-21.oe2203sp4.noarch                                           6/8
  Installing       : httpd-filesystem-2.4.51-21.oe2203sp4.noarch                                           6/8
  Installing       : mod_http2-1.15.25-3.oe2203sp4.x86_64                                                  7/8
  Installing       : httpd-2.4.51-21.oe2203sp4.x86_64                                                      8/8
  Running scriptlet: httpd-2.4.51-21.oe2203sp4.x86_64                                                      8/8
  Verifying        : apr-1.7.0-6.oe2203sp4.x86_64                                                          1/8
  Verifying        : apr-util-1.6.1-14.oe2203sp4.x86_64                                                    2/8
  Verifying        : httpd-2.4.51-21.oe2203sp4.x86_64                                                      3/8
  Verifying        : httpd-filesystem-2.4.51-21.oe2203sp4.noarch                                           4/8
  Verifying        : httpd-tools-2.4.51-21.oe2203sp4.x86_64                                                5/8
  Verifying        : mariadb-connector-c-3.1.13-4.oe2203sp4.x86_64                                         6/8
  Verifying        : mod_http2-1.15.25-3.oe2203sp4.x86_64                                                  7/8
  Verifying        : openEuler-logos-httpd-1.0-9.oe2203sp4.noarch                                          8/8

Installed:
  apr-1.7.0-6.oe2203sp4.x86_64                       apr-util-1.6.1-14.oe2203sp4.x86_64
  httpd-2.4.51-21.oe2203sp4.x86_64                   httpd-filesystem-2.4.51-21.oe2203sp4.noarch
  httpd-tools-2.4.51-21.oe2203sp4.x86_64             mariadb-connector-c-3.1.13-4.oe2203sp4.x86_64
  mod_http2-1.15.25-3.oe2203sp4.x86_64               openEuler-logos-httpd-1.0-9.oe2203sp4.noarch

Complete!

6.制作软连接,指向/mnt/docker-ce/

[root@yum_server ~]# cd /var/www/html/

[root@yum_server html]# ln -s /mnt/docker-ce/ docker

[root@yum_server html]# ls
docker
[root@yum_server html]# ll
总用量 0
lrwxrwxrwx 1 root root 15  829 18:27 docker -> /mnt/docker-ce/

7.开启httpd服务

[root@yum_server html]# systemctl restart httpd

[root@yum_server html]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

8.简单测试访问

  • 访问http://172.25.254.143/docker
    在这里插入图片描述

client端实验步骤

1.配置内网网络yum源

[root@yum_client ~]# cd /etc/yum.repos.d/
[root@yum_client yum.repos.d]# ls
openEuler.repo.bak
[root@yum_client yum.repos.d]# vim docker-ce.repo
[docker]
name=docker-ce
baseurl=http://172.25.254.143/docker
gpgcheck=0

2.测试

[root@yum_client ~]# yum makecache
docker-ce                                                                      481 kB/s | 4.7 kB     00:00
Metadata cache created.

实验最终测试

  • yum_client上测试
[root@yum_client ~]# yum install docker-ce -y
Last metadata expiration check: 0:01:50 ago on 2024年08月29日 星期四 18时35分32秒.
Dependencies resolved.
===============================================================================================================
 Package                           Architecture       Version                         Repository          Size
===============================================================================================================
Installing:
 docker-ce                         x86_64             3:27.2.0-1.el9                  docker              27 M
Installing dependencies:
 container-selinux                 noarch             2:2.138-5.oe2203sp4             docker              33 k
 containerd.io                     x86_64             1.7.21-3.1.el9                  docker              43 M
 docker-ce-cli                     x86_64             1:27.2.0-1.el9                  docker             7.8 M
Installing weak dependencies:
 docker-buildx-plugin              x86_64             0.16.2-1.el9                    docker              14 M
 docker-compose-plugin             x86_64             2.29.2-1.el9                    docker              13 M

Transaction Summary
===============================================================================================================
Install  6 Packages

Total download size: 104 M
Installed size: 407 M
Downloading Packages:
(1/6): container-selinux-2.138-5.oe2203sp4.noarch.rpm                          6.4 MB/s |  33 kB     00:00
(2/6): docker-buildx-plugin-0.16.2-1.el9.x86_64.rpm                             56 MB/s |  14 MB     00:00
(3/6): docker-ce-cli-27.2.0-1.el9.x86_64.rpm                                    59 MB/s | 7.8 MB     00:00
(4/6): docker-ce-27.2.0-1.el9.x86_64.rpm                                        54 MB/s |  27 MB     00:00
(5/6): docker-compose-plugin-2.29.2-1.el9.x86_64.rpm                            60 MB/s |  13 MB     00:00
(6/6): containerd.io-1.7.21-3.1.el9.x86_64.rpm                                  61 MB/s |  43 MB     00:00
---------------------------------------------------------------------------------------------------------------
Total                                                                          149 MB/s | 104 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                       1/1
  Installing       : docker-compose-plugin-2.29.2-1.el9.x86_64                                             1/6
  Running scriptlet: docker-compose-plugin-2.29.2-1.el9.x86_64                                             1/6
  Installing       : container-selinux-2:2.138-5.oe2203sp4.noarch                                          2/6
  Running scriptlet: container-selinux-2:2.138-5.oe2203sp4.noarch                                          2/6
  Installing       : containerd.io-1.7.21-3.1.el9.x86_64                                                   3/6
  Running scriptlet: containerd.io-1.7.21-3.1.el9.x86_64                                                   3/6
  Installing       : docker-buildx-plugin-0.16.2-1.el9.x86_64                                              4/6
  Running scriptlet: docker-buildx-plugin-0.16.2-1.el9.x86_64                                              4/6
  Installing       : docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6
  Running scriptlet: docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6
  Installing       : docker-ce-3:27.2.0-1.el9.x86_64                                                       6/6
  Running scriptlet: docker-ce-3:27.2.0-1.el9.x86_64                                                       6/6
  Verifying        : container-selinux-2:2.138-5.oe2203sp4.noarch                                          1/6
  Verifying        : containerd.io-1.7.21-3.1.el9.x86_64                                                   2/6
  Verifying        : docker-buildx-plugin-0.16.2-1.el9.x86_64                                              3/6
  Verifying        : docker-ce-3:27.2.0-1.el9.x86_64                                                       4/6
  Verifying        : docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6
  Verifying        : docker-compose-plugin-2.29.2-1.el9.x86_64                                             6/6

Installed:
  container-selinux-2:2.138-5.oe2203sp4.noarch            containerd.io-1.7.21-3.1.el9.x86_64
  docker-buildx-plugin-0.16.2-1.el9.x86_64                docker-ce-3:27.2.0-1.el9.x86_64
  docker-ce-cli-1:27.2.0-1.el9.x86_64                     docker-compose-plugin-2.29.2-1.el9.x86_64

Complete!
  • 发现实验成功
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

^~^前行者~~~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值