createrepo 创建本地 yum 源

安装 createrepo

yum install -y yum-utils createrepo

配置华为源信息

[base]
name=CentOS-$releasever - Base - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos/$releasever/os/$basearch/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos/$releasever/updates/$basearch/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos/$releasever/extras/$basearch/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7

同步源数据到本地

创建数据目录

mkdir -pv /repo/centos/7/os/x86_64

同步源信息

reposync -n --repoid=base --repoid=updates --repoid=extras --repoid=centosplus -p /repo/centos/7/os/x86_64

查看数据目录

# tree -d /repo/centos/7/os/x86_64
/repo/centos/7/os/x86_64
├── base
│   └── Packages
├── centosplus
│   └── Packages
├── extras
│   └── Packages
└── updates
    └── Packages

8 directories

创建 yum 源

base

# createrepo /repo/centos/7/os/x86_64/base
Spawning worker 0 with 5036 pkgs
Spawning worker 1 with 5036 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

updates

# createrepo /repo/centos/7/os/x86_64/updates
Spawning worker 0 with 883 pkgs
Spawning worker 1 with 883 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

extras

# createrepo /repo/centos/7/os/x86_64/extras/
Spawning worker 0 with 139 pkgs
Spawning worker 1 with 139 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

centosplus

# createrepo /repo/centos/7/os/x86_64/centosplus/
Spawning worker 0 with 8 pkgs
Spawning worker 1 with 7 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

nginx 配置

server {
    listen       5000;
    server_name  localhost;

    location / {
        autoindex on;
        root   /repo;
    }
}

访问本地 yum 源

 

本地 yum 源验证

local.repo

[local-base]
name=CentOS-$releasever - Base - mirrors.huaweicloud.com
baseurl=http://192.168.174.107:5000/centos/$releasever/os/$basearch/base/
gpgcheck=0

[local-updates]
name=CentOS-$releasever - Updates - mirrors.huaweicloud.com
baseurl=http://192.168.174.107:5000/centos/$releasever/os/$basearch/updates/
gpgcheck=0

[local-extras]
name=CentOS-$releasever - Extras - mirrors.huaweicloud.com
baseurl=http://192.168.174.107:5000/centos/$releasever/os/$basearch/extras/
gpgcheck=1

[local-centosplus]
name=CentOS-$releasever - Plus - mirrors.huaweicloud.com
baseurl=https://192.168.174.107:5000/centos/$releasever/os/$basearch/centosplus/
gpgcheck=0
enabled=0

构建 yum 缓存 

# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
local-base                                                                                                                                                                                | 2.9 kB  00:00:00     
local-extras                                                                                                                                                                              | 2.9 kB  00:00:00     
local-updates                                                                                                                                                                             | 2.9 kB  00:00:00     
(1/9): local-base/7/x86_64/filelists_db                                                                                                                                                   | 7.2 MB  00:00:00     
(2/9): local-base/7/x86_64/other_db                                                                                                                                                       | 2.6 MB  00:00:00     
(3/9): local-base/7/x86_64/primary_db                                                                                                                                                     | 6.1 MB  00:00:00     
(4/9): local-extras/7/x86_64/filelists_db                                                                                                                                                 | 190 kB  00:00:00     
(5/9): local-extras/7/x86_64/other_db                                                                                                                                                     |  94 kB  00:00:00     
(6/9): local-extras/7/x86_64/primary_db                                                                                                                                                   | 136 kB  00:00:00     
(7/9): local-updates/7/x86_64/primary_db                                                                                                                                                  | 2.1 MB  00:00:00     
(8/9): local-updates/7/x86_64/filelists_db                                                                                                                                                | 2.2 MB  00:00:00     
(9/9): local-updates/7/x86_64/other_db                                                                                                                                                    | 513 kB  00:00:00     
Metadata Cache Created

安装 createrepo

# yum  install createrepo
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package createrepo.noarch 0:0.9.9-28.el7 will be installed
--> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-28.el7.noarch
--> Processing Dependency: deltarpm for package: createrepo-0.9.9-28.el7.noarch
--> Running transaction check
---> Package deltarpm.x86_64 0:3.6-3.el7 will be installed
---> Package python-deltarpm.x86_64 0:3.6-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================================================
 Package                                               Arch                                         Version                                               Repository                                        Size
=================================================================================================================================================================================================================
Installing:
 createrepo                                            noarch                                       0.9.9-28.el7                                          local-base                                        94 k
Installing for dependencies:
 deltarpm                                              x86_64                                       3.6-3.el7                                             local-base                                        82 k
 python-deltarpm                                       x86_64                                       3.6-3.el7                                             local-base                                        31 k

Transaction Summary
=================================================================================================================================================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 207 k
Installed size: 558 k
Is this ok [y/d/N]: y
Downloading packages:
(1/3): createrepo-0.9.9-28.el7.noarch.rpm                                                                                                                                                 |  94 kB  00:00:00     
(2/3): deltarpm-3.6-3.el7.x86_64.rpm                                                                                                                                                      |  82 kB  00:00:00     
(3/3): python-deltarpm-3.6-3.el7.x86_64.rpm                                                                                                                                               |  31 kB  00:00:00     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                            2.6 MB/s | 207 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : deltarpm-3.6-3.el7.x86_64                                                                                                                                                                     1/3 
  Installing : python-deltarpm-3.6-3.el7.x86_64                                                                                                                                                              2/3 
  Installing : createrepo-0.9.9-28.el7.noarch                                                                                                                                                                3/3 
  Verifying  : createrepo-0.9.9-28.el7.noarch                                                                                                                                                                1/3 
  Verifying  : deltarpm-3.6-3.el7.x86_64                                                                                                                                                                     2/3 
  Verifying  : python-deltarpm-3.6-3.el7.x86_64                                                                                                                                                              3/3 

Installed:
  createrepo.noarch 0:0.9.9-28.el7                                                                                                                                                                               

Dependency Installed:
  deltarpm.x86_64 0:3.6-3.el7                                                                         python-deltarpm.x86_64 0:3.6-3.el7                                                                        

Complete!

更新本地 yum 源

更新软件包

reposync -n --repoid=base --repoid=updates --repoid=extras --repoid=centosplus -p /repo/centos/7/os/x86_64

更新 yum 元数据

createrepo --update /repo/centos/7/os/x86_64/base
createrepo --update /repo/centos/7/os/x86_64/updates
createrepo --update /repo/centos/7/os/x86_64/extras/
createrepo --update /repo/centos/7/os/x86_64/centosplus/
posted @ 2024-08-20 14:38  小吉猫  阅读(35)  评论(0编辑  收藏  举报