运维开发网

rpm和yum软件包管理,Linux编译安装及文本三剑客之sed

运维开发网 https://www.qedev.com 2021-02-05 17:46 出处:51CTO 作者:oiccwiea
1、自建yum仓库,分别为网络源和本地源网络源创建基于本地光盘OSyum源和基于阿里云yum源配置文件base.repo```[root@repo-server~]#cat/etc/yum.repos.d/base.repo[BaseOS]name=BaseOSbaseurl=file:///misc/cd/https://mirrors.aliyun.com/centos/$releasever

1、自建yum仓库,分别为网络源和本地源

  1. 网络源

    创建基于本地光盘OS yum源 和 基于阿里云 yum 源 配置文件 base.repo

[root@repo-server ~]# cat /etc/yum.repos.d/base.repo
[BaseOS]
name=BaseOS
baseurl=file:///misc/cd/
        https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        https://repo.huaweicloud.com/centos/$releasever/os/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        https://repo.huaweicloud.com/centos/$releasever/os/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7

[root@repo-server ~]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
 * BaseOS: 
 * extras: mirrors.aliyun.com
BaseOS                                                              | 3.6 kB  00:00:00     
epel                                                                | 4.7 kB  00:00:00     
extras                                                              | 2.9 kB  00:00:00     
(1/6): BaseOS/7/x86_64/group_gz                                     | 153 kB  00:00:00     
(2/6): epel/7/x86_64/group_gz                                       |  95 kB  00:00:00     
(3/6): BaseOS/7/x86_64/primary_db                                   | 6.1 MB  00:00:01     
(4/6): extras/7/x86_64/primary_db                                   | 222 kB  00:00:00     
(5/6): epel/7/x86_64/updateinfo                                     | 1.0 MB  00:00:01     
(6/6): epel/7/x86_64/primary_db                                     | 6.9 MB  00:00:02     
repo id                                        repo name                             status
BaseOS/7/x86_64                                BaseOS                                10,072
epel/7/x86_64                                  epel                                  13,516
extras/7/x86_64                                extras                                   448
repolist: 24,036

[root@repo-server ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * BaseOS: 
 * extras: mirrors.aliyun.com
repo id                                   repo name                         status
BaseOS/7/x86_64                           BaseOS                            enabled: 10,072
epel/7/x86_64                             epel                              enabled: 13,516
extras/7/x86_64                           extras                            enabled:    448
repolist: 24,036

2.本地源

在服务器端设置

使用 httpd 搭建服务器端

安装 httpd


[root@repo-server ~]# yum info httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * BaseOS: 
 * extras: mirrors.aliyun.com
Available Packages
Name        : httpd
Arch        : x86_64
Version     : 2.4.6
Release     : 95.el7.centos
Size        : 2.7 M
Repo        : BaseOS/7/x86_64
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
            : web server.

[root@repo-server ~]# yum -y install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * BaseOS: 
 * extras: repo.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-97.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================
 Package         Arch             Version                          Repository         Size
===========================================================================================
Installing:
 httpd           x86_64           2.4.6-97.el7.centos              updates           2.7 M

Transaction Summary
===========================================================================================
Install  1 Package

Total download size: 2.7 M
Installed size: 9.4 M
Downloading packages:
httpd-2.4.6-97.el7.centos.x86_64.rpm                                | 2.7 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : httpd-2.4.6-97.el7.centos.x86_64                                        1/1 
  Verifying  : httpd-2.4.6-97.el7.centos.x86_64                                        1/1 

Installed:
  httpd.x86_64 0:2.4.6-97.el7.centos                                                       

Complete!

把 httpd 设置为开机启动

[root@repo-server ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

参考阿里云目录结构在 /var/www/html目录下建立子目录

[root@repo-server ~]# mkdir -pv /var/www/html/centos/7
mkdir: created directory ‘/var/www/html/centos’
mkdir: created directory ‘/var/www/html/centos/7’
[root@repo-server ~]# ll -d /var/www/html/centos/7
drwxr-xr-x 2 root root 6 Jan 26 10:52 /var/www/html/centos/7

把光盘挂载到 /var/www/html/centos/7/ 目录下

[root@repo-server ~]# mount /dev/sr0 /var/www/html/centos/7/
mount: /dev/sr0 is write-protected, mounting read-only

外网访问界面如下图

rpm和yum软件包管理,Linux编译安装及文本三剑客之sed

配置 extras源 和 updates源 到 /var/www/html/centos/7/ 目录下

先查看系统有没有安装 reposync 程序

[root@repo-server ~]# rpm -q reposync
package reposync is not installed

[root@repo-server ~]# yum provides reposync
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * BaseOS: 
 * extras: repo.huaweicloud.com
BaseOS/7/x86_64/filelists_db                                        | 7.2 MB  00:00:01     
epel/7/x86_64/filelists_db                                          |  12 MB  00:00:02     
extras/7/x86_64/filelists_db                                        | 224 kB  00:00:00     
updates/7/x86_64/filelists_db                                       | 2.8 MB  00:00:00     
yum-utils-1.1.31-54.el7_8.noarch : Utilities based around the yum package manager
Repo        : BaseOS
Matched from:
Filename    : /usr/bin/reposync

[root@repo-server ~]# yum -y install yum-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * BaseOS: 
 * extras: repo.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be installed
...
Installed:
  yum-utils.noarch 0:1.1.31-54.el7_8                                                       

Dependency Installed:
  libxml2-python.x86_64 0:2.9.1-6.el7.5         python-chardet.noarch 0:2.2.1-3.el7        
  python-kitchen.noarch 0:1.1.1-5.el7          

Dependency Updated:
  libxml2.x86_64 0:2.9.1-6.el7.5                                                           

Complete!

[root@repo-server ~]# reposync --repoid=extras --download-metadata -p /var/www/html/centos/7/

下载完成后会发现 /var/www/html/centos/7/extras 目录下没有 repodata

使用 createrepo 命令 创建 repodata

[root@repo-server ~]# yum -y install createrepo

[root@repo-server ~]# cd /var/www/html/centos/7/extras/
[root@repo-server extras]# createrepo .
Spawning worker 0 with 224 pkgs
Spawning worker 1 with 224 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@repo-server extras]# ll
total 36
drwxr-xr-x 2 root root 28672 Jan 26 13:16 Packages
drwxr-xr-x 2 root root  4096 Jan 26 13:57 repodata

[root@repo-server ~]# reposync --repoid=updates --download-metadata -p /var/www/html/centos/7/

[root@repo-server ~]# ll /var/www/html/centos/7/updates
total 96
drwxr-xr-x 2 root root 73728 Jan 26 14:19 Packages
[root@repo-server ~]# cd /var/www/html/centos/7/updates
[root@repo-server updates]# createrepo .
Spawning worker 0 with 604 pkgs
Spawning worker 1 with 603 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@repo-server updates]# ll
total 100
drwxr-xr-x 2 root root 73728 Jan 26 14:19 Packages
drwxr-xr-x 2 root root  4096 Jan 26 14:22 repodata

配置 epel 源 到 /var/www/html/ 目录下

[root@repo-server ~]# reposync --repoid=epel --download-metadata -p /var/www/html/centos/7/
[root@repo-server ~]# ll /var/www/html
total 4
drwxr-xr-x 3 root root   15 Jan 26 12:06 centos
drwxr-xr-x 3 root root 4096 Jan 26 14:31 epel
[root@repo-server ~]# ll /var/www/html/epel/
total 1516
-rw-r--r--  1 root root    1178 Jan 26 14:31 17701387eccd44278df27e4386893256cc81680f81fb2e8de30d55c3fc51dd79-prestodelta.xml.gz
-rw-r--r--  1 root root 1048004 Jan 26 14:31 3371a70630a485083c97670856e8efd7f3cd52952b020cafe9bbab589f5c52ea-updateinfo.xml.bz2
-rw-r--r--  1 root root  398109 Jan 26 14:31 f595f0a7dd6d3f82d4f168b21aad081d1498842ea068ae58039c385f230f0cc6-comps-Everything.x86_64.xml
-rw-r--r--  1 root root   97653 Jan 26 14:31 f7dcae2527a34760d69f8690d8049c97210f05fe3dd4a94a16ff46ce2b6cdf5f-comps-Everything.x86_64.xml.gz
drwxr-xr-x 33 root root     285 Jan 26 14:31 Packages
[root@repo-server ~]# cd /var/www/html/epel/
[root@repo-server epel]# ll
total 1516
-rw-r--r--  1 root root    1178 Jan 26 14:31 17701387eccd44278df27e4386893256cc81680f81fb2e8de30d55c3fc51dd79-prestodelta.xml.gz
-rw-r--r--  1 root root 1048004 Jan 26 14:31 3371a70630a485083c97670856e8efd7f3cd52952b020cafe9bbab589f5c52ea-updateinfo.xml.bz2
-rw-r--r--  1 root root  398109 Jan 26 14:31 f595f0a7dd6d3f82d4f168b21aad081d1498842ea068ae58039c385f230f0cc6-comps-Everything.x86_64.xml
-rw-r--r--  1 root root   97653 Jan 26 14:31 f7dcae2527a34760d69f8690d8049c97210f05fe3dd4a94a16ff46ce2b6cdf5f-comps-Everything.x86_64.xml.gz
drwxr-xr-x 33 root root     285 Jan 26 14:31 Packages
[root@repo-server epel]# createrepo .
Spawning worker 0 with 6756 pkgs
Spawning worker 1 with 6756 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@repo-server epel]# ll
total 1520
-rw-r--r--  1 root root    1178 Jan 26 14:31 17701387eccd44278df27e4386893256cc81680f81fb2e8de30d55c3fc51dd79-prestodelta.xml.gz
-rw-r--r--  1 root root 1048004 Jan 26 14:31 3371a70630a485083c97670856e8efd7f3cd52952b020cafe9bbab589f5c52ea-updateinfo.xml.bz2
-rw-r--r--  1 root root  398109 Jan 26 14:31 f595f0a7dd6d3f82d4f168b21aad081d1498842ea068ae58039c385f230f0cc6-comps-Everything.x86_64.xml
-rw-r--r--  1 root root   97653 Jan 26 14:31 f7dcae2527a34760d69f8690d8049c97210f05fe3dd4a94a16ff46ce2b6cdf5f-comps-Everything.x86_64.xml.gz
drwxr-xr-x 33 root root     285 Jan 26 14:31 Packages
drwxr-xr-x  2 root root    4096 Jan 26 15:28 repodata

外网访问 os extras updates 源 和 epel 源界面如下

rpm和yum软件包管理,Linux编译安装及文本三剑客之sed

rpm和yum软件包管理,Linux编译安装及文本三剑客之sed

在本地客户端配置 yum 仓库

[root@repo-client ~]# cat /etc/yum.repos.d/base.repo
[BaseOS]
name=BaseOS
baseurl=http://10.0.0.201/centos/7/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=extras
baseurl=http://10.0.0.201/centos/7/extras/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=updates
baseurl=http://10.0.0.201/centos/7/updates/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[epel]
name=epel
baseurl=http://10.0.0.201/epel/
gpgcheck=1
enabled=1
gpgkey=http://10.0.0.201/epel/RPM-GPG-KEY-EPEL-7

[root@repo-client ~]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
BaseOS                                                              | 3.6 kB  00:00:00     
epel                                                                | 2.9 kB  00:00:00     
extras                                                              | 2.9 kB  00:00:00     
updates                                                             | 2.9 kB  00:00:00     
(1/5): BaseOS/group_gz                                              | 153 kB  00:00:00     
(2/5): extras/primary_db                                            | 222 kB  00:00:00     
(3/5): BaseOS/primary_db                                            | 3.3 MB  00:00:01     
(4/5): epel/primary_db                                              | 6.8 MB  00:00:02     
(5/5): updates/primary_db                                           | 4.7 MB  00:00:01     
repo id                                   repo name                                  status
BaseOS                                    BaseOS                                      4,071
epel                                      epel                                       13,512
extras                                    extras                                        448
updates                                   updates                                     1,207
repolist: 19,238
[root@repo-client ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                               repo name                             status
BaseOS                                BaseOS                                enabled:  4,071
epel                                  epel                                  enabled: 13,512
extras                                extras                                enabled:    448
updates                               updates                               enabled:  1,207
repolist: 19,238
0

精彩评论

暂无评论...
验证码 换一张
取 消