在本次案例中,我将使用 CentOS 7 的 Everything 镜像作为本地yum源,并同时将自身作为私有网络中唯一的 YUM 源服务器。
环境介绍
序号 | IP地址 | 系统版本 | 备注 |
---|---|---|---|
1 | 192.168.110.86 | CentOS 7 | 镜像源主机 |
2 | 192.168.110.87 | CentOS 7 | 客户端 |
软件版本
1 | [root@localhost ~]# cat /etc/os-release |
将ISO挂载为本地源
- 下载Everything的镜像到本地:大概有10G左右,不过好消息是这个镜像以后也不会更新了,最大也就10G了。
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
- 新建本地源挂载点:
1
mkdir -p /opt/everything
- 挂载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 - 移除原有软件源清单:
1
mv /etc/yum.repos.d/ /etc/yum.repos.d.bak
- 新建本地源清单
/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-7gpgcheck
参数用于指定是否检查公钥,因为是本地源所以其实也没必要;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 | # From lxnchan.cn |
将本地源作为网络中的镜像源
镜像源服务器配置
- 本地安装
httpd
:1
yum install -y httpd
- 新建httpd配置文件
/etc/httpd/conf.d/yum.conf
:保存退出。1
2
3
4
5
6
7
8
9
10Alias /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> - 随后启用并重启httpd:访问
1
2systemctl enable --now httpd
systemctl restart httpdhttp://192.168.110.86/repo/
,应该可以看到Everything镜像下的文件列表。如果是404或者403则需要检查配置文件是否正确。
客户端配置
- 移除原有软件源清单:
1
mv /etc/yum.repos.d/ /etc/yum.repos.d.bak
- 新建本地源清单
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-7baseurl
应该要指向之前创建的服务器地址。
这里同样禁用了公钥检查,如果需要启用还需要将everything镜像里面的KEY传送到客户端。保存后退出。 - 刷新一下缓存看一下是否有报错:此时就已经可以开始使用本地源安装软件了。
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
预览: