【经验分享】基于cobbler的openeuler节点自动部署

部署cobbler服务节点

虽然cobbler服务节点并不要求和待部署节点系统一致,但原版cobbler无法识别openeuler的系统标识,需要安装openeuler自己适配过的版本,因此服务节点还是建议使用openeuler系统搭建。
软件包方面cobbler包已经包含全部需要的功能,cobbler-web只是额外提供了图形化的网页前端,方便交互操作,如果只使用命令行操作可以不装。

yum install cobbler cobbler-web

cobbler整合了自动部署需要的dhcp、tftp、rsync等服务,根据需要在防火墙上放行服务端口:

#示例中网口位于internal域
firewall-cmd --zone=internal --add-service=dhcp --permanent
firewall-cmd --zone=internal --add-service=tftp --permanent
firewall-cmd --zone=internal --add-service=rsyncd --permanent
#如果启用网页管理
firewall-cmd --zone=internal --add-service=http --permanent
#刷新
firewall-cmd --reload

在总配置文件/etc/cobbler/settings中设置cobbler服务节点的ip(示例中为192.168.0.10):

# this is the address of the cobbler server -- as it is used
# by systems during the install process, it must be the address
# or hostname of the system as those systems can see the server.
# if you have a server that appears differently to different subnets
# (dual homed, etc), you need to read the --server-override section
# of the manpage for how that works.
server: 192.168.0.10

各个子服务的简要配置参考后续章节,配置好这些子服务后可以启用cobbler服务:

systemctl enable --now cobblerd
# 在子服务都配置完成后,同步所有配置,唤醒子服务
cobbler sync

注意每次修改配置,以及新增待部署节点,都需要重新sync。

tftp服务

以系统默认的tftp服务为例,在总配置文件/etc/cobbler/settings中声明由cobbler管理此子服务,并设置好tftp服务ip,本示例中tftp就在cobbler节点上,因此next_server和server是同一个ip:

# set to 1 to enable Cobbler's TFTP management features.
# the choice of TFTP mangement engine is in /etc/cobbler/modules.conf
manage_tftpd: 1
# if using cobbler with manage_dhcp, put the IP address
# of the cobbler server here so that PXE booting guests can find it
# if you do not set this correctly, this will be manifested in TFTP open timeouts.
next_server: 192.168.0.10
# This variable contains the location of the tftpboot directory. If this directory is not present cobbler does not
# start.
# Default: /var/lib/tftpboot
tftpboot_location: "/var/lib/tftpboot"

在cobbler模块设置/etc/cobbler/modules.conf中选择:

# tftpd:
# chooses the TFTP management engine if manage_tftp is enabled
# in /etc/cobbler/settings, which is ON by default.
#
# choices:
#    managers.in_tftpd -- default, uses the system's tftp server
#    managers.tftpd_py -- uses cobbler's tftp server
#

[tftpd]
module = managers.in_tftpd

同时根据实际场景需求编辑/etc/xinetd.d/tftp中的选项,其中disable需要改为no以启用tftp服务。
可以手动通过xinetd启用tftp服务测试配置效果,但非必要,cobbler同步配置时也会自动唤醒它:

systemctl enable --now xinetd

dhcp服务

ip分配方面有dhcpd和dnsmasq等选择,服务节点上应当确保有且只有其中一种服务运行,以dhcpd为例,在总配置文件/etc/cobbler/settings中声明由cobbler管理此子服务:

# set to 1 to enable Cobbler's DHCP management features.
# the choice of DHCP management engine is in /etc/cobbler/modules.conf
manage_dhcp: 1

在cobbler模块设置/etc/cobbler/modules.conf中选择:

# dhcp:
# chooses the DHCP management engine if manage_dhcp is enabled
# in /etc/cobbler/settings, which is off by default.
# choices:
#    managers.isc     -- default, uses ISC dhcpd
#    managers.dnsmasq -- uses dnsmasq, also must select dnsmasq for dns above
# NOTE: more configuration is still required in /etc/cobbler
# for more information:
# https://github.com/cobbler/cobbler/wiki/Dhcp-management

