cobbler

Cobbler是一个用于自动化Linux服务器安装的工具,通过PXE、DHCP和DNS服务管理,简化了物理和虚拟机的部署过程。它支持Kickstart服务、YUM仓库管理和电源管理,且具备Web界面。安装Cobbler涉及配置源、安装软件、设置服务自启、修改配置文件、导入镜像、创建kickstart脚本等步骤,最后同步配置并重启服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

介绍

Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。

Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。

Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。

Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。

cobbler官网地址:官网.

cobbler集成的服务

  • PXE服务支持
  • DHCP服务管理
  • DNS服务管理(可选bind,dnsmasq)
  • 电源管理
  • Kickstart服务支持
  • YUM仓库管理
  • TFTP(PXE启动时需要)
  • Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

cobbler 安装

#配置epel源
[root@localhost ~]# yum install epel-release -y

#安装cobbler以及相关的软件
[root@localhost ~]# yum -y install dhcp-* tftp  python-ctypes xinetd pykickstart cobbler cobbler-web syslinux fence-agents


#设置开机自启
[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 cobblerd
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.

#修改server的IP为本机IP
[root@localhost ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.8.128/' /etc/cobbler/settings

#设置tftp的ip地址为本机ip
[root@localhost ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.8.128/' /etc/cobbler/settings

#生成加密密码
[root@localhost ~]# openssl passwd -1 
Password: 
Verifying - Password: 
$1$NKElOZdp$91xoMesMQ1n.KwbXsz9TB.

#将新生成的加密密码加入到配置文件
[root@localhost ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$Pke3JWSn$RwDn2joTPzf6QdwGfO/l7/"

 manage_dhcp: 1   //修改为1

#重启cobbler
[root@localhost ~]# systemctl restart cobblerd


#配置dhcp
[root@localhost ~]# vim /etc/cobbler/dhcp.template 
subnet 192.168.8.0 netmask 255.255.255.0 {
     option routers             192.168.8.128;
     option domain-name-servers 192.168.8.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.8.100 192.168.8.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;


#重启服务并同步配置
//重启服务并同步配置,改完dhcp必须要sync同步配置
[root@localhost cobbler]# systemctl restart cobblerd
[root@localhost cobbler]# cobbler sync
task started: 2021-10-13_192725_sync
task started (id=Sync, time=Wed Oct 13 19:27:25 2021)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
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/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

[root@localhost cobbler]# cd /var/lib/cobbler/loaders/
[root@localhost loaders]# ls
COPYING.syslinux  grub-x86_64.efi  menu.c32    README
COPYING.yaboot    grub-x86.efi     pxelinux.0  yaboot
[root@localhost loaders]# cp /usr/share/syslinux/menu.c32 menu.c32 
[root@localhost loaders]# cp /usr/share/syslinux/pxelinux.0 .

#导入镜像
[root@localhost ~]# mount /dev/cdrom  /mnt/
[root@localhost ~]# cobbler import --name=centos7 --arch=x86_64 --path=/mnt
task started: 2021-10-13_231256_import
task started (id=Media import, time=Wed Oct 13 23:12:56 2021)
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-x86_64:
creating new distro: centos8-x86_64
trying symlink: /var/www/cobbler/distro_mirror/centos8-x86_64 -> /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-x86_64 for centos8-x86_64
processing repo at : /var/www/cobbler/distro_mirror/centos8-x86_64/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/centos8-x86_64/AppStream
looking for /var/www/cobbler/distro_mirror/centos8-x86_64/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/centos8-x86_64/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/centos8-x86_64/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/centos8-x86_64/BaseOS
looking for /var/www/cobbler/distro_mirror/centos8-x86_64/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/centos8-x86_64/BaseOS/repodata

#说明
	--path	#镜像路径
	--name	#为安装源定义名字
	--arch	#指定安装平台


#查看镜像列表
[root@localhost ~]# cobbler list
distros:
   centos7-x86_64

profiles:
   centos7-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:


[root@localhost templates]# cobbler profile report centos7-x86_64
Name                           : centos7-x86_64
Automatic Installation Template : sample.ks
Automatic Installation Metadata : {}
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : centos7-x86_64
Enable gPXE?                   : False
Enable PXE Menu?               : True
Fetchable Files                : {}
DHCP Filename Override         : <<inherit>>
Kernel Options                 : {}
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


#创建kickstarts自动安装脚本
[root@localhost ~]# cat > /var/lib/cobbler/kickstarts/centos7.ks <<EOF
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.8.128/cobbler/ks_mirror/centos7-x86_64
$yum_repo_stanza
reboot

rootpw --iscrypted $6$hnAOxmuoZiHyD07l$xTFCSTRuwo6Ac3xS2Ebk0rUdgozLSwCOuw9idMHM9GrSJMOPJkPZfEGgt6ocu2Tle6t422NHRxfLHNVG19dF41

selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr

%packages
@^minimal
@core
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
EOF

#检查文件
[root@localhost templates]# cobbler validateks
task started: 2021-10-13_234113_validate_autoinstall_files
task started (id=Automated installation files validation, time=Wed Oct 13 23:41:13 2021)
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 templates]# cobbler profile edit --name centos7-x86_64  --kickstart=/var/lib/cobbler/kickstarts/centos7.ks

#配置网卡名称为传统网卡名称eth0
[root@localhost templates]# cobbler profile edit --name centos7-x86_64 --kopts='![net.ifnames=0 biosdevname=0](https://img-blog.csdnimg.cn/09417439b6f54ca4a95bffca4906ae5a.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBATmVhV2Fsa2U=,size_20,color_FFFFFF,t_70,g_se,x_16)
'

#同步cobbler
[root@localhost templates]# cobbler sync
task started: 2021-10-13_235517_sync
task started (id=Sync, time=Wed Oct 13 23:55:17 2021)
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/centos8-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/centos8-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: centos8-x86_64
trying hardlink /var/www/cobbler/distro_mirror/centos8-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/centos8-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos8-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos8-x86_64
trying hardlink /var/www/cobbler/distro_mirror/centos8-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/centos8-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos8-x86_64/initrd.img
Writing template files for centos8-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf

#重启服务
[root@localhost templates]# systemctl restart cobblerd.service 
[root@localhost templates]# systemctl restart httpd
[root@localhost templates]# systemctl restart xinetd


在这里插入图片描述

定制安装

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[root@localhost ~]# cobbler sync
task started: 2021-10-14_144625_sync
task started (id=Sync, time=Thu Oct 14 14:46:25 2021)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-2d-2f-da
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/grub/01-00-50-56-2D-2F-DA
removing: /var/lib/tftpboot/images/centos7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying distros to tftpboot
copying files for distro: centos7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7-x86_64/initrd.img
copying images
generating PXE configuration files
generating: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-2d-2f-da
generating: /var/lib/tftpboot/grub/01-00-50-56-2D-2F-DA
generating PXE menu structure
copying files for distro: centos7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7-x86_64/initrd.img
Writing template files for centos7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos7-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/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***
[root@localhost ~]# systemctl restart httpd.service cobblerd.service xinetd.service

在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值