Lxn-Chan!

在未知的未来将要发生的事,一定有它的意义

在本次案例中,我将使用 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
    此时就已经可以开始使用本地源安装软件了。

 简单说两句

这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • Latest
  • Oldest
  • Hottest
Powered by Waline v2.15.8


联系站长 | 服务状态 | 友情链接

备案号:辽ICP备19013963号

萌ICP备 20219421 号

津公网安备12011602300394号

中国互联网违法和不良信息举报中心

架构版本号:8.1.6 | 本站已全面支持IPv6

已在各种bug中存活 2249 天 22 小时 49 分 48 秒

Copyright 2024 LingXuanNing, All rights reserved.