• Linux 搭建本地镜像源(CentOS 离线 yum)


    使用 RPM 包搭建本地镜像源

    1. 下载所有源中的 RPM 包

    yum -y install httpd yum-utils createrepo 
    
    • 1

    创建 RPM 包的下载目录

    mkdir /var/www/html/centos
    
    • 1

    启动 httpd 服务

    [root@localhost ~]# systemctl start httpd
    [root@localhost ~]# ss -antulp | grep :80
    tcp   LISTEN 0      511                *:80               *:*    users:(("httpd",pid=10418,fd=4),("httpd",pid=10417,fd=4),("httpd",pid=10416,fd=4),("httpd",pid=10414,fd=4))
    
    • 1
    • 2
    • 3

    在这里插入图片描述
    查看当前 yum

    [root@localhost ~]# yum repolist
    repo id                                           repo name
    appstream                                         CentOS Stream 9 - AppStream
    baseos                                            CentOS Stream 9 - BaseOS
    extras-common                                     CentOS Stream 9 - Extras packages
    
    • 1
    • 2
    • 3
    • 4
    • 5

    可以看到当前一共有三个源仓库,分别为 appstreambaseosextras-common。下面分别将这些仓库中的 RPM 包下载下来。

    将当前源中所有的软件包下载到创建好的目录

    [root@localhost ~]# reposync --repo appstream -p /var/www/html/centos/
    
    • 1

    之后用同样的命令,将所有的软件源的 RPM 包都下载好。
    在这里插入图片描述
    [注]:下载数量很多需内心等待。

    [root@localhost ~]# reposync --repo baseos -p /var/www/html/centos/
    
    • 1
    [root@localhost ~]# reposync --repo extras-common -p /var/www/html/centos/
    
    • 1

    2. 为 yum 源生成 repodata 索引依赖

    查看下载好的所有源的 RPM 包。

    [root@localhost ~]# ll /var/www/html/centos/
    total 0
    drwxr-xr-x. 3 root root 22 Nov 23 16:02 appstream
    drwxr-xr-x. 3 root root 22 Nov 24 09:21 baseos
    drwxr-xr-x. 3 root root 22 Nov 24 09:49 extras-common
    
    • 1
    • 2
    • 3
    • 4
    • 5

    进入下载的目录

    [root@localhost ~]# cd /var/www/html/centos/
    
    • 1

    分别为所有仓库生成 repodata 索引。
    生成 appstream 仓库的 repodata 索引依赖。

    [root@localhost centos]# createrepo appstream/
    Directory walk started
    Directory walk done - 13373 packages
    Temporary output repo path: appstream/.repodata/
    Preparing sqlite DBs
    Pool started (with 5 workers)
    Pool finished
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    生成 baseos 仓库的 repodata 索引依赖。

    [root@localhost centos]# createrepo baseos/
    Directory walk started
    Directory walk done - 3848 packages
    Temporary output repo path: baseos/.repodata/
    Preparing sqlite DBs
    Pool started (with 5 workers)
    Pool finished
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    生成 extras-common 仓库的 repodata 索引依赖。

    [root@localhost centos]# createrepo extras-common/
    Directory walk started
    Directory walk done - 38 packages
    Temporary output repo path: extras-common/.repodata/
    Preparing sqlite DBs
    Pool started (with 5 workers)
    Pool finished
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    成功后即可在仓库目录中看到生成好的 repodata:

    [root@localhost centos]# ls appstream/
    Packages  repodata
    [root@localhost centos]# ls baseos/
    Packages  repodata
    [root@localhost centos]# ls extras-common/
    Packages  repodata
    [root@localhost centos]# ll appstream/repodata/
    total 41540
    -rw-r--r--. 1 root root 12051562 Nov 24 09:59 19be5e75d0fe8a9d2f1a32b2994cf8e1c2437860f66cb1f64519ac3dfe68ca19-filelists.sqlite.bz2
    -rw-r--r--. 1 root root  7073863 Nov 24 09:59 32dc077706f3317759e93ab06c6c8c59a4fb48d62f5277ba746436f02446c902-primary.sqlite.bz2
    -rw-r--r--. 1 root root  4038253 Nov 24 09:59 3a15770cdd1ff2a49c78568050569ca8b55c93d1b46917c89694d5e575fc80cb-other.sqlite.bz2
    -rw-r--r--. 1 root root  3245284 Nov 24 09:59 b339d402b66a76c904679c448fa600cbbec0b316bbe1ee7405610000555c598a-other.xml.gz
    -rw-r--r--. 1 root root  2758017 Nov 24 09:59 c2f8de3be4e63df01b0d4feda3976eb3a976c90b6315b4e71161f0529f62d720-primary.xml.gz
    -rw-r--r--. 1 root root 13349045 Nov 24 09:59 d97fb51cba16b5a2029174c1b83bed4f3c08758bef1a3435d1925739dc623c76-filelists.xml.gz
    -rw-r--r--. 1 root root     3117 Nov 24 09:59 repomd.xml
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    3. 备份 yum 配置文件,并配置新 yum 源

    进入 yum 源配置文件目录,并备份之前的配置文件:

    [root@localhost ~]# cd /etc/yum.repos.d
    [root@localhost yum.repos.d]# ls
    centos-addons.repo  centos.repo
    [root@localhost yum.repos.d]# mkdir bk
    [root@localhost yum.repos.d]# mv centos* bk
    [root@localhost yum.repos.d]# ls bk
    centos-addons.repo  centos.repo
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    创建新的配置文件并添加源:

    [root@localhost yum.repos.d]# vim im.repo
    
    • 1

    添加如下内容:

    [appstream]		
    name=appstream			# 根据自己的仓库名命名
    baseurl=http://10.1.1.99/centos/appstream
    gpgcheck=0
    enabled=1
    [baseos]
    name=baseos
    baseurl=http://10.1.1.99/centos/baseos
    gpgcheck=0
    enabled=1
    [extras-common]
    name=extras-common
    baseurl=http://10.1.1.99/centos/extras-common
    gpgcheck=0
    enabled=1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    4. 验证

    清理当前 yum

    [root@localhost ~]# yum clean all
    15 files removed
    
    • 1
    • 2

    建立 yum 缓存

    [root@localhost ~]# yum makecache
    appstream                                                                               196 MB/s |  15 MB     00:00
    baseos                                                                                  246 MB/s | 5.9 MB     00:00
    extras-common                                                                           3.8 MB/s | 8.7 kB     00:00
    Metadata cache created.
    
    • 1
    • 2
    • 3
    • 4
    • 5

    查看当前 yum 仓库

    [root@localhost ~]# yum repolist
    repo id                                                     repo name
    appstream                                                   appstream
    baseos                                                      baseos
    extras-common                                               extras-common
    
    • 1
    • 2
    • 3
    • 4
    • 5

    更新 yum

    [root@localhost ~]# yum update
    
    • 1

    使用本地源下载软件

    [root@localhost ~]# yum install -y tree
    Last metadata expiration check: 0:03:44 ago on Thu 24 Nov 2022 10:47:10 AM CST.
    Dependencies resolved.
    ========================================================================================================================
     Package                  Architecture               Version                           Repository                  Size
    ========================================================================================================================
    Installing:
     tree                     x86_64                     1.8.0-10.el9                      baseos                      56 k
    
    Transaction Summary
    ========================================================================================================================
    Install  1 Package
    
    Total download size: 56 k
    Installed size: 113 k
    Downloading Packages:
    tree-1.8.0-10.el9.x86_64.rpm                                                             24 MB/s |  56 kB     00:00
    ------------------------------------------------------------------------------------------------------------------------
    Total                                                                                   5.4 MB/s |  56 kB     00:00
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
      Preparing        :                                                                                                1/1
      Installing       : tree-1.8.0-10.el9.x86_64                                                                       1/1
      Running scriptlet: tree-1.8.0-10.el9.x86_64                                                                       1/1
      Verifying        : tree-1.8.0-10.el9.x86_64                                                                       1/1
    
    Installed:
      tree-1.8.0-10.el9.x86_64
    
    Complete!
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    下载成功!

    完成

  • 相关阅读:
    worthington酶丨worthington酶的特异性和分类
    伦敦金的交易时间究竟多长?
    FPGA USB host原型验证流程及调试手段
    深入浅出对话系统——任务型对话系统技术框架
    IOS安全测试学习-DVIA-v2
    283. 多边形,《算法竞赛进阶指南》,
    深入了解网络流量清洗--使用免费的雷池社区版进行防护
    Leetcode33. Search in Rotated Sorted Array | Binary Search
    Spring Security认证流程分
    “第四十八天” 计算机组成原理
  • 原文地址:https://blog.csdn.net/qq_36393978/article/details/128001922