欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > 2分钟学会使用createrepo制作本地yum仓库

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

2024/10/24 20:17:39 来源:https://blog.csdn.net/huaz_md/article/details/141683657  浏览:    关键词:2分钟学会使用createrepo制作本地yum仓库

华子目录

  • `createrepo`介绍
  • 实验主题
  • 实验前提
  • 实验前的准备
    • 1.`server端`配置`yum网络源`(这里以`阿里云`为主)
    • 2.`server端`配置`本地yum源`(需要挂载本地镜像)
    • 3.关闭`selinux`和`firewalld`
    • 4.安装`createrepo`包
  • `server端`实验步骤
    • 1.只下载,不安装
    • 2.制作本地yum仓库
    • 3.制作安装`docker-ce`的本地`yum源`
    • 4.`server端`测试
    • 5.安装`httpd`
    • 6.制作软连接,指向`/mnt/docker-ce/`
    • 7.开启httpd服务
    • 8.简单测试访问
  • client端实验步骤
    • 1.配置`内网网络yum源`
    • 2.测试
  • 实验最终测试

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 kcontainerd.io                    x86_64            1.7.21-3.1.el9                   docker             43 Mdocker-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 Mdocker-compose-plugin            x86_64            2.29.2-1.el9                     docker             13 MTransaction Summary
=============================================================================================================
Install  6 PackagesTotal 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 kcontainerd.io                     x86_64             1.7.21-3.1.el9                  docker              43 Mdocker-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 Mdocker-compose-plugin             x86_64             2.29.2-1.el9                    docker              13 MTransaction Summary
===============================================================================================================
Install  6 PackagesTotal size: 104 M
Installed size: 407 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing        :                                                                                       1/1Installing       : docker-compose-plugin-2.29.2-1.el9.x86_64                                             1/6Running scriptlet: docker-compose-plugin-2.29.2-1.el9.x86_64                                             1/6Installing       : container-selinux-2:2.138-5.oe2203sp4.noarch                                          2/6Running scriptlet: container-selinux-2:2.138-5.oe2203sp4.noarch                                          2/6Installing       : containerd.io-1.7.21-3.1.el9.x86_64                                                   3/6Running scriptlet: containerd.io-1.7.21-3.1.el9.x86_64                                                   3/6Installing       : docker-buildx-plugin-0.16.2-1.el9.x86_64                                              4/6Running scriptlet: docker-buildx-plugin-0.16.2-1.el9.x86_64                                              4/6Installing       : docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6Running scriptlet: docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6Installing       : docker-ce-3:27.2.0-1.el9.x86_64                                                       6/6Running scriptlet: docker-ce-3:27.2.0-1.el9.x86_64                                                       6/6Verifying        : container-selinux-2:2.138-5.oe2203sp4.noarch                                          1/6Verifying        : containerd.io-1.7.21-3.1.el9.x86_64                                                   2/6Verifying        : docker-buildx-plugin-0.16.2-1.el9.x86_64                                              3/6Verifying        : docker-ce-3:27.2.0-1.el9.x86_64                                                       4/6Verifying        : docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6Verifying        : docker-compose-plugin-2.29.2-1.el9.x86_64                                             6/6Installed:container-selinux-2:2.138-5.oe2203sp4.noarch            containerd.io-1.7.21-3.1.el9.x86_64docker-buildx-plugin-0.16.2-1.el9.x86_64                docker-ce-3:27.2.0-1.el9.x86_64docker-ce-cli-1:27.2.0-1.el9.x86_64                     docker-compose-plugin-2.29.2-1.el9.x86_64Complete!
  • 发现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 kapr-util                          x86_64             1.6.1-14.oe2203sp4               bendi             105 khttpd-filesystem                  noarch             2.4.51-21.oe2203sp4              bendi             6.8 khttpd-tools                       x86_64             2.4.51-21.oe2203sp4              bendi              67 kmariadb-connector-c               x86_64             3.1.13-4.oe2203sp4               bendi             174 kmod_http2                         x86_64             1.15.25-3.oe2203sp4              bendi             122 kopenEuler-logos-httpd             noarch             1.0-9.oe2203sp4                  bendi             6.6 kTransaction Summary
