Cobbler
是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP
,DNS
等。
Cobbler
可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler
是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler
内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack
cobbler
命令详解
cobbler check //核对当前设置是否有问题
cobbler list //列出所有的cobbler元素
cobbler report //列出元素的详细信息
cobbler sync //同步配置到数据目录,更改配置最好都要执行下
cobbler reposync //同步yum仓库
cobbler distro //查看导入的发行版系统信息
cobbler system //查看添加的系统信息
cobbler profile //查看配置信息
安装部署
[root@test yum.repos.d]# dnf install epel-release
//下载官方的epel源 请使用centos默认源
[root@test ~]# dnf module list | grep cobbler
cobbler 3 default [d] Versatile Linux deployment server
cobbler 3.3 default Versatile Linux deployment server
//打开其中一个
[root@test ~]# dnf module enable cobbler:3
Last metadata expiration check: 0:01:22 ago on Sat 13 Aug 2022 10:29:43 AM CST.
Dependencies resolved.
=====================================================================================================
Package Architecture Version Repository Size
=====================================================================================================
Enabling module streams:
cobbler 3
Transaction Summary
=====================================================================================================
Is this ok [y/N]: y
Complete!
[root@test ~]# dnf list all | grep cobbler
cobbler.noarch 3.2.2-11.module_el8+14161+f12890f2 epel-modular
cobbler-tests.noarch 3.2.2-11.module_el8+14161+f12890f2 epel-modular
cobbler-web.noarch 3.2.2-11.module_el8+14161+f12890f2 epel-modular
[root@test ~]# yum -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync-daemon
//安装依赖包
[root@test ~]# systemctl enable --now httpd
[root@test ~]# systemctl enable --now cobblerd
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
[root@test ~]# systemctl enable --now rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service
[root@test ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:25151 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 *:443 *:*
LISTEN 0 128 *:80 *:*
//设为开机自启
[root@test ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@test ~]# vim /etc/selinux/config
bash: vim: command not found
[root@test ~]# vi /etc/selinux/config
[root@test ~]# setenforce 0
//关闭防火墙selinux
[root@test ~]# openssl passwd -1
Password:
Verifying - Password:
$1$wyLJEV9/$QAMHYhaWRKlzvxgGs1fKK0
//生成的密码给系统使用
[root@test ~]# vim /etc/cobbler/settings.yaml
default_password_crypted: "$1$wyLJEV9/$QAMHYhaWRKlzvxgGs1fKK0"
server: 192.168.80.33
next_server: 192.168.80.33
manage_dhcp: true
//修改此处几行配置
[root@test ~]# vim /etc/cobbler/dhcp.template
ignore client-updates;
set vendorclass = option vendor-class-identifier;
option system-arch code 93 = unsigned integer 16;
subnet 192.168.80.0 netmask 255.255.255.0 { //网段和子网掩码
option routers 192.168.80.2; //网关
option domain-name-servers 114.114.114.114; //dns
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.80.30 192.168.80.100; //分布多少个ip
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.80.33; //本机ip
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
# Legacy
if option system-arch = 00:00 {
[root@test ~]# systemctl restart httpd cobblerd
//重启
[root@test ~]# cobbler check
[root@test ~]# dnf -y install yum-utils
[root@test ~]# dnf -y install syslinux
[root@test ~]# dnf -y install syslinux-extlinux syslinux-tftpboot
//安装包 解决报错
[root@test ~]# cp /usr/share/syslinux/pxelinux.0 /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
//复制这两个文件到这个目录里面
[root@test ~]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0
[root@test ~]# /usr/share/cobbler/bin/mkgrub.sh
//执行这个脚本
[root@test ~]# ls /var/lib/cobbler/loaders/
grub ldlinux.c32 menu.c32 pxelinux.0
[root@test ~]# cobbler sync
task started: 2022-08-13_110600_sync
task started (id=Sync, time=Sat Aug 13 11:06:00 2022)
running python triggers from /var/lib/cobbler/triggers/task/sync/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/sync/pre/*
shell triggers finished successfully
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/system
removing: /var/lib/tftpboot/grub/system_link
removing: /var/lib/tftpboot/grub/images
copying bootloaders
running: ['rsync', '-rpt', '--copy-links', '--exclude=.cobbler_postun_cleanup', '/var/lib/cobbler/loaders/', '/var/lib/tftpboot']
received on stdout:
received on stderr:
running: ['rsync', '-rpt', '--copy-links', '--exclude=README.grubconfig', '/var/lib/cobbler/grub_config/', '/var/lib/tftpboot']
received on stdout:
received on stderr:
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
shell triggers finished successfully
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running python trigger cobbler.modules.managers.genders
running shell triggers from /var/lib/cobbler/triggers/change/*
shell triggers finished successfully
*** TASK COMPLETE ***
//同步
[root@test ~]# mount /dev/cdrom /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@test ~]# ls /mnt/
AppStream BaseOS EFI images isolinux LICENSE media.repo TRANS.TBL
//挂载镜像
[root@test ~]# cobbler import --name=CentOS8 --arch=X86_64 --path=/mnt
//导入镜像
task started: 2022-08-13_112606_import
task started (id=Media import, time=Sat Aug 13 11:26:06 2022)
running python triggers from /var/lib/cobbler/triggers/task/import/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/import/pre/*
shell triggers finished successfully
Found a candidate signature: breed=redhat, version=rhel8
Found a matching signature: breed=redhat, version=rhel8
Adding distros from path /var/www/cobbler/distro_mirror/CentOS8-x86_64:
creating new distro: CentOS8-x86_64
trying symlink: /var/www/cobbler/distro_mirror/CentOS8-x86_64 -> /var/www/cobbler/links/CentOS8-x86_64
creating new profile: CentOS8-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/distro_mirror/CentOS8-x86_64 for CentOS8-x86_64
processing repo at : /var/www/cobbler/distro_mirror/CentOS8-x86_64/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/CentOS8-x86_64/AppStream
looking for /var/www/cobbler/distro_mirror/CentOS8-x86_64/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/CentOS8-x86_64/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/CentOS8-x86_64/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/CentOS8-x86_64/BaseOS
looking for /var/www/cobbler/distro_mirror/CentOS8-x86_64/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/CentOS8-x86_64/BaseOS/repodata
*** TASK COMPLETE ***
[root@test ~]# cobbler list
distros:
CentOS8-x86_64
profiles:
CentOS8-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
//列出镜像
[root@test ~]# cobbler distro report
Name : CentOS8-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS8-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/CentOS8-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/CentOS8-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Management Classes : []
OS Version : rhel8
Owners : ['admin']
Redhat Management Key :
Remote Boot Initrd : ~
Remote Boot Kernel : ~
Template Files : {}
镜像存放的位置
[root@test ~]# ss -an | grep 67
u_str ESTAB 0 0 /run/systemd/journal/stdout 26468 * 26467
u_str ESTAB 0 0 * 25767 * 25768
u_str ESTAB 0 0 * 25768 * 25767
u_str ESTAB 0 0 * 26467 * 26468
udp ESTAB 0 0 192.168.80.33%ens33:68 192.168.80.100:67
tcp ESTAB 0 52 192.168.80.33:22 192.168.80.1:55678
//检查dhcp是否打开
[root@test ~]# cobbler profile get-autoinstall --name CentOS8-x86_64
# Sample kickstart file for current EL, Fedora based distributions.
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --enabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=http://192.168.80.33/cblr/links/CentOS8-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.80.33/cobbler/distro_mirror/CentOS8-x86_64/AppStream
repo --name=source-2 --baseurl=http://192.168.80.33/cobbler/distro_mirror/CentOS8-x86_64/BaseOS
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$wyLJEV9/$QAMHYhaWRKlzvxgGs1fKK0
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone America/New_York
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
autopart
%pre
set -x -v
exec 1>/tmp/ks-pre.log 2>&1
# Once root's homedir is there, copy over the log.
while : ; do
sleep 10
if [ -d /mnt/sysimage/root ]; then
cp /tmp/ks-pre.log /mnt/sysimage/root/
logger "Copied %pre section log to system"
break
fi
done &
# Enable installation monitoring
%end
%packages
%end
%post --nochroot
set -x -v
exec 1>/mnt/sysimage/root/ks-post-nochroot.log 2>&1
%end
%post
set -x -v
exec 1>/root/ks-post.log 2>&1
# Start yum configuration
curl "http://192.168.80.33/cblr/svc/op/yum/profile/CentOS8-x86_64" --output /etc/yum.repos.d/cobbler-config.repo
# End yum configuration
# Start post_install_network_config generated code
# End post_install_network_config generated code
# Start download cobbler managed config files (if applicable)
# End download cobbler managed config files (if applicable)
# Start koan environment setup
echo "export COBBLER_SERVER=192.168.80.33" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.80.33" > /etc/profile.d/cobbler.csh
# End koan environment setup
$SNIPPET('redhat_register')
# Begin cobbler registration
# cobbler registration is disabled in /etc/cobbler/settings.yaml
# End cobbler registration
# Enable post-install boot notification
# Start final steps
curl "http://192.168.80.33/cblr/svc/op/autoinstall/profile/CentOS8-x86_64" -o /root/cobbler.ks
# End final steps
%end
//生成ks文件
[root@test ~]# cd /var/lib/cobbler/templates/
[root@test templates]# vim centos8.ks
[root@test templates]# cat centos8.ks
auth --useshadow --enablemd5
bootloader --location=mbr
clearpart --all --initlabel
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
# Use network installation
url --url=http://192.168.80.33/cblr/links/CentOS8-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.80.33/cobbler/distro_mirror/CentOS8-x86_64/AppStream
repo --name=source-2 --baseurl=http://192.168.80.33/cobbler/distro_mirror/CentOS8-x86_64/BaseOS
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$wyLJEV9/$QAMHYhaWRKlzvxgGs1fKK0
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
autopart
%pre
set -x -v
exec 1>/tmp/ks-pre.log 2>&1
# Once root's homedir is there, copy over the log.
while : ; do
sleep 10
if [ -d /mnt/sysimage/root ]; then
cp /tmp/ks-pre.log /mnt/sysimage/root/
logger "Copied %pre section log to system"
break
fi
done &
# Enable installation monitoring
%end
%packages
%end
%post --nochroot
set -x -v
exec 1>/mnt/sysimage/root/ks-post-nochroot.log 2>&1
%end
%post
set -x -v
exec 1>/root/ks-post.log 2>&1
# Start yum configuration
curl "http://192.168.80.33/cblr/svc/op/yum/profile/CentOS8-x86_64" --output /etc/yum.repos.d/cobbler-config.repo
# End yum configuration
# Start post_install_network_config generated code
# End post_install_network_config generated code
# Start download cobbler managed config files (if applicable)
# End download cobbler managed config files (if applicable)
# Start koan environment setup
echo "export COBBLER_SERVER=192.168.80.33" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.80.33" > /etc/profile.d/cobbler.csh
# End koan environment setup
$SNIPPET('redhat_register')
# Begin cobbler registration
# cobbler registration is disabled in /etc/cobbler/settings.yaml
# End cobbler registration
# Enable post-install boot notification
# Start final steps
curl "http://192.168.80.33/cblr/svc/op/autoinstall/profile/CentOS8-x86_64" -o /root/cobbler.ks
# End final steps
%end
[root@test ~]# cobbler validate-autoinstalls
task started: 2022-08-13_120453_validate_autoinstall_files
task started (id=Automated installation files validation, time=Sat Aug 13 12:04:53 2022)
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 ***
//自动安装
[root@test ~]# cobbler profile edit --name CentOS8-x86_64 --autoinstall centos8.ks
[root@test ~]# cobbler profile report --name CentOS8-x86_64
Name : CentOS8-x86_64
Automatic Installation Template : centos8.ks //这里改成我们命名的.ks
Automatic Installation Metadata : {}
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS8-x86_64
Enable gPXE? : False
Enable PXE Menu? : True
Fetchable Files : {}
DHCP Filename Override : <>
Kernel Options : {}
Kernel Options (Post Install) : {}
Management Classes : []
Management Parameters : <>
Name Servers : []
Name Servers Search Path : []
Next Server Override : <>
Owners : ['admin']
Parent Profile :
Proxy :
Red Hat Management Key : <>
Repos : []
Server Override : <>
Template Files : {}
Virt Auto Boot : True
Virt Bridge : xenbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm
[root@test ~]# cobbler profile edit --name CentOS8-x86_64 --kernel-options 'net.ifnames=0 biosdevname=0'
[root@test ~]# cobbler profile report --name CentOS8-x86_64
Name : CentOS8-x86_64
Automatic Installation Template : centos8.ks
Automatic Installation Metadata : {}
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS8-x86_64
Enable gPXE? : False
Enable PXE Menu? : True
Fetchable Files : {}
DHCP Filename Override : <>
Kernel Options : {'net.ifnames': '0', 'biosdevname': '0'} //网卡回归重新命名
[root@test ~]# cobbler sync
task started: 2022-08-13_121405_sync
task started (id=Sync, time=Sat Aug 13 12:14:05 2022)
running python triggers from /var/lib/cobbler/triggers/task/sync/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/sync/pre/*
shell triggers finished successfully
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/CentOS8-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/system
removing: /var/lib/tftpboot/grub/system_link
removing: /var/lib/tftpboot/grub/grub.cfg
removing: /var/lib/tftpboot/grub/local_efi.cfg
removing: /var/lib/tftpboot/grub/local_legacy.cfg
removing: /var/lib/tftpboot/grub/local_powerpc-ieee1275.cfg
removing: /var/lib/tftpboot/grub/x86_64_menu_items.cfg
removing: /var/lib/tftpboot/images/CentOS8-x86_64
copying bootloaders
running: ['rsync', '-rpt', '--copy-links', '--exclude=.cobbler_postun_cleanup', '/var/lib/cobbler/loaders/', '/var/lib/tftpboot']
received on stdout:
received on stderr:
running: ['rsync', '-rpt', '--copy-links', '--exclude=README.grubconfig', '/var/lib/cobbler/grub_config/', '/var/lib/tftpboot']
received on stdout:
received on stderr:
copying distros to tftpboot
copying files for distro: CentOS8-x86_64
trying hardlink /var/www/cobbler/distro_mirror/CentOS8-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/CentOS8-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS8-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: CentOS8-x86_64
trying hardlink /var/www/cobbler/distro_mirror/CentOS8-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/CentOS8-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS8-x86_64/initrd.img
Writing template files for CentOS8-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
processing boot_files for distro: CentOS8-x86_64
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
shell triggers finished successfully
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running python trigger cobbler.modules.managers.genders
running shell triggers from /var/lib/cobbler/triggers/change/*
shell triggers finished successfully
*** TASK COMPLETE ***
//最后同步
[root@test ~]# systemctl restart httpd cobblerd rsyncd dhcpd
[root@test ~]# systemctl enable --now tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
//重启
新建虚拟机
选择我们要的系统centos8
安装成功输入密码,密码是.ks文件设置的
用ip链接
用ip访问,密码账户cobbler
创建系统
通用配置
网络配置
MAC地址可在虚拟机网络适配器,高级选项生成
同步
开机自动装机
ip是192.168.80.24.跟网页手动配置的一样就说明成功