【实验需求】

为了提高公司内部服务器下载软件包的速度,同时也不占用网络带宽,需要在内网部署一台私有的 YUM 服务,将阿里云镜像源的相关镜像保存到本地,公司其它内网服务器的 YUM 源均指向该私有 YUM 仓库。

【实验环境】

image-20230725145957128
1
2
3
repo-mirror-server        192.168.119.147
client1 192.168.119.158
client2 192.168.119.145

【实验过程】

1、安装 Cobbler及其相关的服务和组件

1
2
3
# Cobbler 依赖与epel源,安装前需要先配好epel源
[root@repo-mirror-server ~]# yum -y install cobbler
[root@repo-mirror-server ~]# systemctl enable --now cobblerd httpd

2、使用阿里云 zabbix 的源为例进行测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[root@repo-mirror-server ~]# cobbler repo add --name=zabbix --mirror=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/ --arch=x86_64 --breed=yum
[root@repo-mirror-server ~]# cobbler reposync
task started: 2023-07-25_141239_reposync
task started (id=Reposync, time=Tue Jul 25 14:12:39 2023)
hello, reposync
run, reposync, run!
creating: /var/www/cobbler/repo_mirror/zabbix/config.repo
creating: /var/www/cobbler/repo_mirror/zabbix/.origin/zabbix.repo
running: /usr/bin/reposync -l -n -d --config=/var/www/cobbler/repo_mirror/zabbix/.origin/zabbix.repo --repoid=zabbix --download_path=/var/www/cobbler/repo_mirror -a x86_64
2.9 kB 00:00
321 kB 00:00
308 kB 00:00
436 kB 00:01
899 kB 00:01
825 kB 00:01
785 kB 00:01
826 kB 00:01
13 kB 00:00
342 kB 00:00
2.2 MB 00:03
2.2 MB 00:03
13 kB 00:00
12 kB 00:00
12 kB 00:00
3.0 MB 00:04

received on stderr:
running: createrepo -c cache -s sha /var/www/cobbler/repo_mirror/zabbix
received on stdout: Spawning worker 0 with 2 pkgs
Spawning worker 1 with 2 pkgs
Spawning worker 2 with 2 pkgs
Spawning worker 3 with 2 pkgs
Spawning worker 4 with 2 pkgs
Spawning worker 5 with 2 pkgs
Spawning worker 6 with 1 pkgs
Spawning worker 7 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

received on stderr:
running: chown -R root:apache /var/www/cobbler/repo_mirror/zabbix
received on stdout:
received on stderr:
running: chmod -R 755 /var/www/cobbler/repo_mirror/zabbix
received on stdout:
received on stderr:
*** TASK COMPLETE ***

# 查看同步后的结果
[root@repo-mirror-server ~]# ls /var/www/cobbler/repo_mirror/zabbix
cache zabbix-proxy-mysql-4.0.47-1.el7.x86_64.rpm zabbix-server-pgsql-4.0.47-1.el7.x86_64.rpm
config.repo zabbix-proxy-pgsql-4.0.47-1.el7.x86_64.rpm zabbix-web-4.0.47-1.el7.noarch.rpm
repodata zabbix-proxy-sqlite3-4.0.47-1.el7.x86_64.rpm zabbix-web-japanese-4.0.47-1.el7.noarch.rpm
zabbix-agent-4.0.47-1.el7.x86_64.rpm zabbix-release-4.0-2.el7.noarch.rpm zabbix-web-mysql-4.0.47-1.el7.noarch.rpm
zabbix-get-4.0.47-1.el7.x86_64.rpm zabbix-sender-4.0.47-1.el7.x86_64.rpm zabbix-web-pgsql-4.0.47-1.el7.noarch.rpm
zabbix-java-gateway-4.0.47-1.el7.x86_64.rpm zabbix-server-mysql-4.0.47-1.el7.x86_64.rpm

3、配置其中一台客户端的yum源指向该仓库地址进行测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[root@client1 ~]# vim /etc/yum.repos.d/yum.repo
[zabbix4.0]
name=zabbix4.0
baseurl=http://192.168.119.147/cobbler/repo_mirror/zabbix
enabled=1
gpgcheck=0

[root@client1 ~]# yum clean all
[root@client1 ~]# yum makecache

[root@client1 ~]# yum -y install zabbix-agent
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zabbix-agent.x86_64 0:4.0.47-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================
Installing:
zabbix-agent x86_64 4.0.47-1.el7 zabbix4.0 436 k

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

Total download size: 436 k
Installed size: 1.5 M
Downloading packages:
zabbix-agent-4.0.47-1.el7.x86_64.rpm | 436 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : zabbix-agent-4.0.47-1.el7.x86_64 1/1
Verifying : zabbix-agent-4.0.47-1.el7.x86_64 1/1

Installed:
zabbix-agent.x86_64 0:4.0.47-1.el7

Complete!

4、同步base、epel等其它镜像源,方法同上

1
2
3
4
[root@repo-mirror-server ~]# cobbler repo add --name=Base --mirror=https://mirrors.aliyun.com/centos/7/os/x86_64/ --arch=x86_64 --breed=yum
[root@repo-mirror-server ~]# cobbler repo add --name=extras --mirror=https://mirrors.aliyun.com/centos/7/extras/x86_64/ --arch=x86_64 --breed=yum
[root@repo-mirror-server ~]# cobbler repo add --name=epel --mirror=https://mirrors.aliyun.com/epel/7/x86_64/ --arch=x86_64 --breed=yum
[root@repo-mirror-server ~]# cobbler reposync

5、在浏览器中打开进行查看

image-20230725144550974

6、配置客户端指向该内网YUM源仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@client1 ~]# vim /etc/yum.repos.d/yum.repo
[zabbix4.0]
name=zabbix4.0
baseurl=http://192.168.119.147/cobbler/repo_mirror/zabbix
enabled=1
gpgcheck=0
[Base]
name=Base
baseurl=http://192.168.119.147/cobbler/repo_mirror/Base/
enabled=1
gpgcheck=0
[epel]
name=epel
baseurl=http://192.168.119.147/cobbler/repo_mirror/epel/
enabled=1
gpgcheck=0
[extras]
name=extras
baseurl=http://192.168.119.147/cobbler/repo_mirror/extras/
enabled=1
gpgcheck=0

7、设置计划任务,每天3点定时更新

1
2
3
[root@repo-mirror-server ~]# crontab -l
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
0 3 * * * cobbler reposync &> /dev/null