[dhcp]
module = managers.isc

dhcpd实际使用的配置文件是/etc/dhcp/dhcpd.conf,但cobbler会在同步配置的时候重新生成这个文件,因此不建议直接修改此文件,正确的配置方式是修改cobbler的模板/etc/cobbler/dhcp.template
根据实际场景需求编辑中的选项,以决定如何给新加入的节点自动分配ip。
dhcpd服务会在cobbler同步配置时自动唤醒,不需要手动启用。

rsync服务

类似的,在总配置文件/etc/cobbler/settings中声明由cobbler管理此子服务:

# set to 1 to enable Cobbler's RSYNC management features.
manage_rsync: 1

这个服务通常不需要调整什么参数。

dns服务

cobbler也可以管理dns,但集群内网通常会有独立的dns服务节点,此处略过,在总配置文件/etc/cobbler/settings中声明不需要cobbler管理即可:

# set to 1 to enable Cobbler's DNS management features.
# the choice of DNS mangement engine is in /etc/cobbler/modules.conf
manage_dns: 0

网页前端

如果需要网页操作界面,额外启用cobbler web服务,web服务依赖httpd,定义在/etc/httpd/conf.d/cobbler_web.conf,通常不需要修改,直接启用httpd服务即可。

systemctl enable --now httpd

访问路径为http://server_ip/cobbler_web,默认的登录账号和密码均为cobbler。

生成引导镜像

根据待部署节点的构架不同,需要在服务端准备不同的grub引导文件。旧版cobbler曾经提供过get-loaders指令,实质是从github上的某个仓库中获取官方准备好的引导文件。现在这种做法已经废弃,虽然openeuler版本的cobbler依然保留着这个指令,但无法正常执行。
新的方案是直接在本地生成grub文件,需要本地环境中存在目标构架的依赖模块,如果目标构架跟服务节点本身一致的话比较方便,直接从yum源中安装即可,但如果服务节点和待部署节点构架不同的话,就需要手动获取依赖包。
以生成x64和aarch64构架引导镜像为例:

#cobbler节点本身是x64构架,yum源中有对应的依赖包
yum install grub2-efi-x64-modules efibootmgr
#aarch64构架依赖包不在yum源中,需要从aarch64的源中手动下载到本地再安装
yum install /tmp/grub2-efi-aa64-modules-2.06-15.oe2203.noarch.rpm
#生成所有可用构架的引导镜像
/usr/share/cobbler/bin/mkgrub.sh

定制template脚本

template脚本定义了PXE安装的具体行为,应当根据实际需要进行定制。通称kickstart,但目前的cobbler版本似乎不再使用这个称呼。
以下示例为文字模式安装系统,格式化存储盘并创建LVM分区,然后按照预置的server环境模板和系统工具附加组选择需要安装的软件包。
其中$SNIPPET('***')引用的代码段位于/var/lib/cobbler/snippets,但由于openeuler对cobbler的适配不完善,部分自带的snippet没有进行适配,无法识别openeuler系统类型,所以引用snippet时需要检查其中的代码段是否有效。

#version=DEVEL
# Use network installation
url --url=$tree
# Use text mode install
text
# Reboot after installation
reboot
# DONOT Run the Setup Agent on first boot
firstboot --disable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network template
$SNIPPET('network_config')
# Root password
rootpw --iscrypted '[ENCRYPTED_SHA]'
# SELinux configuration
selinux --disabled
# System services
services --enabled="chronyd"
# System timezone
timezone  Asia/Shanghai --utc
timesource --ntp-server [NTP_SERVER]
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda

