Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。
使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP、DNS、TFTP、RSYNC以及yum仓库、构造系统ISO镜像。 Cobbler支持命令行管理,web界面管理,还提供了API接口,可以方便二次开发使用,Cobbler客户端Koan支持虚拟机安装和操作系统重新安装
Cobbler是通过将DHCP、TFTP、DNS、HTTP等服务进行集成,创建一个中央管理节点,其可以实现的功能有配置服务,创建存储库,解压缩操作系统媒介,代理或集成一个配置管理系统,控制电源管理等。 Cobbler的最终目的是实现无需进行人工干预即可安装机器。在进行进一步的操作之前,我们有必要先了解下pxe和kickstart 。
cobbler集成的服务
PEX概念
预启动执行环境(Preboot eXecution Environment,PXE,也被称为预执行环境)是让计算机通过网卡独立地使用数据设备(如硬盘)或者安装操作系统。Intel 搞出来的。
Kickstart 概述
Kickstart 是红帽开发的一种工具,我们可以简单理解为一个自动安装应答配置管理程序。通过读取这个配置文件,系统知道怎么去分区,要安装什么包,配什么IP,优化什么内核参数等等。其主要有以下部分组成:
Cobbler的设计方式
Cobbler 的配置结构基于一组注册的对象。每个对象表示一个与另一个实体相关联的实体(该对象指向另一个对象,或者另一个对象指向该对象)。当一个对象指向另一个对象时,它就继承了被指向对象的数据,并可覆盖或添加更多特定信息。以下对象类型的定义为:
关闭防火墙和selinux,然后重启
[root@localhost ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
[root@localhost ~]# reboot
连接断开
安装eple源和cobbler相关的软件
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install httpd dhcp-* tftp xinetd pykickstart
//开启cobbler源,然后再继续安装软件包
[root@localhost ~]# yum -y install module enable cobbler
[root@localhost ~]# yum -y install cobbler cobbler-web
启动HTTP的和cobblerd并设置开机自启
[root@centos-7 ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@centos-7 ~]# systemctl enable --now cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
[root@centos-7 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::443 :::*
更改配置文件中的IP地址,改成本机的IP地址
[root@localhost cobbler]# pwd
/etc/cobbler
[root@localhost cobbler]# vim settings
server: 192.168.164.128
next_server: 192.168.164.128
生成一个加密的密码,写入到配置文件中/etc/cobbler/settings
[root@centos-7 cobbler]# openssl passwd -1
Password:
Verifying - Password:
$1$.PmhBwFL$FlvmDEZ/lihDR8pHzFHki0
[root@centos-7 cobbler]# vim settings
default_password_crypted: "$1$.PmhBwFL$FlvmDEZ/lihDR8pHzFHki0"
//改完配置文件同步一下
[root@centos-7 cobbler]# cobbler sync
启动rsync并设置开机自启
[root@centos-7 ~]# systemctl enable --now rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
重启cobbler然后配置tftp
[root@centos-7 ~]# systemctl restart cobblerd.service
[root@centos-7 ~]# vim /etc/xinetd.d/tftp
service tftp
{
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -B 1380 -v -s /var/lib/tftpboot
per_source = 11
cps = 100 2
flags = IPv4
}
执行检查环境命令
[root@centos-7 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.
//解决办法
1、centos8中的同样目录中的文件移动到/var/lib/cobbler/loaders
cd loaders
cp /usr/share/syslinux/pxelinux.0 . //把本地的文件复制到当前目录一共8个文件 下面的图
cp /usr/share/syslinux/menu.c32 .
......
......
2、第二个可以忽略不管,此次部署用不到
3、 yum -y install fence-agents
重启并同步一下
[root@centos-7 loaders]# systemctl restart cobblerd.service
[root@centos-7 loaders]# cobbler sync
打开DHCP功能,并配置DHCP模板文件
[root@centos-7 cobbler]# cd /etc/cobbler/
[root@centos-7 cobbler]# vim settings
manage_dhcp: 1 //用cobbler管理dhcp
[root@centos-7 cobbler]# pwd
/etc/cobbler
[root@centos-7 cobbler]# vim dhcp.template
subnet 192.168.164.0 netmask 255.255.255.0 { //改成自己的网段
option routers 192.168.164.128; //本机得IP地址做为网关
option domain-name-servers 192.168.164.2; //dns 域名解析
option subnet-mask 255.255.255.0; //子网掩码
range dynamic-bootp 192.168.164.100 192.168.164.254; //地址范围
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
//重启并同步
[root@centos-7 cobbler]# systemctl restart cobblerd.service
[root@centos-7 cobbler]# cobbler sync
//查看DHCP是以打开
[root@centos-7 cobbler]# netstat -anulp | grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 46506/dhcpd
#如果找不到命令则需要安装依赖包 yum -y install net-tools
导入镜像
//挂载光盘
[root@centos-7 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
//导入镜像,会把镜像导入到/var/www/cobbler中。
[root@centos-7 ~]# cobbler import --path=/mnt --name=centos-7 --arch=x86_64
task started: 2021-10-13_201750_import
task started (id=Media import, time=Wed Oct 13 20:17:50 2021)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/centos-7-x86_64:
creating new distro: centos-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos-7-x86_64 -> /var/www/cobbler/links/centos-7-x86_64
creating new profile: centos-7-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/ks_mirror/centos-7-x86_64 for centos-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos-7-x86_64 //镜像导入的位置
need to process repo/comps: /var/www/cobbler/ks_mirror/centos-7-x86_64
looking for /var/www/cobbler/ks_mirror/centos-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos-7-x86_64/repodata
*** TASK COMPLETE ***
# --path //镜像路径
# --name //为安装源定义一个名字
# --arch //指定安装源平台
查看镜像列表,当中列着发行版和配置文件
[root@centos-7 ~]# cobbler list
distros:
centos-7-x86_64 //发行版
profiles:
centos-7-x86_64 //配置文件
systems:
repos:
images:
mgmtclasses:
packages:
files:
//配置文件位置,里面是镜像文件内容
[root@centos-7 centos-7-x86_64]# pwd
/var/www/cobbler/ks_mirror/centos-7-x86_64
[root@centos-7 ks_mirror]# cd centos-7-x86_64/
[root@centos-7 centos-7-x86_64]# ll
总用量 316
-rw-rw-r-- 1 root root 14 5月 2 2018 CentOS_BuildTag
drwxr-xr-x 3 root root 35 5月 4 2018 EFI
-rw-rw-r-- 1 root root 227 8月 30 2017 EULA
-rw-rw-r-- 1 root root 18009 12月 10 2015 GPL
drwxr-xr-x 3 root root 57 5月 4 2018 images
drwxr-xr-x 2 root root 198 5月 4 2018 isolinux
drwxr-xr-x 2 root root 43 5月 4 2018 LiveOS
drwxrwxr-x 2 root root 225280 5月 4 2018 Packages
drwxrwxr-x 2 root root 4096 5月 4 2018 repodata
-rw-rw-r-- 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root 2883 5月 4 2018 TRANS.TBL
创建kickstarts自动安装脚本
这个脚本是系统安装时的操作,也就是装系统的时候让你设置的时区、密码、最小化等等。这里写成了一个脚本
[root@centos-7 kickstarts]# pwd
/var/lib/cobbler/kickstarts
[root@centos-7 kickstarts]# cat centos-7-x86_64.ks
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.164.128/cobbler/ks_mirror/centos-7-x86_64
$yum_repo_stanza
reboot
//密码,这要把本机/root/anaconda-ks.cfg中的密码复制过来,这样新的虚拟机就和本机密码一样了
rootpw --iscrypted $6$zFsJQ/RU46s0ghKG$EivXcNIpN7//7GqVtVNhLgKoiLU6KHUCHy8UtADI4QMCrxN.qbHb9wDnY7AqYkHjUA7KUE5tWVN9MuCYhF6c..
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
检查ks文件是否有语法等问题
[root@centos-7 kickstarts]# cobbler validateks
task started: 2021-10-13_204834_validateks
task started (id=Kickstart Validation, time=Wed Oct 13 20:48:34 2021)
----------------------------
osversion: rhel7
checking url: http://192.168.164.128/cblr/svc/op/ks/profile/centos-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.164.128/cblr/svc/op/ks/profile/centos-7-x86_64"
received on stdout:
received on stderr:
*** all kickstarts seem to be ok *** //没有问题,进行下一步即可
*** TASK COMPLETE ***
查看当前cobbler有哪些配置文件
[root@centos-7 kickstarts]# cobbler profile list
centos-7-x86_64
//查看当前系统使用的配置文件是不是刚刚创建的脚本,如果不是要修改
[root@centos-7 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
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Repos : []
Server Override : <<inherit>>
Template Files : {}
Virt Auto Boot : 1
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
//修改kickstart,把刚刚创建的ks文件设置为默认的文件kickstart
[root@localhost ~]# cobbler profile edit --name rhel-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/rhel-7-x86_64.ks
设置网卡,设置成传统命名网卡eth,这样网卡的名字就都一样了便于日后统一管理
[root@centos-7 kickstarts]# cobbler profile edit --name centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
此时再去查看系统信息,内核参数和kickstart都已经设置好了
[root@centos-7 ~]# 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 : {'biosdevname': '0', 'net.ifnames': '0'}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/centos-7-x86_64.ks
......
......
同步cobbler
[root@centos-7 ~]# cobbler sync
task started: 2021-10-13_210633_sync
task started (id=Sync, time=Wed Oct 13 21:06:33 2021)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos-7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos-7-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
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 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 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@centos-7 ~]# systemctl restart xinetd.service //tftp是基于xinetd的,也就受xinetd管理
[root@centos-7 ~]# systemctl restart cobblerd.service
[root@centos-7 ~]# systemctl restart httpd.service
[root@centos-7 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 :::873 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::443 :::*
创建虚拟机
镜像不选 网络选择NAT模式
启动虚拟机待出现蓝色界面就代表部署成功 开始装系统
定制安装步骤:
同步配置和重启服务
[root@localhost ~]# cobbler sync
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart xinetd