首页主机资讯如何通过Cobbler定制Ubuntu系统环境

如何通过Cobbler定制Ubuntu系统环境

时间2025-11-20 01:09:03发布访客分类主机资讯浏览1410
导读:通过 Cobbler 定制 Ubuntu 系统环境 一 架构与方案选择 使用 Cobbler 统一管理 DHCP/TFTP/PXE/HTTP,实现无人值守安装与镜像分发。 Ubuntu 定制通常有两种路径: 传统 preseed(deb...

通过 Cobbler 定制 Ubuntu 系统环境

一 架构与方案选择

  • 使用 Cobbler 统一管理 DHCP/TFTP/PXE/HTTP,实现无人值守安装与镜像分发。
  • Ubuntu 定制通常有两种路径:
    • 传统 preseed(debian-installer):适合服务器批量安装,参数可控、镜像可离线。
    • Subiquity + cloud-init:Ubuntu 20.04/22.04/24.04 推荐路径,支持 autoinstall 与用户数据云配置,维护友好。
  • 镜像导入方式可选:
    • 直接 import ISO(便捷,适合 Subiquity/桌面版)。
    • 使用 debmirror 同步 APT 仓库(适合传统 preseed 离线安装)。

二 环境准备与基础配置

  • 安装组件(以 Ubuntu Server 为例):
    • sudo apt-get update
    • sudo apt-get install cobbler cobbler-web dhcp3-server tftpd-hpa xinetd debmirror
  • 配置 DHCP(示例,按实际网段修改):
    • /etc/dhcp/dhcpd.conf
      • subnet 192.168.1.0 netmask 255.255.255.0 {
        • range 192.168.1.100 192.168.1.200;
        • option routers 192.168.1.1;
        • option domain-name-servers 8.8.8.8, 8.8.4.4;
        • filename “pxelinux.0”;
        • next-server 192.168.1.2;
        • }
    • /etc/default/isc-dhcp-server:INTERFACESv4 “eth0”
    • 启动服务:sudo systemctl restart isc-dhcp-server
  • 配置 TFTP(xinetd):
    • /etc/xinetd.d/tftp:disable = no
    • 启动服务:sudo systemctl restart xinetd
  • 启动 Cobbler 并自检:
    • sudo systemctl start cobbler & & sudo systemctl enable cobbler
    • sudo cobbler get-loaders
    • sudo cobbler check(按提示修复)

三 导入镜像与创建 Profile

  • 方式 A(ISO 导入,适合 Subiquity/桌面版)
    • 挂载 ISO:mount -o loop /iso/ubuntu-24.04.1-live-server-amd64.iso /mnt
    • 导入:cobbler import --name Ubuntu24 --path /mnt
    • 查看生成的 distro/profile:cobbler distro list;cobbler profile list
  • 方式 B(debmirror 仓库,适合 preseed 离线安装)
    • 配置 /etc/debmirror.conf(注释掉 @dists/@arches 限制)
    • 同步:debmirror -a amd64 --method http --dist focal --section main,restricted,universe,multiverse --host archive.ubuntu.com /path/to/mirror
    • 导入:cobbler import --path /path/to/mirror --name ubuntu-20.04
  • 创建 Profile(preseed 示例)
    • cobbler profile add --name ubuntu-20.04-profile --distro ubuntu-20.04 --kickstart /var/lib/cobbler/kickstarts/ubuntu-20.04.seed
  • 创建 Profile(Subiquity/cloud-init 示例)
    • 上传 ISO 到 Web 目录:
      • mkdir -p /var/www/cobbler/pub/cloud-init/Ubuntu24
      • cp /iso/ubuntu-24.04.1-live-server-amd64.iso /var/www/cobbler/pub/cloud-init/Ubuntu24/
    • 编辑 distro 内核参数(将 192.168.10.40 替换为 Cobbler 服务器地址):
      • cobbler distro edit --name Ubuntu24-casper-x86_64 --kernel-options ‘root=/dev/ram0 ramdisk_size=1500000 ip=dhcp url=http://192.168.10.40/cblr/pub/cloud-init/Ubuntu24/ubuntu-24.04.1-live-server-amd64.iso autoinstall cloud-config-url=http://192.168.10.40/cblr/svc/op/autoinstall/profile/Ubuntu24-casper-x86_64’
    • 绑定 cloud-init 用户数据模板:
      • cobbler profile edit --name Ubuntu24-casper-x86_64 --autoinstall cloud-init_user-data
  • 同步:cobbler sync

四 定制内容与示例

  • 定制方式一览
    • 软件源与镜像:ISO 离线源(Subiquity)或本地 APT 仓库(preseed/debmirror)
    • 分区与文件系统:preseed 的 preseed/partman 或 Subiquity 的 autoinstall storage
    • 用户与密码:preseed 的 passwd 模块;Subiquity/cloud-init 的 users 与 chpasswd
    • 包与任务:preseed 的 pkgsel;cloud-init 的 packages/runcmd/snap
    • 网络:DHCP 或静态;可在 system 级别绑定 MAC/IP
  • 示例 1:preseed 关键片段(/var/lib/cobbler/kickstarts/ubuntu-20.04.seed)
    • d-i debian-installer/locale string en_US.UTF-8
    • d-i keyboard-configuration/xkb-keymap select us
    • d-i netcfg/choose_interface select auto
    • d-i netcfg/get_hostname string ubuntu2004
    • d-i netcfg/get_domain string local
    • d-i mirror/country string manual
    • d-i mirror/http/hostname string archive.ubuntu.com
    • d-i mirror/http/directory string /ubuntu
    • d-i mirror/http/proxy string
    • d-i clock-setup/utc boolean true
    • d-i time/zone string Asia/Shanghai
    • d-i partman-auto/method string regular
    • d-i partman-auto/choose_recipe select atomic
    • d-i partman-partitioning/confirm_write_new_label boolean true
    • d-i partman/confirm boolean true
    • d-i partman/confirm_nooverwrite boolean true
    • d-i passwd/user-fullname string Ubuntu User
    • d-i passwd/username string ubuntu
    • d-i passwd/user-password-crypted password $1$cobbler$nBCRhq3fBRuMs35Rp4EUX/ # 用 openssl passwd -1 生成
    • d-i pkgsel/include string openssh-server vim htop
    • d-i pkgsel/upgrade select none
    • d-i finish-install/reboot_in_progress note
  • 示例 2:cloud-init 用户数据(/var/lib/cobbler/autoinstall_templates/cloud-init_user-data)
    • #cloud-config
    • hostname: ubuntu24
    • users:
      • name: ubuntu sudo: ALL=(ALL) NOPASSWD:ALL ssh_authorized_keys:
        • ssh-rsa AAAAB3NzaC1yc2E… # 你的公钥 shell: /bin/bash
    • packages:
      • curl
      • vim
      • htop
    • runcmd:
        • echo ‘vm.swappiness=10’ > > /etc/sysctl.conf
        • systemctl enable --now ssh
    • timezone: Asia/Shanghai
    • write_files:
      • path: /etc/apt/sources.list.d/custom.list content: | deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
  • 说明
    • 使用 preseed 时,创建 system 可绑定 MAC 实现静态网络与快速引导;使用 Subiquity 时,可在 system 级别设置静态 IP 并通过 cloud-config-url 拉取用户数据。

五 部署与验证

  • 创建主机条目(示例)
    • 按 MAC 绑定(推荐,更快):
      • NAME=“Ubuntu24-auto” & & cobbler system add --name $NAME --profile Ubuntu24-casper-x86_64 --kernel-options “root=/dev/ram0 ramdisk_size=1500000 ip=dhcp url=http://192.168.10.40/cblr/pub/cloud-init/Ubuntu24/ubuntu-24.04.1-live-server-amd64.iso autoinstall cloud-config-url=http://192.168.10.40/cblr/svc/op/autoinstall/system/$NAME” --mac-address “00:50:56:39:B7:BA” --static true --ip-address “192.168.10.250” --netmask “255.255.255.0” --gateway “192.168.10.2” --name-servers “223.5.5.5” --hostname “Ubuntu24” --netboot-enabled true & & NAME=“”
    • 或 DHCP 自动发现(首次发现较慢):
      • cobbler system add --name Ubuntu24-dhcp --profile Ubuntu24-casper-x86_64 --netboot-enabled true
  • 同步并启动
    • cobbler sync
    • 客户端从 PXE 启动,安装完成后登录验证(如 cloud-init 模板设置了密码,可用该账户登录;或检查 SSH 公钥是否生效)
  • 常见问题
    • 新版本 Ubuntu 24.04(Noble) 可能不在默认签名中,需手动扩展 /var/lib/cobbler/distro_signatures.json,添加 “noble” 签名后重启 cobblerd 并 cobbler sync。
    • 若使用 ISO 离线安装,确保 url= 指向 Cobbler 的 HTTP 目录,且 ISO 已放置到正确路径(如 /var/www/cobbler/pub/cloud-init/Ubuntu24/)。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: 如何通过Cobbler定制Ubuntu系统环境
本文地址: https://pptw.com/jishu/751816.html
Cobbler在Ubuntu集群部署中的作用 Debian上Zookeeper的权限如何管理

游客 回复需填写必要信息