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配置文件详解
cobbler配置文件目录在/etc/cobbler
| 配置文件 | 作用 |
|---|---|
| /etc/cobbler/settings | 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 | 模块的配置文件 |
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仓库存储目录 |
cobbler日志文件
| 日志文件路径 | 说明 |
|---|---|
| /var/log/cobbler/installing | 客户端安装日志 |
| /var/log/cobbler/cobbler.log | cobbler日志 |
cobbler命令详解
cobbler check //核对当前设置是否有问题 cobbler list //列出所有的cobbler元素 cobbler report //列出元素的详细信息 cobbler sync //同步配置到数据目录,更改配置最好都要执行下 cobbler reposync //同步yum仓库 cobbler distro //查看导入的发行版系统信息 cobbler system //查看添加的系统信息 cobbler profile //查看配置信息2. cobbler服务端部署
//关闭防火墙 [root@localhost ~]# systemctl disable --now firewalld.service [root@localhost ~]# setenforce 0 [root@localhost ~]# vim /etc/selinux/config SELINUX=disabled [root@localhost ~]# reboot //下载所需的软件包 [root@localhost ~]# yum -y install epel-release git dhcp-* tftp pykickstart xinetd [root@localhost ~]# yum -y module enable cobbler [root@localhost ~]# yum -y install cobbler cobbler-web
//给服务设置开机自启 [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 tftp Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket. [root@localhost ~]# systemctl enable --now cobblerd.service Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
//生成密码 [root@localhost ~]# openssl passwd -1 -salt "$RANDOM" 'abc123' $1$21353$8OA27aHZIzp5OE9sssyrL0 [root@localhost ~]#
//修改配置文件 [root@localhost ~]# vim /etc/cobbler/settings server: 192.168.200.142 //修改为本地ip next_server: 192.168.200.142 //修改为本机ip .... //此处为省略内容 default_password_crypted: "$1$28958$sq1sJFDX0bZo.H8Q.8NLg0" //将新生成的加密密码加入到配置文件 ..... //此处为省略内容
//重启cobbler
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl status cobblerd.service
[root@localhost ~]# cobbler check
解决报错
[root@localhost ~]# yum -y install fence-agents debmirror yum-utils syslinux
[root@localhost ~]# sed -i 's|@dists=.*|#@dists=|' /etc/debmirror.conf
[root@localhost ~]# sed -i 's|@arches=.*|#@arches=|' /etc/debmirror.conf
[root@localhost ~]# systemctl restart cobblerd.service
[root@localhost ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp
[root@localhost ~]# cat /etc/xinetd.d/tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no //这里改为no
per_source = 11
cps = 100 2
flags = IPv4
}
[root@localhost ~]# systemctl enable --now rsyncd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler check //结果会报错,不管他 后面cobbler sync不报错就行
//配置dhcp
[root@localhost ~]# sed -i '/^manage_dhcp/s/0/1/' /etc/cobbler/settings
[root@localhost ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1
[root@localhost ~]# cat /etc/cobbler/dhcp.template
subnet 192.168.200.0 netmask 255.255.255.0 { //网段改为自己主机网段
option routers 192.168.200.142; //改为自己主机IP地址
option domain-name-servers 192.168.200.2; //网关改为自己主机网关
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.200.200 192.168.200.254; //可以部署的主机数量也改成自己主机网段
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
//重启服务并同步配置,改完dhcp必须要sync同步配置 [root@localhost ~]# systemctl restart cobblerd [root@localhost ~]# cobbler sync task started: 2021-10-13_110228_sync task started (id=Sync, time=Wed Oct 13 11:02:28 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/rhel-8-x86_64 removing: /var/lib/tftpboot/pxelinux.cfg/default removing: /var/lib/tftpboot/grub/system removing: /var/lib/tftpboot/grub/system_link removing: /var/lib/tftpboot/grub/images removing: /var/lib/tftpboot/grub/x86_64_menu_items.cfg removing: /var/lib/tftpboot/images/rhel-8-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: rhel-8-x86_64 trying hardlink /var/www/cobbler/distro_mirror/rhel-8-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/rhel-8-x86_64/vmlinuz trying hardlink /var/www/cobbler/distro_mirror/rhel-8-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/rhel-8-x86_64/initrd.img copying images generating PXE configuration files generating PXE menu structure copying files for distro: rhel-8-x86_64 trying hardlink /var/www/cobbler/distro_mirror/rhel-8-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/rhel-8-x86_64/vmlinuz trying hardlink /var/www/cobbler/distro_mirror/rhel-8-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/rhel-8-x86_64/initrd.img Writing template files for rhel-8-x86_64 processing boot_files for distro: rhel-8-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 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 *** //这里是complete就是对的
//检查dhcp是否正常
[root@localhost ~]# ss -anulp|grep dhcp
UNCONN 0 0 *:67 *:* users:(("dhcpd",pid=82889,fd=7))
[root@localhost ~]#
[root@localhost ~]# mount /dev/sr0 /mnt //导入centos7镜像 [root@localhost ~]# mount /dev/sr0 /mnt/ mount: /dev/sr0 写保护,将以只读方式挂载 [root@localhost ~]# [root@localhost ~]# cobbler import --path=/mnt --name=centos-7 --arch=x86_64 task started: 2021-10-13_112317_import task started (id=Media import, time=Wed Oct 13 11:23:17 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 ~]# cd /var/www/cobbler/ks_mirror/ [root@localhost ks_mirror]# ls centos-7-x86_64 config [root@localhost ~]# cobbler list distros: centos-7-x86_64 profiles: centos-7-x86_64 systems: repos: images: mgmtclasses: packages: files:
//创建kickstarts自动安装脚本 查看主机上默认的文件,进行对比更改 [root@localhost ~]# cat anaconda-ks.cfg #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation media cdrom # Use graphical install graphical # Run the Setup Agent on first boot firstboot --enable ignoredisk --only-use=sda # Keyboard layouts keyboard --vckeymap=cn --xlayouts='cn' # System language lang zh_CN.UTF-8 # Network information network --bootproto=dhcp --device=ens33 --ipv6=auto --activate network --hostname=localhost.localdomain # Root password rootpw --iscrypted $6$yjjcqhzrGUFZH4KP$99Dume6ZsJn3IN51w/2lNc2ihRmfddQTEYtvINSl7mXwvtyXzW72xAwSYXYDJaXl2zz7rM1FXNJcwYiRYlwtq0 # System services services --disabled="chronyd" # System timezone timezone Asia/Shanghai --isUtc --nontp user --name=admin --password=$6$0WffW9n25DjOWwxp$II2AaIoKb5xXIGOpMujIFWjEZ.nNO9nyaaazMf3JJP7K7Vrfc0mueMK9bapDV2cy81z2f90ryqr3Pg9sWLd6z1 --iscrypted --gecos="admin" # System bootloader configuration bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda autopart --type=lvm # Partition clearing information clearpart --none --initlabel %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 //我们自己编写的一个文件 [root@localhost ~]# cat /var/lib/cobbler/kickstarts/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.153.146/cobbler/ks_mirror/centos-7-x86_64 //此目录为/var/www/cobbler/ks_mirror/centos-7-x86_64/这个cobbler目录 $yum_repo_stanza reboot rootpw --iscrypted $6$yjjcqhzrGUFZH4KP$99Dume6ZsJn3IN51w/2lNc2ihRmfddQTEYtvINSl7mXwvtyXzW72xAwSYXYDJaXl2zz7rM1FXNJcwYiRYlwtq0 //改为主机上的密码 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 //查看cobbler镜像列表 [root@localhost ~]# cobbler list [root@localhost ~]# cobbler list distros: centos-7-x86_64 profiles: centos-7-x86_64 systems: repos: images: mgmtclasses: packages: files:
//检查ks文件语法是否有误
[root@localhost ~]# cobbler validateks
task started: 2021-10-13_115841_validateks
task started (id=Kickstart Validation, time=Wed Oct 13 11:58:41 2021)
----------------------------
osversion: rhel7
checking url: http://192.168.200.142/cblr/svc/op/ks/profile/centos-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.200.142/cblr/svc/op/ks/profile/centos-7-x86_64"
received on stdout:
received on stderr:
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***
[root@localhost ~]#
//查看当前cobbler有哪些配置文件
[root@localhost ~]# 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
//修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@localhost ~]# cobbler profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.ks
[root@localhost ~]# 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/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
//配置网卡名称为传统网卡名称eth0
[root@localhost ~]# cobbler profile edit --name centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
[root@localhost ~]# 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
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
task started: 2021-10-13_120236_sync
task started (id=Sync, time=Wed Oct 13 12:02:36 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/efidefault
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 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@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 :::*
//安装虚拟机时连接超时解决办法
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@localhost ~]#
[root@localhost ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
3. 客户端安装
创建一台没有镜像的虚拟机做客户端进行安装
定制安装步骤:
- 统计服务器mac地址
- 配置cobbler
- 安装
统计mac地址直接最重要的配置
在 cobbler 的web界面上配置
通过web网页访问
同步配置并重启相关服务:
[root@localhost ~]# cobbler sync [root@localhost ~]# systemctl restart httpd [root@localhost ~]# systemctl restart cobblerd [root@localhost ~]# systemctl restart xinetd



