RockyLinux配置cobbler无人值守安装服务

1. 环境

复制代码
Cobbler=3.2
Linux=RockyLinux-8.6
#客户端测试环境
Linux=RockyLinux-8.6
Linux=CentOS-7.9
#镜像
官方完整版镜像

2. 关闭防火墙和selinux

复制代码
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
systemctl disable --now firewalld

3. 安装依赖包及Cobbler3.2

复制代码
​
yum install epel-release  -y
yum module list | grep cobbler
dnf module enable cobbler:3 -y
yum install rsync rsync-daemon httpd dhcp-server tftp tftp-server cobbler cobbler-web pykickstart vim grub2-* yum-utils syslinux* -y
systemctl enable --now cobblerd httpd rsyncd tftp

4. 配置Cobbler文件

复制代码
sed -i.bak 's/^server: 127.0.0.1/server: 192.168.75.131/' /etc/cobbler/settings.yaml 
sed -i "s#next_server: 127.0.0.1#next_server: 192.168.75.131#" /etc/cobbler/settings.yaml
sed -i "s#manage_dhcp: false#manage_dhcp: true#" /etc/cobbler/settings.yaml
#生成默认系统root密码
openssl passwd -1 -salt "$RANDOM" 'root'
vim /etc/cobbler/settings.yaml
....
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
....
#验证修改
egrep '^server:|^next_server|^manage_dhcp|^default_password_' /etc/cobbler/settings.yaml
'''
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
manage_dhcp: true
next_server: 192.168.75.131
server: 192.168.75.131
'''

5. 配置DHCP服务摸版

vim /etc/cobbler/dhcp.template

复制代码
...
subnet 192.168.75.0 netmask 255.255.255.0 {  //修改此处网段
     option routers             192.168.75.2;  //修改此处网关
     option domain-name-servers 114.114.114.114;  //修改此处dns
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.75.100 192.168.75.200; //地址池 
     default-lease-time 21600; 
     max-lease-time 43200; 
     next-server $next_server;
}
....
5.1 配置DNSMASQ服务摸版(如使用dnsmasq服务配置,替代默认dhcp)

vim /etc/cobbler/dnsmasq.template

复制代码
...
# Cobbler generated configuration file for dnsmasq
# $date 
#
​
# resolve.conf .. ?
#no-poll
#enable-dbus
read-ethers
addn-hosts = /var/lib/cobbler/cobbler_hosts
​
dhcp-range=192.168.75.100,192.168.75.250,255.255.255.0,12h #内网如果已经有DHCP服务器的地址池,代理DHCP服务器地址池.
dhcp-option=option:router,192.168.75.254  #该网段DHCP服务器IP地址,代理DHCP的IP地址.
​
#dhcp-range=192.168.7.5,192.168.1.200
#dhcp-option=66,$next_server
dhcp-lease-max=1000
dhcp-authoritative
#dhcp-boot=pxelinux.0
#dhcp-boot=net:normalarch,pxelinux.0
​
dhcp-boot=grub/grubx64.efi # 修改此处
dhcp-boot=net:x86_64,grub/grubx64.efi  #修改此处
​
tftp-root=/var/lib/tftpboot  # 增加该行
​
$insert_cobbler_system_definitions
...
5.2 ###启用dnsmasq

vim /etc/cobbler/modules.conf

复制代码
...
[dhcp]
#module = managers.isc  # 注释默认
module = managers.dnsmasq # 启用dnsmasq
...

6. 检查当前cobbler配置

复制代码
#重启服务
systemctl restart cobblerd httpd rsyncd tftp
#检查
cobbler check
'''
The following are potential configuration items that you may want to fix:
​
1: some network boot-loaders are missing from /var/lib/cobbler/loaders. If you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely. Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, and yaboot.
2: debmirror package is not installed, it will be required to manage debian deployments and repositories
3: fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
​
Restart cobblerd and then run 'cobbler sync' to apply changes.
'''
#问题1,需要引导文件:
yum install syslinux* -y
cp /usr/share/syslinux/{menu.c32,pxelinux.0,libutil.c32,ldlinux.c32} /var/lib/cobbler/loaders/
ls /var/lib/cobbler/loaders/
'''
ldlinux.c32  libutil.c32  menu.c32  pxelinux.0
'''
​
#问题2和问题3可以忽略
因为是debian系统才需要解决;
debian系统解决办法安装 fence-agents;

