Cobbler 是一个系统启动服务(boot server),可以通过网络启动(PXE)的方式用来快速安装、重装物理服务器和虚拟机,支持安装不同的 Linux 发行版和 Windows。该工具使用python开发,小巧轻便(才15k行代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP,DNS,以及yum包镜像。
Cobbler 使用命令行方式管理,也提供了基于 Web 的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
1、PXE服务支持
2、DHCP服务管理
3、DNS服务管理(可选bind,dnsmasq)
4、电源管理
5、Kickstart服务支持
6、yum仓库管理
7、TFTP (PXE启动时需要)
8、Apache(提供kickstart 的安装源,并提供定制化的kickstart配置)
同时,它和apache做了深度整合。通过 cobbler,可以实现对RedHat/Centos/Fedora系统的快速部署,同时也支持Suse 和Debian(Ubuntu)系统,通过配置也支持windows。
Server端:
第一步,启动Cobbler服务
第二步,进行Cobbler错误检查,执行cobbler check命令
第三步,进行配置同步,执行cobbler sync命令
第四步,复制相关启动文件文件到TFTP目录中
第五步,启动DHCP服务,提供地址分配
第六步,DHCP服务分配IP地址
第七步,TFTP传输启动文件
第八步,Server端接收安装信息
第九步,Server端发送ISO镜像与Kickstart文件
Client端:
第一步,客户端以PXE模式启动
第二步,客户端获取IP地址
第三步,通过TFTP服务器获取启动文件
第四步,进入Cobbler安装选择界面
第五步,客户端确定加载信息
第六步,根据配置信息准备安装系统
第七步,加载Kickstart文件
第八步,传输系统安装的其它文件
第九步,进行安装系统
环境 | ip地址 |
---|---|
centos7 | 192.168.143.139 |
// 关闭防火墙和selinux本机已做
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX=disabled can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
[root@localhost ~]# reboot
[root@localhost ~]# getenforce
Disabled
root@139 ~]# yum install -y epel-release
//安装cobbler以及相关的软件
[root@139 ~]# yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart
//启动服务并设置开机自启
[root@139 ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@139 ~]# systemctl enable --now cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
[root@139 ~]# vim /etc/cobbler/settings
serever:192.168.143.139
next_server: 192.168.143.139
[root@139 ~]# openssl passwd -1
Password:
Verifying - Password:
$1$wq6R.yUR$cYR1jJRosArFMa0LZZG1q0
[root@139 cobbler]# vim /etc/cobbler/settings
###
default_password_crypted: "$1$wq6R.yUR$cYR1jJRosArFMa0LZZG1q0" #修改
###
[root@139 cobbler]# systemctl enable --now rsyncd
[root@139 cobbler]# vim /etc/xinetd.d/tftp
###
disable = no #修改
###
//通过cobbler check 核对当前设置是否有问题
[root@139 cobbler]# 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, you may run 'cobbler get-loaders' to download them, or, 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, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
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.
[root@139 ~]# yum -y install fence-agents
[root@139 cobbler]# cd /var/lib/cobbler/loaders/
[root@139 loaders]# ls
[root@139 loaders]# pwd
/var/lib/cobbler/loaders
###提供loaders/压缩包直链,https://wwe.lanzoui.com/ilf1Cvbcvsd
# 因为centos7版本无法生成文件,这是centos8传来的
[root@139 cobbler]# tar xf loaders.tar.gz
[root@139 cobbler]# ls loaders
collections grub_config lock snippets triggers webui_sessions
distro_signatures.json loaders scripts templates web.ss
[root@139 ~]# cd /etc/cobbler/
[root@139 cobbler]# vim settings
###
manage_dhcp: 1
###
[root@139 cobbler]# vim dhcp.template
###
subnet 192.168.143.0 netmask 255.255.255.0 {
#修改
option routers 192.168.143.139; #修改
option domain-name-servers 192.168.143.2; # 修改
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.143.200 192.168.143.254; #修改
###
[root@139 cobbler]# systemctl restart cobblerd
[root@139 cobbler]# cobbler sync
[root@139 cobbler]# netstat -anulp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 13320/dhcpd
[root@139 cobbler]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@139 cobbler]# ls /mnt
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
[root@139 cobbler]# cobbler import --path=/mnt --name=centos-7 --arch=x86_64
[root@139 ~]# cd /var/www/cobbler
[root@139 cobbler]# ls ks_mirror/centos-7-x86_64/
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
[root@139 cobbler]#
[root@139 cobbler]# cobbler list
distros:
centos-7-x86_64
profiles:
centos-7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
//创建kickstarts自动安装脚本
[root@139 cobbler]# cat > /var/lib/cobbler/kickstarts/rhel-7-x86_64.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://172.16.12.128/cobbler/ks_mirror/rhel-7-x86_64 #修改的链接
$yum_repo_stanza
reboot
rootpw --iscrypted $6$2WTFvfNvAMgCUPuC$MJgWGzhakgxrRObcEbAwSe8vkz0s//xyiTllGwxRsHHruQhcskO69u2LVTU9u0eemHXH2pzcGawyAJ54R2E/x0 #修改的密码
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@139 cobbler]# cd
[root@139 ~]# cd /var/lib/cobbler/kickstarts/
[root@139 kickstarts]# ls
default.ks install_profiles rhel-7-x86_64.ks sample_esx4.ks sample_esxi6.ks sample.seed
esxi4-ks.cfg legacy.ks sample_autoyast.xml sample_esxi4.ks sample.ks sample.seed.28
esxi5-ks.cfg pxerescue.ks sample_end.ks sample_esxi5.ks sample_old.seed
[root@139 kickstarts]# mv rhel-7-x86_64.ks centos-7-x86_64.ks
[root@139 kickstarts]#
[root@139 kickstarts]# ls
centos-7-x86_64.ks install_profiles sample_end.ks sample_esxi6.ks sample.seed.28
default.ks legacy.ks sample_esx4.ks sample.ks
esxi4-ks.cfg pxerescue.ks sample_esxi4.ks sample_old.seed
esxi5-ks.cfg sample_autoyast.xml sample_esxi5.ks sample.seed
[root@139 kickstarts]# vim centos-7-x86_64.ks
替换密码 文件链接位置
###
# Root password
rootpw --iscrypted $6$o.KUbTGeilEbPTwv$.k4r6XZAFPFOTU9G4cYSOUoVcM0UEIfvtMV.iZxsAep5rtXbt9jG9rar8aTT1.ruvbPg/GakalCbSN0UsdQ2c0 # 修改
url --url=http://192.168.143.139/cobbler/ks_mirror/centos-7-x86_64 # 修改
###
[root@139 kickstarts]# cobbler validateks #检查
task started: 2021-10-14_004455_validateks
task started (id=Kickstart Validation, time=Thu Oct 14 00:44:55 2021)
----------------------------
osversion: rhel7
checking url: http://192.168.143.139/cblr/svc/op/ks/profile/centos-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.143.139/cblr/svc/op/ks/profile/centos-7-x86_64"
received on stdout:
received on stderr:
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***
[root@139 kickstarts]# cobbler profile list
centos-7-x86_64
[root@139 kickstarts]# cobbler profile report
Name : centos-7-x86_64
TFTP Boot Files : {
}
Comment :
DHCP Tag : default
Distribution : centos-7-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {
}
Kernel Options : {
}
Kernel Options (Post Install) : {
}
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks
[root@139 kickstarts]# cobbler profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.ks
[root@139 kickstarts]#
[root@139 kickstarts]# cobbler sync
task started: 2021-10-14_005029_sync
task started (id=Sync, time=Thu Oct 14 00:50:29 2021)
//为避免发生未知问题,先把服务端所有服务重启
[root@139 kickstarts]# systemctl restart httpd cobblerd xinetd
访问http://192.168.143.139/cobbler_web提示没有权限
Forbidden
You don’t have permission to access /cobbler_web on this server.
解决方案
使用https地址访问: https://192.168.143.139/cobbler_web
在浏览器上添加例外或者换成微软浏览器访问
账号密码都为cobbler
// 同步重启
[root@139 systems.d]# cobbler sync
task started: 2021-10-14_153209_sync
task started (id=Sync, time=Thu Oct 14 15:32:09 2021)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos-7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-30-8b-c4
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-20-e0-2a
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/01-00-50-56-30-8B-C4
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/grub/01-00-50-56-20-E0-2A
removing: /var/lib/tftpboot/images/centos-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
copying distros to tftpboot
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos-7-x86_64/initrd.img
copying images
generating PXE configuration files
generating: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-20-e0-2a
generating: /var/lib/tftpboot/grub/01-00-50-56-20-E0-2A
generating PXE menu structure
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos-7-x86_64/initrd.img
Writing template files for centos-7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos-7-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@139 systems.d]# systemctl restart httpd cobblerd xinetd
[root@139 systems.d]#
[root@139 systems.d]# pwd
/var/lib/cobbler/config/systems.d
[root@139 systems.d]# ls
test.json
[root@139 systems.d]# cat test.json
{
"comment": "", "status": "production", "kickstart": "/var/lib/cobbler/kickstarts/centos-7-x86_64.ks", "name_servers_search": [], "ks_meta": {
}, "kernel_options_post": {
}, "image": "", "redhat_management_key": "<>" , "virt_path": "<>" , "power_user": "", "kernel_options": {
"biosdevname": "0", "net.ifnames": "0"}, "ctime": 1634195518.830579, "name_servers": ["114.114.114.114"], "mtime": 1634196717.134878, "enable_gpxe": false, "template_files": {
}, "gateway": "192.168.143.2", "uid": "MTYzNDE5NTUxOC44MzE5NDE5NTUuMDMxMDY", "virt_auto_boot": 0, "power_type": "amt_ws", "virt_cpus": "<>" , "mgmt_parameters": "<>" , "boot_files": {
}, "hostname": "servera.example.com", "repos_enabled": false, "mgmt_classes": [], "power_pass": "", "netboot_enabled": true, "ipv6_autoconfiguration": false, "profile": "centos-7-x86_64", "virt_type": "xenpv", "interfaces": {
"eth0": {
"ipv6_address": "", "interface_type": "", "static": true, "cnames": [], "bridge_opts": "", "management": false, "interface_master": "", "mac_address": "00:50:56:20:E0:2A", "ipv6_prefix": "", "virt_bridge": "xenbr0", "netmask": "255.255.255.0", "bonding_opts": "", "ip_address": "192.168.143.140", "dhcp_tag": "", "ipv6_mtu": "", "static_routes": [], "ipv6_static_routes": [], "if_gateway": "", "dns_name": "", "mtu": "", "connected_mode": false, "ipv6_secondaries": [], "ipv6_default_gateway": ""}}, "power_address": "", "proxy": "<>" , "fetchable_files": {
}, "virt_file_size": "<>" , "ldap_enabled": false, "monit_enabled": false, "ipv6_default_device": "", "virt_pxe_boot": 0, "virt_disk_driver": "<>" , "owners": "<>" , "name": "test", "virt_ram": "<>" , "power_id": "", "server": "<>" , "redhat_management_server": "<>" , "depth": 2, "ldap_type": "authconfig", "template_remote_kickstarts": 0}
[root@139 systems.d]#