cobbler简介
1,Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
2,Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
3,Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
4,Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
puppet是一种Linux、Unix、windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet的设计目标是简化对这些资源的管理以及妥善处理资源间的依赖关系。puppet采用C/S星状的结构,所有的客户端和一个或几个服务器交互。每个客户端周期的(默认半个小时)向服务器发送请求,获得其最新的配置信息,保证和该配置信息同步。每个puppet客户端每半小时(可以设置)连接一次服务器端, 下载最新的配置文件,并且严格按照配置文件来配置客户端. 配置完成以后,puppet客户端可以反馈给服务器端一个消息. 如果出错,也会给服务器端反馈一个消息
cobbler官网:https://cobbler.github.io/
cobbler相关配置信息
1、cobbler集成的服务:
PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时需要)
Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
2、cobbler配置文件详解:
cobbler配置文件目录在/etc/cobbler
配置文件
/etc/cobbler/settings.yaml 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 模块的配置文件
3、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仓库存储目录
4、cobbler日志文件:
日志文件路径 说明
/var/log/cobbler/installing 客户端安装日志
/var/log/cobbler/cobbler.log cobbler日志
5、cobbler命令详解:
cobbler check //核对当前设置是否有问题
cobbler list //列出所有的cobbler元素
cobbler report //列出元素的详细信息
cobbler sync //同步配置到数据目录,更改配置最好都要执行下
cobbler reposync //同步yum仓库
cobbler distro //查看导入的发行版系统信息
cobbler system //查看添加的系统信息
cobbler profile //查看配置信息
cobbler服务端部署
安装cobbler以及相关的软件
先去安装
dhcp* tftp tftp-server pykickstart rsync rsync-daemon 后再安装cobbler cobbler-web
yum -y install dhcp* tftp tftp-server pykickstart rsync rsync-daemon
[root@node1 ~]# yum -y install cobbler-web
Last metadata expiration check: 0:04:54 ago on Thu 25 Jul 2024 08:43:28 AM CST.
Error:
Problem: problem with installed package cobbler-3.3.4-1.el9.noarch
- package cobbler3.2-3.2.2-16.el9.noarch from epel conflicts with cobbler > 3.2.2 provided by cobbler-3.3.4-1.el9.noarch from @System
- package cobbler3.2-3.2.2-16.el9.noarch from epel conflicts with cobbler > 3.2.2 provided by cobbler-3.3.4-1.el9.noarch from epel
- package cobbler3.2-web-3.2.2-16.el9.noarch from epel requires cobbler3.2 = 3.2.2-16.el9, but none of the providers can be installed
- conflicting requests
(try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
[root@node1 ~]#
// 单独安装cobbler会报错需要加上一个参数 --allowerasing 才能继续安装
设置服务启动并开机自启
[root@node1 ~]# systemctl restart httpd
[root@node1 ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@node1 ~]# systemctl restart rsyncd
[root@node1 ~]# systemctl enable rsyncd
[root@node1 ~]# systemctl restart tftp
[root@node1 ~]# systemctl enable tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
[root@node1 ~]# systemctl restart cobblerd
/usr/lib/systemd/system/cobblerd.service.
[root@node1 ~]# systemctl enable cobblerd
关闭防火墙和selinux,node1这台虚拟机已经设置完成,
[root@node1 ~]# systemctl enable cobblerd
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
[root@node1 ~]# systemctl status firewalld
○ firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@node1 ~]# getenforce
Disabled
[root@node1 ~]#
修改服务器的主机的ip为本机ip,设置tftp的ip地址为本机ip
配置文件在 /etc/cobbler/settings.yaml中
server: 192.168.100.10
next_server: 192.168.100.10
安装虚拟机的时候会设置密码,所以在配置文件当中提前设置好,密码为加密文件需要先加密后设置。
[root@node1 ~]# openssl passwd -1 -salt "$RANDOM" 'redhat'
$1$10026$PdagJ2QpRSjVIMGompbA20
// -1 md5方式加密
// -5哈希ssa256方式加密
// -6哈希格式ssa512方式加密
// -salt生成一个随机值
// 调用"$RANDOM"随机生成出来,
// redhat为密码
此时生成出来了一个加密后的密码
加入到/etc/cobbler/settings.yaml中
default_password_crypted: "$1$10026$PdagJ2QpRSjVIMGompbA20"
将cobbler的dhcp功能打开
在/etc/cobbler/settings.yaml中
manage_dhcp: true
重启cobbler服务,在使用cobbler check检查配置
[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.
[root@node1 ~]#
出现了五个问题
第一个问题是丢失了两个文件包:pxelinux.0, menu.c32,需要将他拷贝进去
[root@node1 ~]# yum -y install syslinux*
[root@node1 syslinux]# cp pxelinux.0 /var/lib/cobbler/loaders/
[root@node1 syslinux]# cp menu.c32 /var/lib/cobbler/loaders/
第二个问题和第三个问题解决方法一样
yum -y install yum-utils
问题4和问题5可以忽略,因为是debian系统才需要解决,我们使用的是rocky-9版本
配置DHCP模板文件
vim /etc/cobbler/dhcp.template
subnet 192.168.100.0 netmask 255.255.255.0 { // 192.168.100.0 为网段
option routers 192.168.100.254; // 网关
option domain-name-servers 114.114.144.144; // dns
option subnet-mask 255.255.255.0; // 子网掩码
range dynamic-bootp 192.168.100.200 192.168.100.210; // 地址池
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
同步cobbler配置
[root@node1 ~]# systemctl restart httpd cobblerd
[root@node1 ~]# cobbler sync
task started: 2024-07-25_095147_sync
task started (id=Sync, time=Thu Jul 25 09:51:47 2024)
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 ***
挂载镜像
断开后设置
设置为rocky图形化的镜像,返回并连接
挂载
[root@node1 ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: source write-protected, mounted read-only.
[root@node1 ~]# cd /mnt/
[root@node1 mnt]# ls
AppStream BaseOS EFI images isolinux LICENSE media.repo
[root@node1 mnt]#
导入镜像
[root@node1 mnt]# cobbler import --path=/mnt/ --name=Rocky-9 arch=x86_64
--name // 自己命名
arch // 架构
查看cobbler镜像列表
[root@node1 mnt]# cobbler list
distros:
Rocky-9-x86_64
profiles:
Rocky-9-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
[root@node1 mnt]#
查看详细信息 查看指定的--name 接镜像名
[root@node1 mnt]# cobbler distro report --name Rocky-9-x86_64
Name : Rocky-9-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/Rocky-9-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/Rocky-9/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/Rocky-9/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Management Classes : []
OS Version : rhel9
Owners : ['admin']
Redhat Management Key :
Remote Boot Initrd : ~
Remote Boot Kernel : ~
Template Files : {}
创建kickstarts自动安装脚本
[root@node1 mnt]# cobbler profile get-autoinstall --name Rocky-9-x86_64 > /var/lib/cobbler/templates/rocky9.ks
修改脚本的内容
firewall --disable
// 设置yum源
repo --name=soure-1 --baseurl="http://192.168.100.10/cobbler/distro_mirror/AppStream"
repo --name=soure-2 --baseurl="http://192.168.100.10/cobbler/distro_mirror/BaseOS"
// 设置最小安装
@^minimal-environment
现在来执行脚本
[root@node1 ~]# 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
检查配置,在启动所需要的服务,
[root@node1 loaders]# cobbler sync
[root@node1 loaders]# systemctl restart httpd cobblerd rsyncd dhcpd
此时就可以去安装虚拟机了
手动安装
创建一个虚拟机然后打开虚拟机
选择Rocky-9进行安装
自动安装
使用浏览器访问https://192.168.100.10/cobbler_web
默认登录的用户名和密码都为cobbler
点击Actions--Sync,右上角有同步日志
同步成功