惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
J
Java Code Geeks
I
InfoQ
腾讯CDC
Vercel News
Vercel News
IT之家
IT之家
V
Visual Studio Blog
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 叶小钗
有赞技术团队
有赞技术团队
月光博客
月光博客
Martin Fowler
Martin Fowler
量子位
L
LangChain Blog
B
Blog
Last Week in AI
Last Week in AI
博客园 - 司徒正美
Microsoft Security Blog
Microsoft Security Blog
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans

泠泫凝的异次元空间

通过串口安装Linux | 泠泫凝的异次元空间 curl自编译 | 泠泫凝的异次元空间 Minecraft 认证服务器代理 | 泠泫凝的异次元空间 飞塔分流配置实战 | 泠泫凝的异次元空间 Windows 安全启动证书检查 | 泠泫凝的异次元空间 Lxn-OneDriveCLI | 泠泫凝的异次元空间 华三交换机配置 ERPS 环网 | 泠泫凝的异次元空间 PVE 配置 VLAN 感知 | 泠泫凝的异次元空间 MT7922 无线网卡安装 | 泠泫凝的异次元空间 无显示输出 Linux 主机配置桌面显示 | 泠泫凝的异次元空间 Wireguard 部署 SOP 手册(自用) | 泠泫凝的异次元空间 Zabbix 7.4 通过钉钉发送告警提醒 | 泠泫凝的异次元空间 Debian with xfce 通过 VNC 共享屏幕 华三S6860 IRF堆叠 | 泠泫凝的异次元空间 iPad 应用侧载 | 泠泫凝的异次元空间 Smart DNS 分区解析 | 泠泫凝的异次元空间 建立 NFS 服务器并挂载到客户端 | 泠泫凝的异次元空间 将 Android 以 MTP 方式连接至 Debian PVE 虚拟机迁移至 vCenter | 泠泫凝的异次元空间 vCenter 虚拟机迁移至 PVE | 泠泫凝的异次元空间 PVE迁移时提示密钥验证失败 | 泠泫凝的异次元空间 修改Windows设备设置区域 | 泠泫凝的异次元空间 恢复 SecureCRT 7.x 保存的密码 | 泠泫凝的异次元空间 PVE 超融合下电与上电流程 | 泠泫凝的异次元空间 记一次Zabbix异常处理 | 泠泫凝的异次元空间 苹果设备保存SHSH2 | 泠泫凝的异次元空间 PVE超融合部署 | 泠泫凝的异次元空间 树莓派启用zram | 泠泫凝的异次元空间 在 Hyper-V 上安装 EVE-NG | 泠泫凝的异次元空间 Zabbix 部署与 Windows 硬件信息收集 | 泠泫凝的异次元空间
CentOS 7 使用镜像作为本地源并将自身作为YUM源服务器 | 泠泫...
Lxn's Area · 2025-04-04 · via 泠泫凝的异次元空间

在本次案例中,我将使用 CentOS 7 的 Everything 镜像作为本地yum源,并同时将自身作为私有网络中唯一的 YUM 源服务器。

环境介绍

序号IP地址系统版本备注
1192.168.110.86CentOS 7镜像源主机
2192.168.110.87CentOS 7客户端

软件版本

