是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等
可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用
批量装机 cobbler
PXE的基础上进行封装
-
优点
较早前的kickstart的升级版,容易配置, 自带web界面比较易于管理 内置了一个轻量级配置管理系统, 支持和其它配置管理系统集成
cobbler集成的服务
PXE服务支持 DHCP服务管理 DNS服务管理(可选bind,dnsmasq) 电源管理 Kickstart服务支持 YUM仓库管理 TFTP(PXE启动时需要) Apache(提供kickstart的安装源,并提供定制化的kickstart配置)cobbler服务端部署(镜像:SO7.5)
#关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
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
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum -y install epel-release vim wget
[root@localhost ~]# yum -y install httpd dhcp-* tftp xinetd pykickstart
#然后进行安装并开启
[root@localhost ~]# yum -y install cobbler cobbler-web
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start cobblerd
[root@localhost ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl enable cobblerd
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:25151 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 *:443 *:*
[root@localhost ~]# vim /etc/cobbler/settings.yaml
# if you do not set this correctly, this will be manifested in TFTP open timeouts.
next_server: 192.168.230.133
# (dual homed, etc), you need to read the --server-override section
# of the manpage for how that works.
server: 192.168.230.133
[root@localhost ~]# openssl passwd -1
Password:
Verifying - Password:
$1$XYuTkg4b$3rkZk/y7/uSZQXj1nhHC5.
[root@localhost ~]# cd /etc/cobbler
[root@localhost cobbler]# vim settings.yaml
# and put the output between the "" below.
default_password_crypted: "$1$HIhP3YqD$Y/SpYdsxt3H4G8bdZdxQf.
"
# the choice of DHCP management engine is in /etc/cobbler/modules.conf
manage_dhcp: true
[root@localhost cobbler]# vi /etc/cobbler/dhcp.template
subnet 192.168.230.0(需要修改) netmask 255.255.255.0 {
option routers 192.168.230.133; #修改为主机ip
option domain-name-servers 192.168.230.2; #需要修改
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.230.100 192.168.230.254; #需要修改
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
[root@localhost cobbler]# systemctl start cobblerd.service
[root@localhost cobbler]# systemctl enable cobblerd.service
[root@localhost cobbler]# systemctl status cobblerd.service
● cobblerd.service - Cobbler Helper Daemon
Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; enabled; vendor preset: disab>
Active: active (running) since Tue 2021-10-12 06:21:28 EDT; 1min 39s ago
Main PID: 316313 (cobblerd)
Tasks: 1 (limit: 4743)
Memory: 39.6M
CGroup: /system.slice/cobblerd.service
└─316313 /usr/bin/python3.6 -s /usr/bin/cobblerd -F
10月 12 06:21:28 localhost.localdomain systemd[1]: Starting Cobbler Helper Daemon...
10月 12 06:21:28 localhost.localdomain systemd[1]: Started Cobbler Helper Daemon.
10月 12 06:21:34 localhost.localdomain dhcpd[316634]: ldap_gssapi_principal is not set,GSS>
10月 12 06:21:34 localhost.localdomain dhcpd[316634]: Not searching LDAP since ldap-server>
10月 12 06:21:34 localhost.localdomain dhcpd[316634]: Source compiled to use binary-leases
[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, 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
#第一个问题是在OS7.5上面无法解决的,但是SO 8上面可以下载下来,所以我直接拖的文件,可以进行忽略
#第二个问题安装了,不行,问题不大,可以进行忽略
[root@localhost cobbler]# cobbler sync
task started: 2021-10-12_063153_sync
task started (id=Sync, time=Tue Oct 12 06:31:53 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/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
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 ***
#查看DHCP进程
[root@localhost cobbler]# netstat -anulp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 129350/dhcpd
#导入redhat7镜像
[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# cobbler import --path=/mnt --name=centos-7 --arch=x86_64
task started: 2021-10-13_192743_import
task started (id=Media import, time=Wed Oct 13 19:27:43 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 ***
#查看创建的发行版和配置文件(如果没有就是配置错误)
[root@localhost www]# cobbler list
distros:
centos-7-x86_64
profiles:
centos-7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
#创建kickstarts自动安装脚本
[root@localhost www]# cat > /var/lib/cobbler/kickstarts/centos-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://192.168.230.133/cobbler/ks_mirror/centos-7-x86_64
> $yum_repo_stanza
> reboot
>
> rootpw --iscrypted $6$pyWYNn.6nhfr7OFP$meVh19D/019XfS/BEUKZ.wfD4LOcajkPSK1eGEqOe0dGjTp5FFVQ9428GqV.0v56qGXe2hJSko0szReX0geBa/ #看你自己主机是什么就是什么
>
> 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 www]# cd /var/lib/cobbler/kickstarts/
[root@localhost kickstarts]# cobbler profile list
centos-7-x86_64
[root@localhost 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 : <>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <>
Red Hat Management Server : <>
Repos : []
Server Override : <>
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
[root@localhost kickstarts]# cobbler profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.ks
[root@localhost kickstarts]# cobbler profile edit --name centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
[root@localhost kickstarts]# cobbler profile reportName : 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
Kickstart metadata : {}
Management Classes : []
Management Parameters : <>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <>
Red Hat Management Server : <>
Repos : []
Server Override : <>
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
[root@localhost ~]# cobbler sync
[root@localhost ~]# systemctl restart xinetd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# 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 :::*
接下来就是客户端安装
新建虚拟机从pxe启动,若出现以下界面则表示成功:
4. 定制安装
定制安装步骤:
统计服务器mac地址
配置cobbler
安装
统计mac地址此处就不赘述了,直接最重要的配置
在 cobbler 的web界面上配置:
/同步一下然后重启 [root@localhost ~]# cobbler sync [root@localhost ~]# systemctl restart xinetd [root@localhost ~]# systemctl restart httpd [root@localhost ~]# systemctl restart cobblerd