7. 同步Cobbler配置

复制代码
cobbler sync
#看到这个即为成功同步
'''
....
shell triggers finished successfully
*** TASK COMPLETE ***   
'''

8. 导入镜像

需提前上传完整版RockyLinux8.6镜像到服务器.

复制代码
#创建镜像挂载目录
mkdir -p /Rocky86
#挂载镜像
mount -t iso9660 -o loop,ro /iso/Rocky-8.6-x86_64-dvd1.iso /Rocky86 
#导入镜像
cobbler import --path=/Rocky86/ --name=Rocky86 --arch=x86_64
#看到这个结果即为成功
'''
cobbler import --path=/Rocky86/ --name=Rocky86 --arch=x86_64
....
*** TASK COMPLETE ***
'''
#--path: 镜像路径
#--name: 为安装源定义一个名字
#--arch: 指定安装源是 32 位、64 位、ia64, 目前支持的选项有: x86│x86_64│ia64
#安装源的唯一标示就是根据 name 参数来定义,本例导入成功后,安装源的唯一标示就是:Rocky86-x86_64,如果重复,系统会提示导入失败.
​
#查看导入镜像
cobbler list
'''
distros:
   Rocky86-x86_64  #镜像
​
profiles:
   Rocky86-x86_64  #配置文件
...
'''
#查看导入镜像详细信息
cobbler distro report --name Rocky86-x86_64

9. 创建kickstarts自动安装脚本

ks模板脚本默认文件存放在/var/lib/cobbler/templates/

复制代码
cd /var/lib/cobbler/templates/
#生成模板文件 
cobbler profile get-autoinstall --name Rocky86-x86_64 > rocky86.ks
#修改生成的模板文件,如下:
vim rocky86.ks
'''
authselect --useshadow --enablemd5
bootloader --location=mbr --boot-drive=sda
clearpart --all --initlabel --drives=sda
text
firewall --disabled
services --disabled=firewall
firstboot --disable
keyboard us
lang en_US
url --url=$tree
repo --name=source-1 --baseurl=http://192.168.1.10/cobbler/distro_mirror/Rocky86-x86_64/BaseOS
repo --name=source-2 --baseurl=http://192.168.1.10/cobbler/distro_mirror/Rocky86-x86_64/Minimal
network --bootproto=dhcp --device=eth0 --onboot=on
network --hostname=ksInstallLinux
reboot
rootpw --iscrypted $1$32090$Z9bo6zoIURFVMsJydfw.L/
selinux --disabled
skipx
timezone Asia/Shanghai
zerombr
ignoredisk --only-use=sda
reqpart
part /boot --fstype=xfs --size=1024
part / --fstype=ext4 --grow
​
%packages
@^minimal-environment
%end
'''
​
#验证目录下的ks文件语法是否有误(/var/lib/cobbler/templates/)
cobbler validate-autoinstalls
'''
running python triggers from /var/lib/cobbler/triggers/task/validate_autoinstall_files/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/validate_autoinstall_files/pre/*
shell triggers finished successfully
*** TASK COMPLETE ***  //说明无误
'''
#修改profile,将我们新建的ks文件设为默认的kickstarts安装文件,修改网卡名称.
cobbler profile edit --name Rocky86-x86_64 --kernel-options='net.ifnames=0 biosdevname=0' --autoinstall rocky86.ks
#或者导入镜像时也可以导入模板
cobbler import --path=/Rocky86/ --name=Rocky86 --arch=x86_64 --kernel-options='net.ifnames=0 biosdevname=0' --autoinstall rocky86.ks
​
cobbler profile report --name Rocky86-x86_64
'''
Name : Rocky86-x86_64
Automatic Installation Template : rocky86.ks  //说明成功
Automatic Installation Metadata : {}
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : Rocky86-x86_64
Enable gPXE? : False
Enable PXE Menu? : True
Fetchable Files : {}
DHCP Filename Override : <<inherit>>
Kernel Options : {'net.ifnames': '0', 'biosdevname': '0'}  //说明成功
Kernel Options (Post Install) : {}
Management Classes : []
....
'''
​
#重新同步cobbler
cobbler sync
'''
...
shell triggers finished successfully
*** TASK COMPLETE *** //说明成功
'''
# 重启所有相关服务
systemctl restart httpd cobblerd rsyncd dhcpd

