cobbler服务手动部署与自动部署
cobbler服务部署
配置yum源和epel源
[root@node1 ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@node1 ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@node1 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
安装cobbler所需要的包
[root@node1 ~]# dnf -y module enable cobbler:3
[root@node1 ~]# yum -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon
将所需的服务设置开机自启
[root@node1 ~]# systemctl restart httpd rsyncd tftp cobblerd
[root@node1 ~]# systemctl enable --now httpd rsyncd tftp cobblerd
关闭防火墙和selinux
[root@node1 ~]# sed -i '/SELINUX=/s/enforcing/disabled/g' /etc/sysconfig/selinux
[root@node1 ~]# systemctl stop firewalld
[root@node1 ~]# systemctl disable firewalld
修改server的ip和tftp的ip地址
[root@node1 ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.124.135/' /etc/cobbler/settings.yaml
[root@node1 ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.124.135/' /etc/cobbler/settings.yaml
生成加密的密码
[root@node1 ~]# vim /etc/cobbler/settings.yaml
default_password_crypted: "$1$RANDOMM$AD6LLCfCINpKdgzr8C/Aa0"
//将dhcp的功能打开
manage_dhcp: true
重启cobbler服务
[root@node1 ~]# systemctl restart cobblerd.service
核对上面的设置是否有问题,此时有五个问题
[root@node1 ~]# 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.
问题1解决方法
//这个文件下缺少两个文件
[root@node1 ~]# yum -y install syslinux*
[root@node1 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@node1 ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
问题2和3的解决方法
缺少这个软件包
[root@node1 ~]# yum -y install yum-utils
问题4和问题5是debian系统的问题,我们此时的环境是centos8所以不用管
Debian系统解决办法安装fence-agents
配置dhcp模板文件
[root@node1 ~]# head -30 /etc/cobbler/dhcp.template ;
subnet 192.168.124.0 netmask 255.255.255.0 {
option routers 192.168.124.2;
option domain-name-servers 8.8.8.8;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.124.100 192.168.124.254;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
同步cobbler设置
[root@node1 ~]# systemctl restart httpd cobblerd.service
[root@node1 ~]# cobbler sync
task started: 2022-09-25_142711_sync
task started (id=Sync, time=Sun Sep 25 14:27:11 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 ***
管理distro
[root@node1 ~]# mount /dev/cdrom /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
导入镜像
[root@node1 ~]# cobbler import --path=/mnt/ --name=liuyang arch=x86_64
task started: 2022-09-25_143007_import
task started (id=Media import, time=Sun Sep 25 14:30:07 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/liuyang:
creating new distro: liuyang-x86_64
trying symlink: /var/www/cobbler/distro_mirror/liuyang -> /var/www/cobbler/links/liuyang-x86_64
creating new profile: liuyang-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/liuyang for liuyang-x86_64
processing repo at : /var/www/cobbler/distro_mirror/liuyang/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/liuyang/AppStream
looking for /var/www/cobbler/distro_mirror/liuyang/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/liuyang/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/liuyang/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/liuyang/BaseOS
looking for /var/www/cobbler/distro_mirror/liuyang/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/liuyang/BaseOS/repodata
*** TASK COMPLETE ***
查看cobbler镜像列表
[root@node1 ~]# cobbler list
distros:
liuyang-x86_64
profiles:
liuyang-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
查看详细信息
[root@node1 ~]# cobbler distro report --name liuyang-x86_64
Name : liuyang-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/liuyang-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/liuyang/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/liuyang/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@node1 templates]# cobbler profile get-autoinstall --name liuyang-x86_64 >/var/lib/cobbler/templates/liuyang.ks
[root@node1 templates]# cat /var/lib/cobbler/templates/liuyang.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 --disable
# 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.124.135/cblr/links/liuyang-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.124.135/cobbler/distro_mirror/liuyang/AppStream
repo --name=source-2 --baseurl=http://192.168.124.135/cobbler/distro_mirror/liuyang/BaseOS
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$11779$5cbAG74Tj7fYB4eSrsFHH.
# 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
@^minimanl-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.124.135/cblr/svc/op/yum/profile/liuyang-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.124.135" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.124.135" > /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.124.135/cblr/svc/op/autoinstall/profile/liuyang-x86_64" -o /root/cobbler.ks
# End final steps
%end
操作还没有弄完,还需要做以下操作
[root@node1 templates]# cd /usr/share/cobbler/bin/
[root@node1 bin]# ls
migrate-data-v2-to-v3.py mkgrub.sh
migrate-settings.sh settings-migration-v1-to-v2.sh
[root@node1 bin]# bash 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
grub2-mkimage: error: cannot open `/usr/lib/grub/arm64-efi/moddep.lst': No 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 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
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@node1 bin]# cd /var/lib/cobbler/loaders/
[root@node1 loaders]# cobbler sync
[root@node1 loaders]# systemctl restart httpd cobblerd rsyncd dhcpd
安装一个空的虚拟机,不要添加镜像,然后选我们刚刚上传的镜像
自动安装
httpds://192.168.124.135/cobbler_web
初始账号和密码都是cobbler
点击右上角的日志,没有的话就换一个浏览器或者重新选择sync就可以了
同步日志
开启虚拟机之后他还自都选择镜像
此时已经在安装了
安装完成,此时的网络信息就是我们刚刚设置的