您当前所在位置:首页安装教程Cobbler3.x部署实战

Cobbler3.x部署实战

更新:2023-11-17 15:18:34编辑:tooool归类:安装教程人气:101

云和安全管理服务专家新钛云服 侯明明原创

在大批量安装Linux服务器系统时,如果手动安装,则需要花费大量的时间,而使用PXE安装时,会相对轻松很多。

Cobbler是一个将PXE整套流程合在一起的工具,可以帮我们快速的搭建好PXE安装所需的各种工具,并且在配置中也更方便。

本文将介绍如何部署Cobbler环境,并且安装CentOS7、Ubuntu18作为测试。

Cobbler3.x部署实战

文章结构

  1. 安装并配置Cobbler
  2. 安装Ubuntu18、CentOS7测试
  3. 常用的操作及报错处理

部署前的准备

  1. 一台CentOS8的系统,作为cobbler服务端
  2. 待安装的测试机

建议使用VMWare的虚机,启动比较快,测试方便

详细步骤

Cobbler安装与配置

在准备好的CentOS8中,按如下步骤操作:

  1. 系统的相关优化配置

- 关闭selinux

vim/etc/selinux/configSELINUX=disabled

调整后重启一下系统

- 关闭firewalld

systemctlstopfirewalld && systemctldisablefirewalld
  1. 安装Cobbler及相关的软件包
dnfinstallepel-release-y && dnfmoduleenablecobbler -y && dnfinstallcobbler tftp dhcp-servercobbler-web yum-utils pykickstart debmirror fence-agents vim wget -y
  1. 生成一个加密密码,安装后的系统会将其作为root密码使用
按照提示输入两次想要设置的密码,并将生成的加密密码保存好以下命令生成的加密密码的明文是 passwordopensslpasswd -1Password:
Verifying - Password:$1$rLza5zNH$xLKFqWoK32/IA/zslG3Up0
  1. 修改cobbler的主配置文件/etc/cobbler/setting
将 server 和 next_server 修改为本机的IP地址server:10.1.1.1next_server:10.1.1.1manage_tftpd:1manage_dhcp:1这里填写上一步生成的加密密码default_password_crypted:$1$rLza5zNH$xLKFqWoK32/IA/zslG3Up0
  1. 修改DHCP的配置模板/etc/cobbler/dhcp.template

dhcp的模板内容较多,仅修改下面设置中的部分内容即可

