注:必须使用CentOS官方源
#安装epel
[root@localhost ~]# yum install epel-release rsync rsync-daemon -y
#
[root@localhost ~]# yum module list | grep cobbler
cobbler 3 default [d] Versa
tile Linux deployment server
cobbler 3.3 default Versa
tile Linux deployment server
#cobbler直接开启会失败因为有两个 指定cobbler:3 开启
[root@localhost ~]# dnf module enable cobbler:3 -y
#此时查看已经有了cobbler可以通过yum安装了
[root@localhost ~]# yum 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@localhost ~]# yum install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart -y
#开启httpd和cobbler
[root@localhost ~]# systemctl enable --now httpd
[root@localhost ~]# systemctl enable --now cobblerd
[root@localhost ~]# systemctl enable --now rsyncd
[root@localhost ~]# systemctl enable --now tftp
#关闭防火墙和selinux
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# grep 'SELINUX=disabled' /etc/selinux/config
SELINUX=disabled
[root@localhost ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.220.5/' /etc/cobbler/settings.yaml
[root@localhost ~]# grep "^server: " /etc/cobbler/settings.yaml
server: 192.168.220.5 //此处修改为本机ip
[root@localhost ~]# sed -i "s#next_server: 127.0.0.1#next_server: 192.168.220.5#" /etc/cobbler/settings.yaml
[root@localhost ~]# grep "^next_server: " /etc/cobbler/settings.yaml
next_server: 192.168.220.5 //此处修改为本机ip
#生成密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" '123456789'
$1$20982$uHkwNZPwK6e4cbNUT8uZR0
# 修改 /etc/cobbler/settings 文件中的 default_password_crypted 参数的值为上面生成的密码串
[root@localhost ~]# grep 'default_password_crypted:' /etc/cobbler/settings.yaml
default_password_crypted: "$1$20982$uHkwNZPwK6e4cbNUT8uZR0" //此处修改为生成的密码
#dhcp功能打开
[root@localhost ~]# sed -i "s#manage_dhcp: false#manage_dhcp: true#" /etc/cobbler/settings.yaml
[root@localhost ~]# grep 'manage_dhcp:' /etc/cobbler/settings.yaml
manage_dhcp: true
# 核对当前设置是否有问题
[root@localhost ~]# 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: reposync is not installed, install yum-utils or dnf-plugins-core
3: yumdownloader is not installed, install yum-utils or dnf-plugins-core
4: debmirror package is not installed, it will be required to manage debian deployments and repositories
5: 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.
# 问题2和问题3:
[root@localhost ~]# yum install yum-utils -y
# 问题4和问题5可以忽略
#因为是debian系统才需要解决显示使用的是CentOS8
#debian系统解决办法安装 fence-agents
#问题1:
[root@localhost ~]# yum install syslinux* -y
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@localhost ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@localhost ~]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0
[root@localhost ~]# vim /etc/cobbler/dhcp.template //列出修改过的相关字段
subnet 192.168.220.0 netmask 255.255.255.0 { //网段
option routers 192.168.220.2; //网关
option domain-name-servers 114.114.114.114; //dns
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.220.200 192.168.220.210; //地址池
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
[root@localhost ~]# systemctl restart httpd cobblerd
[root@localhost ~]# cobbler sync
task started: 2022-08-12_044121_sync
task started (id=Sync, time=Fri Aug 12 04:41:21 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/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
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@localhost ~]# mount /dev/cdrom /mnt/ //挂载系统镜像
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# cobbler import --path=/mnt/ --name=CentOS-8 --arch=x86_64 //导入镜像
task started: 2022-08-12_044655_import
task started (id=Media import, time=Fri Aug 12 04:46:55 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/CentOS-8-x86_64:
creating new distro: CentOS-8-x86_64
trying symlink: /var/www/cobbler/distro_mirror/CentOS-8-x86_64 -> /var/www/cobbler/links/CentOS-8-x86_64
creating new profile: CentOS-8-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/CentOS-8-x86_64 for CentOS-8-x86_64
processing repo at : /var/www/cobbler/distro_mirror/CentOS-8-x86_64/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/CentOS-8-x86_64/AppStream
looking for /var/www/cobbler/distro_mirror/CentOS-8-x86_64/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/CentOS-8-x86_64/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/CentOS-8-x86_64/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/CentOS-8-x86_64/BaseOS
looking for /var/www/cobbler/distro_mirror/CentOS-8-x86_64/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/CentOS-8-x86_64/BaseOS/repodata
*** TASK COMPLETE *** //看到这个即为成功
# --path 镜像路径
# --name 为安装源定义一个名字
# --arch 指定安装源是 32 位、64 位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据 name 参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-8-x86_64,如果重复,系统会提示导入失败
[root@localhost ~]# cobbler list //查看
distros:
CentOS-8-x86_64 //镜像
profiles:
CentOS-8-x86_64 //配置文件
systems:
repos:
images:
mgmtclasses:
packages:
files:
[root@localhost ~]# cobbler distro report --name CentOS-8-x86_64 //查看详细信息 查看指定的--name 接镜像名
Name : CentOS-8-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-8-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/CentOS-8-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/CentOS-8-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@localhost ~]# cobbler profile get-autoinstall --name CentOS-8-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.220.5/cblr/links/CentOS-8-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.220.5/cobbler/distro_mirror/CentOS-8-x86_64/AppStream
repo --name=source-2 --baseurl=http://192.168.220.5/cobbler/distro_mirror/CentOS-8-x86_64/BaseOS
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$20982$uHkwNZPwK6e4cbNUT8uZR0
# 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.220.5/cblr/svc/op/yum/profile/CentOS-8-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.220.5" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.220.5" > /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.220.5/cblr/svc/op/autoinstall/profile/CentOS-8-x86_64" -o /root/cobbler.ks
# End final steps
%end
编写cento8.ks文件
#将上面文件的内容复制到centos8.ks文件内并修改其内容
[root@localhost templates]# cd /var/lib/cobbler/templates/
[root@localhost templates]# vim centos8.ks
[root@localhost templates]# cat centos8.ks
auth --useshadow --enablemd5
bootloader --location=mbr
clearpart --all --initlabel
text
firewall --disabled //防火墙关闭
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.220.5/cblr/links/CentOS-8-x86_64
repo --name=source-1 --baseurl=http://192.168.220.5/cobbler/distro_mirror/CentOS-8-x86_64/AppStream
repo --name=source-2 --baseurl=http://192.168.220.5/cobbler/distro_mirror/CentOS-8-x86_64/BaseOS
network --bootproto=dhcp --device=eth0 --onboot=on
reboot
rootpw --iscrypted $1$20982$uHkwNZPwK6e4cbNUT8uZR0
selinux --disabled
skipx
timezone America/New_York
install
zerombr
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
@^minimal-environment //设置为最小化安装
%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.220.5/cblr/svc/op/yum/profile/CentOS-8-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.220.5" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.220.5" > /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.220.5/cblr/svc/op/autoinstall/profile/CentOS-8-x86_64" -o /root/cobbler.ks
# End final steps
%end
[root@localhost ~]# cobbler validate-autoinstalls //验证ks文件语法是否有误
task started: 2022-08-12_053321_validate_autoinstall_files
task started (id=Automated installation files validation, time=Fri Aug 12 05:33:21 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 ***
# 修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@localhost ~]# cobbler profile edit --name CentOS-8-x86_64 --autoinstall centos8.ks
# 修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@localhost ~]# cobbler profile edit --name CentOS-8-x86_64 --kernel-options='net.ifnames=0 biosdevname=0'
[root@localhost ~]# cobbler profile report --name CentOS-8-x86_64
Name : CentOS-8-x86_64 //将默认文件修改为centos8.ks
Automatic Installation Template : centos8.ks
Automatic Installation Metadata : {}
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS-8-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 : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Next Server Override : <<inherit>>
Owners : ['admin']
Parent Profile :
Proxy :
Red Hat Management Key : <<inherit>>
Repos : []
Server Override : <<inherit>>
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@localhost ~]# cobbler sync
task started: 2022-08-12_054316_sync
task started (id=Sync, time=Fri Aug 12 05:43:16 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/CentOS-8-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/CentOS-8-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: CentOS-8-x86_64
trying hardlink /var/www/cobbler/distro_mirror/CentOS-8-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS-8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/CentOS-8-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS-8-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: CentOS-8-x86_64
trying hardlink /var/www/cobbler/distro_mirror/CentOS-8-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS-8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/CentOS-8-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS-8-x86_64/initrd.img
Writing template files for CentOS-8-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
processing boot_files for distro: CentOS-8-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@localhost ~]# systemctl restart httpd cobblerd rsyncd dhcpd
注:内存必须为2G以上
新建一个不带镜像的虚拟机 然后启动
#此时使用新虚拟机去安装系统并不会成功 需要做如下操作
[root@localhost ~]# ls /usr/share/cobbler/bin/
migrate-data-v2-to-v3.py mkgrub.sh
migrate-settings.sh settings-migration-v1-to-v2.sh
[root@localhost ~]# bash /usr/share/cobbler/bin/mkgrub.sh //执行时会有报错 但不影响
[root@localhost ~]# ll /var/lib/cobbler/loaders/ //此时此目录会新增两个文件
总用量 72
drwxr-xr-x 2 root root 79 8月 12 05:53 grub //新增文件 开机会需要
lrwxrwxrwx 1 root root 31 8月 12 05:53 ldlinux.c32 -> /usr/share/syslinux/ldlinux.c32 //新增文件
-rw-r--r-- 1 root root 26272 8月 12 04:33 menu.c32
-rw-r--r-- 1 root root 42376 8月 12 04:32 pxelinux.0
[root@localhost ~]# cobbler sync //因为文件做出改变 所以需要同步下
再次启动就会跳转到这个界面选择Centos-8-x86_64回车,然后等待一段时间
注:安装过程需要一段时间
看到这样的 就是正在安装软件包
等待安装结束后就可以看到正常虚拟机的启动过程
用户为root密码为之前生成的密码
使用https访问到cobbler的网页
账号密码都为cobbler
创建系统
启动新创建的虚拟机(生成mac在网页绑定的那台)
会自动选择不需要要手动操作