温馨提示×

如何同步centos cobbler镜像

小樊
32
2026-10-08 22:27:57
栏目: 智能运维

在 CentOS 上使用 Cobbler 同步镜像(repository / distro),通常分为 系统安装镜像同步 和 软件仓库同步 两类。下面按常见场景说明。


一、Cobbler 基本概念

  • distro:CentOS 安装镜像(ISO 或网络源)
  • repo:YUM 软件仓库
  • profile / system:安装配置

同步核心命令:

cobbler sync
cobbler reposync

二、同步 CentOS 安装镜像(distro)

1. 挂载 CentOS ISO

mkdir -p /mnt/centos7
mount -o loop CentOS-7-x86_64-DVD.iso /mnt/centos7

2. 导入镜像到 Cobbler

cobbler import \
  --path=/mnt/centos7 \
  --name=centos7 \
  --arch=x86_64

导入完成后:

cobbler distro list

3. 同步配置

cobbler sync

三、同步 CentOS YUM 仓库(repo)

1. 添加 repo

cobbler repo add \
  --name=centos7-base \
  --mirror=http://mirrors.aliyun.com/centos/7/os/x86_64/ \
  --arch=x86_64 \
  --breed=yum

可选额外仓库:

cobbler repo add \
  --name=centos7-updates \
  --mirror=http://mirrors.aliyun.com/centos/7/updates/x86_64/

2. 同步仓库

cobbler reposync

只同步指定仓库:

cobbler reposync --only=centos7-base

四、让系统安装时自动使用 repo

1. 绑定 repo 到 profile

cobbler profile edit \
  --name=centos7-x86_64 \
  --repos="centos7-base centos7-updates"

2. 重新同步

cobbler sync

五、设置定时同步(推荐)

crontab -e

示例(每天凌晨同步):

0 2 * * * /usr/bin/cobbler reposync

六、常见问题排查

1. 防火墙 / SELinux

setsebool -P cobbler_can_network_connect 1
systemctl stop firewalld

2. Cobbler 服务状态

systemctl status cobblerd
systemctl status httpd

3. 查看日志

tail -f /var/log/cobbler/cobbler.log

七、示例完整流程(CentOS 7)

cobbler import --path=/mnt/centos7 --name=centos7 --arch=x86_64
cobbler repo add --name=centos7-base --mirror=http://mirrors.aliyun.com/centos/7/os/x86_64/
cobbler repo add --name=centos7-updates --mirror=http://mirrors.aliyun.com/centos/7/updates/x86_64/
cobbler reposync
cobbler profile edit --name=centos7-x86_64 --repos="centos7-base centos7-updates"
cobbler sync

如果你说明 CentOS 版本(6/7/8/Stream) 或 内网/离线环境,我可以给你更精确的同步方案。

0 踩