仅修改以下部分配置即可,根据自己的测试环境修改 网关与待分配的IPsubnet10.1.1.0netmask255.255.255.0{optionrouters10.1.1.254;optiondomain-name-servers223.5.5.5;optionsubnet-mask255.255.255.0;rangedynamic-bootp10.1.1.10010.1.1.200;filename"/pxelinux.0";default-lease-time21600;max-lease-time43200;next-server$next_server;
  1. 编辑/etc/cobbler/tftpd.template
default: offdescription: The tftp server serves files using the trivial file transfer \protocol. The tftp protocol is often used to boot diskless \workstations, download configuration files to network-aware printers, \and to start the installation process for some operating systems.servicetftp{disable=nosocket_type=dgramprotocol=udpwait=yesuser=$userserver=$binaryserver_args=-B 1380 -v -s $argsper_source=11cps=100 2flags=IPv4}
  1. 开启相关的服务
systemctl restart cobblerd tftp dhcp && systemctlenablecobblerd tftp dhcpd
  1. 执行命令cobbler get-loaders下载相关的loader组件
  2. 执行cobbler check检查配置,并解决出现的问题
vim /etc/debmirror.conf注释掉以下两行@dists="sid";@arches="i386";

反复执行 cobbler check,将问题处理完成

  1. 执行cobbler sync生成配置文件并自动重启相关的服务

配置Ubuntu18与CentOS7的镜像

  1. 下载镜像
下载 ubuntu18 镜像注意要从如下链接下载,不要在各大镜像源下载带 live 字样的系统,有 live 字样的操作系统不适用于 seed 文件安装wgethttp://cdimage.ubuntu.com/ubuntu/releases/bionic/release/ubuntu-18.04.5-server-amd64.iso下载 centos7镜像wgethttp://mirrors.163.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso
  1. 挂载镜像到本地
mkdir-p /mnt/ubuntu18; mkdir -pv /mnt/centos7mount-t iso9660 -o loop,ro /root/ubuntu-18.04.5-server-amd64.iso /mnt/ubuntu18mount-t iso9660 -o loop,ro /root/CentOS-7-x86_64-Minimal-2009.iso /mnt/centos7
  1. 导入
cobblerimport--name=ubuntu1804 --path=/mnt/ubuntu18
cobblerimport--name=centos7 --path=/mnt/centos7
  1. 创建system
获取到profile的名称cobblerprofile list上一步获取的 profile 名称填到 --profile 后面cobblersystem add --name=ubuntu1804 --profile=ubuntu1804-x86_64cobblersystem add --name=centos7 --profile=centos7-x86_64
  1. 编辑 ubuntu18的seed文件

打开cobbler的web控制台:https://ip/cobbler_web,用户名密码均为 cobbler

点击左侧的Templates,Edit 右侧的sample.seed,复制全部内容,并新建一个Template文件,可命名为ubuntu1804.seed

这里仅列出需要修改的地方

我这里调整了文件系统格式为 ext4,分区为自动,也可根据自己的情况调整d-i partman-auto/disk string /dev/sda
d-i partman-auto/choose_recipeselectatomic
d-i partman-auto/methodstringregular
d-i partman-lvm/device_remove_lvmbooleantrued-i partman-md/device_remove_mdbooleantrued-i partman-partitioning/confirm_write_new_labelbooleantrued-i partman/choose_partitionselectfinishd-i partman/confirmbooleantrued-i partman/confirm_nooverwritebooleantrued-i partman/default_filesystemstringext4
d-i partman/mount_styleselectuuid该命令表示可以从 cobbler 的指定目录下载 os 初始化的脚本,该脚本用于配置 IP 地址或其他的操作该脚本可以放到 /var/www/cobbler/pub/commands/ 内d-i preseed/late_commandstringwget -P /target/roothttp://$http_server/cblr/pub/commands/ubuntu18_os_start.sh; \
   uname -a
  1. 编辑centos的kickstart文件

打开cobbler的web控制台:https://ip:cobbler_web,用户名密码均为 cobbler

点击左侧的Templates,Edit 右侧的default.ks,复制全部内容,并新建一个Template文件,可命名为centos7.ks

这里仅列出需要修改的地方

Partition clearing informationxfs 文件系统,boot 分配1g,其余分给 / ,没有 swap分区clearpart--all --initlabel
part /boot --asprimary --fstype="xfs"--ondisk=sda  --size=1024part / --asprimary --fstype="xfs"--ondisk=sda  --grow --size=5000下载 os 初始化的脚本curl -o /root/centos7_os_start.sh http://$server/cblr/pub/commands/centos7_os_start.sh
  1. 其他配置

完成以上步骤后,cobbler sync同步一下配置文件

ubuntu 18需要执行如下命令,否则 PXE启动时会报识别光驱的错误,每次cobbler sync后,都需要执行如下命令

cp /mnt/ubuntu18/install/netboot/ubuntu-installer/amd64/initrd.gz /var/lib/tftpboot/images/ubuntu1804-x86_64/

安装测试

  1. 创建一台虚机,注意网卡要和Cobbler在同一个VLAN或广播域,该网段内不要有其他的DHCP服务器

注意:内存要4G或以上,否则会安装不成功

  1. 开机启动

选择 ubuntu18或centos安装即可,ubuntu18的 hwe 版本的内核比较新,对硬件支持更好,可根据需求选择

  1. 等待自动安装完成

日常操作与问题解决

  1. cobbler sync 命令

该命令比较常用,很重要,执行后会将 /etc/cobbler/ 下的 xxx.template 文件解析后写到各自的配置文件或 tftp 根目录以及/var/www/cobbler

执行后会重启部分服务,例如 dhcpd

  1. centos8中安装cobbler和 centos7安装的差异

centos8 epel源中的cobbler是3.x版本比较新,建议使用

centos7安装cobbler在执行 get-loaders时会报错,但是多次执行可能会成功

  1. PXE 启动时报 PXE-E3B TFTP Error

查看一下/var/lib/tftpboot/grub,可能没有 grub.0,如果没有的话,执行一下/usr/share/cobbler/bin/mkgrub.sh,会有报错,但先不用管

/var/lib/cobbler/loaders/看一下,确认是否有 grub 文件夹,如果有的话,应该就没问题了,再 cobbler sync 一下就可以了

参考文档:

· 官方文档-Quickstart

· https://asciinema.org/a/351156

· https://askubuntu.com/questions/1235723/automated-20-04-server-installation-using-pxe-and-live-server-image

· https://wiki.ubuntu.com/UEFI/PXE-netboot-install

· https://ubuntu.com/server/docs/install/netboot-amd64

我告诉你msdn版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

电脑为什么会出现蓝屏 联想电脑ghost备份系统如何安装