===============================================================================================================
Install  8 PackagesTotal size: 1.9 M
Installed size: 6.2 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionRunning scriptlet: mariadb-connector-c-3.1.13-4.oe2203sp4.x86_64                                         1/1Preparing        :                                                                                       1/1Running scriptlet: apr-1.7.0-6.oe2203sp4.x86_64                                                          1/8Installing       : apr-1.7.0-6.oe2203sp4.x86_64                                                          1/8Running scriptlet: apr-1.7.0-6.oe2203sp4.x86_64                                                          1/8Installing       : openEuler-logos-httpd-1.0-9.oe2203sp4.noarch                                          2/8Installing       : mariadb-connector-c-3.1.13-4.oe2203sp4.x86_64                                         3/8Running scriptlet: apr-util-1.6.1-14.oe2203sp4.x86_64                                                    4/8Installing       : apr-util-1.6.1-14.oe2203sp4.x86_64                                                    4/8Running scriptlet: apr-util-1.6.1-14.oe2203sp4.x86_64                                                    4/8Installing       : httpd-tools-2.4.51-21.oe2203sp4.x86_64                                                5/8Running scriptlet: httpd-filesystem-2.4.51-21.oe2203sp4.noarch                                           6/8Installing       : httpd-filesystem-2.4.51-21.oe2203sp4.noarch                                           6/8Installing       : mod_http2-1.15.25-3.oe2203sp4.x86_64                                                  7/8Installing       : httpd-2.4.51-21.oe2203sp4.x86_64                                                      8/8Running scriptlet: httpd-2.4.51-21.oe2203sp4.x86_64                                                      8/8Verifying        : apr-1.7.0-6.oe2203sp4.x86_64                                                          1/8Verifying        : apr-util-1.6.1-14.oe2203sp4.x86_64                                                    2/8Verifying        : httpd-2.4.51-21.oe2203sp4.x86_64                                                      3/8Verifying        : httpd-filesystem-2.4.51-21.oe2203sp4.noarch                                           4/8Verifying        : httpd-tools-2.4.51-21.oe2203sp4.x86_64                                                5/8Verifying        : mariadb-connector-c-3.1.13-4.oe2203sp4.x86_64                                         6/8Verifying        : mod_http2-1.15.25-3.oe2203sp4.x86_64                                                  7/8Verifying        : openEuler-logos-httpd-1.0-9.oe2203sp4.noarch                                          8/8Installed:apr-1.7.0-6.oe2203sp4.x86_64                       apr-util-1.6.1-14.oe2203sp4.x86_64httpd-2.4.51-21.oe2203sp4.x86_64                   httpd-filesystem-2.4.51-21.oe2203sp4.noarchhttpd-tools-2.4.51-21.oe2203sp4.x86_64             mariadb-connector-c-3.1.13-4.oe2203sp4.x86_64mod_http2-1.15.25-3.oe2203sp4.x86_64               openEuler-logos-httpd-1.0-9.oe2203sp4.noarchComplete!

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 kcontainerd.io                     x86_64             1.7.21-3.1.el9                  docker              43 Mdocker-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 Mdocker-compose-plugin             x86_64             2.29.2-1.el9                    docker              13 MTransaction Summary
===============================================================================================================
Install  6 PackagesTotal 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 transactionPreparing        :                                                                                       1/1Installing       : docker-compose-plugin-2.29.2-1.el9.x86_64                                             1/6Running scriptlet: docker-compose-plugin-2.29.2-1.el9.x86_64                                             1/6Installing       : container-selinux-2:2.138-5.oe2203sp4.noarch                                          2/6Running scriptlet: container-selinux-2:2.138-5.oe2203sp4.noarch                                          2/6Installing       : containerd.io-1.7.21-3.1.el9.x86_64                                                   3/6Running scriptlet: containerd.io-1.7.21-3.1.el9.x86_64                                                   3/6Installing       : docker-buildx-plugin-0.16.2-1.el9.x86_64                                              4/6Running scriptlet: docker-buildx-plugin-0.16.2-1.el9.x86_64                                              4/6Installing       : docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6Running scriptlet: docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6Installing       : docker-ce-3:27.2.0-1.el9.x86_64                                                       6/6Running scriptlet: docker-ce-3:27.2.0-1.el9.x86_64                                                       6/6Verifying        : container-selinux-2:2.138-5.oe2203sp4.noarch                                          1/6Verifying        : containerd.io-1.7.21-3.1.el9.x86_64                                                   2/6Verifying        : docker-buildx-plugin-0.16.2-1.el9.x86_64                                              3/6Verifying        : docker-ce-3:27.2.0-1.el9.x86_64                                                       4/6Verifying        : docker-ce-cli-1:27.2.0-1.el9.x86_64                                                   5/6Verifying        : docker-compose-plugin-2.29.2-1.el9.x86_64                                             6/6Installed:container-selinux-2:2.138-5.oe2203sp4.noarch            containerd.io-1.7.21-3.1.el9.x86_64docker-buildx-plugin-0.16.2-1.el9.x86_64                docker-ce-3:27.2.0-1.el9.x86_64docker-ce-cli-1:27.2.0-1.el9.x86_64                     docker-compose-plugin-2.29.2-1.el9.x86_64Complete!
  • 发现实验成功

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com