# Partition clearing information
ignoredisk --only-use=sda
clearpart --all --initlabel --drives=sda
# Disk partitioning information
part /boot --fstype="xfs" --ondisk=sda --size=1024
part /boot/efi --fstype="efi" --ondisk=sda --size=600 --fsoptions="umask=0077,shortname=winnt"
part pv.1 --fstype="lvmpv" --ondisk=sda --size=1 --grow
volgroup openeuler --pesize=4096 pv.1
logvol swap --fstype="swap" --name=swap --vgname=openeuler --recommended
logvol / --fstype="xfs" --name=root --vgname=openeuler --percent=100

%pre
# log kickstart at pre_install period
$SNIPPET('log_ks_pre')
# tell when kickstarts are started
$SNIPPET('autoinstall_start')
# configure network at pre_install period
$SNIPPET('pre_install_network_config')
%end

%packages
@^server-product-environment
@system-tools
%end

%addon com_redhat_kdump --disable --reserve-mb='128'
%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

%post
# log kickstart at post-install period
$SNIPPET('log_ks_post')
# config network at post-install period
$SNIPPET('post_install_network_config')

# tell when kickstarts are fully complete
$SNIPPET('autoinstall_done')
%end

注意autoinstall_done片段会在安装完节点后通知cobbler服务端不再向此节点提供PXE安装服务,可以防止节点重启后误进PXE重复安装系统。如果需要重新安装,参照下一章节的指令在cobbler服务端重新启用PXE即可。

添加待部署节点

添加一个全新类型的待部署节点需要定义distro、profile、system三层信息,如果已有同类型节点,也可以在现有的profile模板基础上直接添加新的system。

创建distro层配置

通过官网下载或者其他途径获取系统镜像,以22.03LTS发行版镜像为例:

#挂载安装盘供导入
mount openEuler-22.03-LTS-x86_64-dvd.iso /media
#创建发行版模板
cobbler import --name=openEuler-22.03-aarch64 --path=/media
cobbler distro list

创建profile层配置

这一层在distro的基础上关联template脚本

#创建场景模板,需要准备好template脚本
cobbler profile add --name=openEuler-22.03-kp --distro=openEuler-22.03-aarch64-aarch64 --autoinstall=openEuler_22.03_aarch64.ks
cobbler profile list

创建system层配置

这一层在profile的基础上添加节点具体的信息,相当于创建节点配置,至少应当提供网卡MAC地址和主机名,其他网络信息可以省略,先让DHCP自动分配,等安装完系统后再进行校正。

cobbler system add --profile=openEuler-22.03-kp --interface=[NETWORK_INTERFACE] --mac=[MAC_ADDRESS] --ip-address=[IP_ADDRESS] --netmask=[NETMASK] --static=1 --hostname=[HOSTNAME] --name=[NODE_NAME]

启用该节点的pxe安装,autoinstall_done关闭的也是这个开关。

cobbler system edit --name=[NODE_NAME] --netboot-enabled=1

刷新配置

修改完以上任意一层配置都需要刷新才能生效。

cobbler sync

待部署节点PXE启动

在cobbler服务端配置完成后,将待部署节点PXE模式启动即可开始自动部署。
如果节点附带有BMC,可以通过ipmi指令远程控制pxe重启,例如:

#仅下一次启动优先尝试pxe
ipmitool -I lanplus -U [IPMI_USER] -P [IPMI_PASSWORD] -H [IPMI_ADDRESS] chassis bootdev pxe
#修改后检查效果
ipmitool -I lanplus -U [IPMI_USER] -P [IPMI_PASSWORD] -H [IPMI_ADDRESS] chassis bootparam get 5

鲲鹏节点可能遇到PXE过程黑屏没有输出的情况,看上去像卡死了。要看到安装进展的话需要进BIOS,关闭Advanced - Misc Configuration - Support SPCR

2 个赞

我碰到了黑屏左上角闪烁光标的问题,是浪潮的服务器,没有你说的那个选项。我想知道它是真的卡死了,还是在安装只是看不到输出呢。

老哥,你这个是在openeuler上部署的cobbler服务吧