Cobbler
Cobbler简介
Cobbler
是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP
,DNS
等。
Cobbler
可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler
是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler
内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
cobbler集成的服务
- PXE服务支持
- DHCP服务管理
- DNS服务管理(可选bind,dnsmasq)
- 电源管理
- Kickstart服务支持
- YUM仓库管理
- TFTP(PXE启动时需要)
- Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
cobbler配置文件详解
cobbler
配置文件目录在/etc/cobbler
配置文件 | 作用 |
---|---|
/etc/cobbler/settings | cobbler 主配置文件 |
/etc/cobbler/iso/ | iso模板配置文件 |
/etc/cobbler/pxe | pxe模板配置文件 |
/etc/cobbler/power | 电源配置文件 |
/etc/cobbler/user.conf | web服务授权配置文件 |
/etc/cobbler/users.digest | web访问的用户名密码配置文件 |
/etc/cobbler/dhcp.template | dhcp服务器的的配置模板 |
/etc/cobbler/dnsmasq.template | dns服务器的配置模板 |
/etc/cobbler/tftpd.template | tftp服务的配置模板 |
/etc/cobbler/modules.conf | 模块的配置文件 |
cobbler数据目录
目录 | 作用 |
---|---|
/var/lib/cobbler/config/ | 用于存放distros,system,profiles等信息配置文件 |
/var/lib/cobbler/triggers/ | 用于存放用户定义的cobbler命令 |
/var/lib/cobbler/kickstart/ | 默认存放kickstart文件 |
/var/lib/cobbler/loaders/ | 存放各种引导程序以及镜像目录 |
/var/www/cobbler/ks_mirror/ | 导入的发行版系统的所有数据 |
/var/www/cobbler/images/ | 导入发行版的kernel和initrd镜像用于远程网络启动 |
/var/www/cobbler/repo_mirror/ | yum仓库存储目录 |
cobbler日志文件
日志文件路径 | 说明 |
---|---|
/var/log/cobbler/installing | 客户端安装日志 |
/var/log/cobbler/cobbler.log | cobbler日志 |
cobbler命令
cobbler check //核对当前设置是否有问题
cobbler list //列出所有的cobbler元素
cobbler report //列出元素的详细信息
cobbler sync //同步配置到数据目录,更改配置最好都要执行下
cobbler reposync //同步yum仓库
cobbler distro //查看导入的发行版系统信息
cobbler system //查看添加的系统信息
cobbler profile //查看配置信息
cobbler服务端部署
#关闭防火墙与SElinux
[root@localhost ~]# systemctl disable --now firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
#SElinux的状态一定要是disabled才可以,所以要重启生效
[root@localhost ~]# reboot
#配置国内的yum源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
#下载epel源
[root@localhost ~]# dnf -y install epel-release
#开启cobble模块
[root@localhost ~]# dnf -y module enable cobbler:3
#下载cobbler以及相关的软件
[root@localhost ~]# dnf -y install httpd dhcp* tftp tftp-server cobbler cobbler-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.service → /usr/lib/systemd/system/rsyncd.service.
[root@localhost ~]# systemctl enable --now tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
[root@localhost ~]# systemctl enable --now cobblerd
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
#生成加密的密码,将新生成的加密密码加入到配置文件
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" 'centos'
$1$18874$ZwbkLyHwFtGmAy8xhD6Ay/
[root@localhost ~]# vim /etc/cobbler/settings.yaml
server: 192.168.92.130 #修改server的ip地址为本机ip
next_server: 192.168.92.130 #设置tftp的ip地址为本机ip
default_password_crypted: "$1$18874$ZwbkLyHwFtGmAy8xhD6Ay/"
manage_dhcp: true #开启dhcp管理
#改完上述配置,重启cobbler服务
[root@localhost ~]# systemctl restart cobblerd.service
#进行错误检查,需要解决这些错误。4和5不用管,那是Debian系统需要解决的问题。
[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.
#问题1的解决方法
[root@localhost ~]# yum -y install syslinux*
[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
#问题2和3的解决方法
[root@localhost ~]# yum -y install yum-utils
#解决后再次检查可以发现还报问题1,如果你已完成问题1的解决方法可以不理。
[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: 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.
#配置DHCP模板文件
[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.92.0 netmask 255.255.255.0 { #192.168.92.0是子网
option routers 192.168.92.2; #网关
option domain-name-servers 8.8.8.8; #DNS
option subnet-mask 255.255.255.0; #子网掩码
range dynamic-bootp 192.168.92.100 192.168.92.120; #地址池
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
#重启服务,生效配置
[root@localhost ~]# systemctl restart httpd cobblerd
#同步cobbler
[root@localhost ~]# cobbler sync
.....................
shell triggers finished successfully
*** TASK COMPLETE ***
#挂载镜像
[root@localhost ~]# mount /dev/cdrom /mnt/
#导入镜像
#说明:
--path //镜像路径
--name //为安装源定义一个名字
--arch //指定安装源平台
#安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS8-x86_64,如果重复,系统会提示导入失败
[root@localhost ~]# cobbler import --path=/mnt/ --name=Centos8 arch=x86_64
task started: 2022-09-23_200632_import
task started (id=Media import, time=Fri Sep 23 20:06:32 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:
creating new distro: Centos8-x86_64
trying symlink: /var/www/cobbler/distro_mirror/Centos8 -> /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 for Centos8-x86_64
processing repo at : /var/www/cobbler/distro_mirror/Centos8/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/Centos8/AppStream
looking for /var/www/cobbler/distro_mirror/Centos8/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/Centos8/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/Centos8/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/Centos8/BaseOS
looking for /var/www/cobbler/distro_mirror/Centos8/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/Centos8/BaseOS/repodata
*** TASK COMPLETE ***
#生成kickstarts自动安装脚本(文件以.ks结尾,切勿tab,会卡死)
[root@localhost ~]# cobbler profile get-autoinstall --name Centos8-x86_64 > /var/lib/cobbler/templates/centos8.ks
#修改脚本
[root@localhost ~]# vim /var/lib/cobbler/templates/centos8.ks
........................
firewall --disable #关闭防火墙
........................
%packages
@^minimal-environment #在%packages与%end中间添加此行
%end
#检查ks脚本文件语法是否有误
[root@localhost bin]# cobbler validate-autoinstalls
task started: 2022-09-23_205335_validate_autoinstall_files
task started (id=Automated installation files validation, time=Fri Sep 23 20:53:35 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 ***
#===============================================================
#如果是生产环境中完成上述操作,然后同步cobbler和重启服务就完成了。
#但是在虚拟机的环境中还需要做些操作,如下:
[root@localhost loaders]# cd /usr/share/cobbler/bin/
[root@localhost bin]# ls
migrate-data-v2-to-v3.py migrate-settings.sh mkgrub.sh settings-migration-v1-to-v2.sh
#可以看到该脚本的执行会报一堆错误,先不用管
[root@localhost 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
#执行完上一步,去/var/lib/cobbler/loaders/下查看有没有grub与ldlinux.c32文件
[root@localhost bin]# cd /var/lib/cobbler/loaders/
[root@localhost ~]# ll /var/lib/cobbler/loaders/
total 72
drwxr-xr-x 2 root root 79 Sep 23 20:50 grub
lrwxrwxrwx 1 root root 31 Sep 23 20:50 ldlinux.c32 -> /usr/share/syslinux/ldlinux.c32
-rw-r--r-- 1 root root 26272 Sep 23 19:42 menu.c32
-rw-r--r-- 1 root root 42376 Sep 23 19:42 pxelinux.0
#同步cobbler
[root@localhost ~]# cobbler sync
#重启服务
[root@localhost ~]# systemctl restart httpd cobblerd rsyncd dhcpd
客户端安装系统
新建一台虚拟机,设置好cpu,内存等配置,无需自行添加镜像。创建好直接开启虚拟机。
需耐心等待,出现如下界面,选择刚刚制作的Distro。
等待几分钟后安装完成。密码是之前生成的并且写到配置文件的密码,我之前设置的是“centos”,注意!不是那一大串加密过后的密码。
定制安装
切记!这里浏览器的地址栏访问cobbler的web界面必须是https+ip+cobbler_web
的格式 。
默认的用户名与密码都是cobbler
。
定制安装步骤:
想查看日志得点击【log】
创建一台虚拟机进行测试
做完上述这些后,开启这台虚拟机。
耐心等待,下图是进入了安装的界面。
安装成功!可以看到IP地址跟之前设置的匹配。