1
2
3
4
5
6
7
8
[root@localhost ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.71.1.el7.x86_64 #1 SMP Tue Jun 28 15:37:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

将ISO挂载为本地源

  1. 下载Everything的镜像到本地:
    1
    wget https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/isos/x86_64/CentOS-7-x86_64-Everything-2207-02.iso -O CentOS-7-x86_64-Everything-2207-02.iso
    大概有10G左右,不过好消息是这个镜像以后也不会更新了,最大也就10G了。
  2. 新建本地源挂载点:
    1
    mkdir -p /opt/everything
  3. 挂载ISO到挂载点:
    1
    mount -o loop CentOS-7-x86_64-Everything-2207-02.iso /opt/everything/
    检查一下有没有成功挂载:
    1
    2
    3
    4
    5
    6
    [root@localhost ~]# df -Th -x tmpfs -x devtmpfs
    Filesystem Type Size Used Avail Use% Mounted on
    /dev/sda3 xfs 150G 12G 139G 8% /
    /dev/sda2 xfs 509M 119M 391M 24% /boot
    /dev/sda1 vfat 50M 12M 39M 23% /boot/efi
    /dev/loop0 iso9660 9.6G 9.6G 0 100% /opt/everything
  4. 移除原有软件源清单:
    1
    mv /etc/yum.repos.d/ /etc/yum.repos.d.bak
  5. 新建本地源清单/etc/yum.repos.d/main.repo
    1
    2
    3
    4
    5
    6
    [local]
    name=local
    baseurl=file:///opt/everything
    enabled=1
    gpgcheck=0
    gpgkey=file:///opt/everything/RPM-GPG-KEY-CentOS-7
    其中gpgcheck参数用于指定是否检查公钥,因为是本地源所以其实也没必要;baseurl指向Everything镜像的挂载点;name可以随便写。
    保存退出后刷新一下缓存看一下是否有报错:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    [root@localhost ~]# yum clean all && yum makecache
    Loaded plugins: fastestmirror
    Cleaning repos: local
    Cleaning up list of fastest mirrors
    Loaded plugins: fastestmirror
    Determining fastest mirrors
    local | 3.6 kB 00:00:00
    (1/4): local/group_gz | 153 kB 00:00:00
    (2/4): local/primary_db | 6.1 MB 00:00:00
    (3/4): local/filelists_db | 7.2 MB 00:00:00
    (4/4): local/other_db | 2.5 MB 00:00:00
    Metadata Cache Created

此时就已经可以开始使用本地源安装软件了。

持久化挂载

编辑/etc/fstab,添加如下行:

1
2
3
# From lxnchan.cn
# <ISO File> <Mount Path> iso9660 defaults,ro,loop 0
/root/CentOS-7-x86_64-Everything-2207-02.iso /opt/everything iso9660 defaults,ro,loop 0

将本地源作为网络中的镜像源

镜像源服务器配置

  1. 本地安装httpd
    1
    yum install -y httpd
  2. 新建httpd配置文件/etc/httpd/conf.d/yum.conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Alias /repo /opt/everything
    <Directory "/opt/everything">
    Options Indexes FollowSymLinks
    IndexOptions NameWidth=* DescriptionWidth=* FoldersFirst
    IndexOptions SuppressIcon HTMLTable Charset=UTF-8 SuppressHTMLPreamble
    Order allow,deny
    Allow from all
    AllowOverride all
    Require all granted
    </Directory>
    保存退出。
  3. 随后启用并重启httpd:
    1
    2
    systemctl enable --now httpd
    systemctl restart httpd
    访问http://192.168.110.86/repo/,应该可以看到Everything镜像下的文件列表。如果是404或者403则需要检查配置文件是否正确。

客户端配置

  1. 移除原有软件源清单:
    1
    mv /etc/yum.repos.d/ /etc/yum.repos.d.bak
  2. 新建本地源清单vi /etc/yum.repos.d/main.repo
    1
    2
    3
    4
    5
    [base]
    name=Server1-EverythingSource
    baseurl=http://192.168.110.86/repo/
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    其中的baseurl应该要指向之前创建的服务器地址。
    这里同样禁用了公钥检查,如果需要启用还需要将everything镜像里面的KEY传送到客户端。保存后退出。
  3. 刷新一下缓存看一下是否有报错:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    [root@localhost ~]# yum clean all && yum makecache
    Loaded plugins: fastestmirror
    Cleaning repos: base
    Cleaning up list of fastest mirrors
    Loaded plugins: fastestmirror
    Determining fastest mirrors
    base | 3.6 kB 00:00:00
    (1/4): base/group_gz | 153 kB 00:00:00
    (2/4): base/filelists_db | 7.2 MB 00:00:00
    (3/4): base/primary_db | 6.1 MB 00:00:00
    (4/4): base/other_db | 2.5 MB 00:00:00
    Metadata Cache Created
    此时就已经可以开始使用本地源安装软件了。

 上一篇

linux Fortigate