cobbler部署

配置yum源

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo h
ttps://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -
e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/e
pel/epel-release-latest-8.noarch.rpm
[root@localhost yum.repos.d]# sed -i 's|^#baseurl=https://download.exampl
e/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.re
pos.d/epel*
[root@localhost ~]# yum module list | grep cobbler
cobbler 3 default [d]
Versatile Linux deployment server
cobbler 3.3 default [d]
Versatile Linux deployment server
[root@localhost ~]# dnf module enable cobbler:3 -y
[root@localhost ~]# yum -y install httpd dhcp* tftp tftp-server cobbler c
obbler-web pykickstart rsync rsync-daemon

设置开机自启

[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service
→ /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl enable --now rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.servic
e → /usr/lib/systemd/system/rsyncd.service.
[root@localhost ~]# systemctl enable --now tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /u
sr/lib/systemd/system/tftp.socket.
[root@localhost ~]# systemctl enable --now cobblerd
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.serv
ice → /usr/lib/systemd/system/cobblerd.service.

关闭防火墙和selinux

[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled

重启系统
修改server的ip地址为本机ip

[root@localhost ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.78.138/'
/etc/cobbler/settings.yaml
[root@localhost ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.16
8.78.138/' /etc/cobbler/settings.yaml
生成加密的密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" 'redhat'
$1$23696$TqUJEFSaMRGHr9m6vntSa/ 这是密码加密后的形式

将新生成的加密密码加入到配置文件

[root@localhost ~]# vim /etc/cobbler/settings.yaml
---------------------------------
default_password_crypted: "$1$23696$TqUJEFSaMRGHr9m6vntSa/"
---------------------------------
[root@localhost ~]# sed -i "s#manage_dhcp: false#manage_dhcp: true#" /et
c/cobbler/settings.yaml
[root@localhost ~]# grep 'manage_dhcp:' /etc/cobbler/settings.yaml
manage_dhcp: true

重启cobbler

[root@localhost ~]# systemctl restart cobblerd

通过cobbler check 核对当前设置是否有问题

[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. I
f 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 wan
t 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 debi
an deployments and repositories
5: fencing tools were not found, and are required to use the (optional) p
ower management features. install cman or fence-agents to use them
Restart cobblerd and then run 'cobbler sync' to apply changes.

问题1解决办法

[root@localhost ~]# yum -y install syslinux*
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/lo
aders/
[root@localhost ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/load
ers/
[root@localhost ~]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0

问题2和问题3解决办法

[root@localhost ~]# yum -y install yum-utils

问题4和问题5可以忽略,因为是debian系统才需要解决,显示使用的
是centos8 Debian系统解决办法安装fence­agents
配置DHCP模板文件

[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.78.0 netmask 255.255.255.0 {
option routers 192.168.78.254;
option domain-name-servers 8.8.8.8;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.78.140 192.168.78.150;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;

同步cobbler配置

[root@localhost ~]# systemctl restart httpd cobblerd
[root@localhost ~]# cobbler sync
task started: 2022-09-23_151024_sync
task started (id=Sync, time=Fri Sep 23 15:10:24 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_cle
anup', '/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 ***

管理distro

[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-09-23_151525_import
task started (id=Media import, time=Fri Sep 23 15:15:25 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:
creating new distro: CentOS-8-x86_64
trying symlink: /var/www/cobbler/distro_mirror/CentOS-8 -> /var/www/cobbl
er/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 for CentOS8-x86_64
processing repo at : /var/www/cobbler/distro_mirror/CentOS-8/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/CentOS-8/AppSt
ream
looking for /var/www/cobbler/distro_mirror/CentOS-8/AppStream/repodata/*c
omps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/CentOS-8/AppStrea
m/repodata
processing repo at : /var/www/cobbler/distro_mirror/CentOS-8/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/CentOS-8/BaseO
S
looking for /var/www/cobbler/distro_mirror/CentOS-8/BaseOS/repodata/*comp
s*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/CentOS-8/BaseOS/re
podata
*** TASK COMPLETE ***

安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装
源的唯一标示就是:CentOS­8­x86_64,如果重复,系统会提示导入
失败
查看cobbler镜像列表

[root@localhost ~]# cobbler list
distros:
CentOS-8-x86_64
profiles:
CentOS-8-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:

查看详细信息 查看指定的–name 接镜像名

[root@localhost ~]# cobbler distro report --name CentOS-8-x86_64
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/
images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/CentOS-8/
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 : {}

创建kickstarts自动安装脚本

[root@localhost ~]# cobbler profile get-autoinstall --name CentOS-8-x86_6
4 > /var/lib/cobbler/templates/centos8.ks
[root@localhost ~]# cd /var/lib/cobbler/templates/
[root@localhost templates]# pwd
/var/lib/cobbler/templates
[root@localhost templates]# cat centos8.ks
# 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 --disabled //关闭防火墙
# 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.78.138/cblr/links/CentOS-8-x86_64
# If any cobbler repo definitions were referenced in the kickstart profil
e, include them here.
repo --name=source-1 --baseurl=http://192.168.78.138/cobbler/distro_mirro
r/CentOS-8/AppStream
repo --name=source-2 --baseurl=http://192.168.78.138/cobbler/distro_mirro
r/CentOS-8/BaseOS
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$23696$TqUJEFSaMRGHr9m6vntSa/
# 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
@^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.78.138/cblr/svc/op/yum/profile/CentOS-8-x86_64" --ou
tput /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.78.138" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.78.138" > /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.78.138/cblr/svc/op/autoinstall/profile/CentOS-8-x86_
64" -o /root/cobbler.ks
# End final steps
%end

此时使用虚拟机去安装系统并不会成功 需要做如下
操作

[root@localhost ~]# cd /usr/share/cobbler/bin/
[root@localhost bin]# ls
migrate-data-v2-to-v3.py migrate-settings.sh mkgrub.sh settings-migrat
ion-v1-to-v2.sh
[root@localhost bin]# bash mkgrub.sh
+ grub2-mkimage -O arm64-efi -o /var/lib/cobbler/loaders/grub/grubaa64.ef
i --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm
gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt pas
sword_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 re
gexp tr efinet
grub2-mkimage: error: cannot open `/usr/lib/grub/arm64-efi/moddep.lst': N
o such file or directory.
+ 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 slee
p 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/gru
b.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 sear
ch_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs t
ftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm s
erial 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.ef
i --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm
gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt pas
sword_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 re
gexp tr chain efinet
grub2-mkimage: error: cannot open `/usr/lib/grub/x86_64-efi/moddep.lst':
No such file or directory.
+ set +x
+ ln -s /usr/share/syslinux/ldlinux.c32 /var/lib/cobbler/loaders/ldlinux.
c32
+ set +x
[root@localhost bin]# cd /var/lib/cobbler/loaders/
[root@localhost loaders]# ll
total 72
drwxr-xr-x 2 root root 79 Sep 23 15:27 grub
lrwxrwxrwx 1 root root 31 Sep 23 15:27 ldlinux.c32 -> /usr/share/sysli
nux/ldlinux.c32
-rw-r--r-- 1 root root 26272 Sep 23 14:57 menu.c32
-rw-r--r-- 1 root root 42376 Sep 23 14:57 pxelinux.0
[root@localhost loaders]# cobbler sync
task started: 2022-09-23_152748_sync
task started (id=Sync, time=Fri Sep 23 15:27:48 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_cle
anup', '/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/images/pxeboot/vm
linuz -> /var/lib/tftpboot/images/CentOS-8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/CentOS-8/images/pxeboot/in
itrd.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/images/pxeboot/vm
linuz -> /var/www/cobbler/images/CentOS-8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/CentOS-8/images/pxeboot/in
itrd.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 loaders]# systemctl restart httpd cobblerd rsyncd dhcpd

手动安装
创建一个虚拟机,然后打开虚拟机


自动安装
使用浏览器访问https://192.168.78.138/cobbler_web
默认登录的用户名和密码都为cobbler




点击Actions–Sync,右上角有同步日志


posted @ 2022-09-25 14:17  舒少`  阅读(41)  评论(0)    收藏  举报