10. 配置UEFI引导自动安装

复制代码
#执行时会有报错 但不影响
bash /usr/share/cobbler/bin/mkgrub.sh
'''
+ grub2-mkimage -O arm64-efi -o /var/lib/cobbler/loaders/grub/grubaa64.efi --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr efinet
+ set +x
+ grub2-mkimage -O i386-pc-pxe -o /var/lib/cobbler/loaders/grub/grub.0 --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr chain pxe biosdisk
+ set +x
+ grub2-mkimage -O powerpc-ieee1275 -o /var/lib/cobbler/loaders/grub/grub.ppc64le --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr net ofnet
grub2-mkimage: error: cannot open `/usr/lib/grub/powerpc-ieee1275/moddep.lst': No such file or directory.
+ set +x
+ grub2-mkimage -O x86_64-efi -o /var/lib/cobbler/loaders/grub/grubx64.efi --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr chain efinet
+ set +x
'''
​
#配置因为文件做出改变,所以需要同步
cobbler sync

11. 修改PXE grub菜单

vim /var/lib/tftpboot/grub/grub.cfg

复制代码
cat /var/lib/tftpboot/grub/grub.cfg
'''
#-------------------------------------------------------------------------------
# Set defaults (is re-set by machine specific configuration file)
#-------------------------------------------------------------------------------
set arch='x86_64'
set hostname='dummy'
set system='dummy'
set lang=en
set serial_console=false
set serial_baud=115200
set serial_line=0
set k_console=""
set local_boot_file=""
set kernel_options=""
#调整超时时间10秒
set timeout=10
#调整默认安装系统
set default='Rocky86-x86_64'
set gfxpayload=text
....
'''
​
#!!!执行cobbler sync都会覆盖此文件!!!

12. 虚拟机客户端安装注意

复制代码
#测试UEFI需要将虚拟机设置成UEFI启动方式;
#虚拟机大小为2核4G;

13. Cobbler配置文件说明

部分

复制代码
/etc/cobbler    #配置文件目录
/etc/cobbler/boot_loader_conf #pxe模板配置文件
/etc/cobbler/dhcp.template  #dhcp目录
​
# 数据文件目录
/var/lib/cobbler/loaders #各种引导文件
/var/lib/cobbler/scripts #脚本文件
/var/lib/cobbler/templates #存放kickstart文件目录
​
# 日志目录
/var/log/cobbler
相关推荐
炫彩@之星几秒前
Windows和Linux安全配置和加固
linux·windows·安全·系统安全配置和加固
KubeSphere 云原生3 分钟前
云原生周刊:利用 eBPF 增强 K8s
云计算·k8s·容器平台·kubesphere
hhhhhhh_hhhhhh_11 分钟前
ubuntu18.04连接不上网络问题
linux·运维·ubuntu
冷心笑看丽美人18 分钟前
探秘 DNS 服务器:揭开域名解析的神秘面纱
linux·运维·服务器·dns
wenxiaocsdn24 分钟前
某科技局国产服务器PVE虚拟化技术文档
运维·服务器
冬天vs不冷1 小时前
Linux用户与权限管理详解
linux·运维·chrome
凯子坚持 c2 小时前
深入Linux权限体系:守护系统安全的第一道防线
linux·运维·系统安全
✿ ༺ ོIT技术༻2 小时前
C++11:新特性&右值引用&移动语义
linux·数据结构·c++
watermelonoops5 小时前
Deepin和Windows传文件(Xftp,WinSCP)
linux·ssh·deepin·winscp·xftp
疯狂飙车的蜗牛6 小时前
从零玩转CanMV-K230(4)-小核Linux驱动开发参考
linux·运维·驱动开发