cobbler
cobbler简介
Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以用来快速构建Linux网络安装环境,大大简化Linux网络安装的配置流程。相比PXE的安装方式,cobbler配置简单,并且可以提供多个版本的操作系统以供选择。cobbler采用了基于命令行的方式进行管理,也提供了web管理界面,还提供了API接口,以方便二次开发使用。
cobbler官网:https://cobbler.github.io/
cobbler工作原理
cobbler工作原理如下图所示:
cobbler在启动后,需要首先进行自身的检查,检查无误后,就可以统筹开启TFTP、DHCP等的各种服务,等到客户端链接。客户端开机后,需要PXE启动的会使用DHCP协议向cobbler请求IP地址,cobbler在给客户端提供IP地址的同时也会告知客户端其下一跳的IP地址。之后客户端会使用TFTP协议请求加载文件,引导客户端启动并安装系统。同时,为了防止设备被重复安装,cobbler还会记录下该设备的安装信息,当该设备再次接入时,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 //查看配置信息
cobbler部署
#配置yum源
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
--2022-09-24 15:19:16-- https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 119.96.90.241, 119.96.90.242, 119.96.90.243, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|119.96.90.241|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2495 (2.4K) [application/octet-stream]
Saving to: '/etc/yum.repos.d/CentOS-Base.repo'
/etc/yum.repos.d/CentOS-B 100%[===================================>] 2.44K --.-KB/s in 0.002s
2022-09-24 15:19:17 (1.06 MB/s) - '/etc/yum.repos.d/CentOS-Base.repo' saved [2495/2495]
[root@localhost yum.repos.d]# ls
CentOS-Base.repo
[root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@localhost yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# dnf module enable cobbler:3 -y
Failed to set locale, defaulting to C.UTF-8
Extra Packages for Enterprise Linux 8 - x86_64 8.7 kB/s | 4.7 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 186 kB/s | 13 MB 01:10
Extra Packages for Enterprise Linux Modular 8 - x86_64 5.8 kB/s | 3.0 kB 00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64 119 kB/s | 733 kB 00:06
Last metadata expiration check: 0:00:05 ago on Sat Sep 24 15:22:12 2022.
Dependencies resolved.
======================================================================================================
Package Architecture Version Repository Size
======================================================================================================
Enabling module streams:
cobbler 3
Transaction Summary
======================================================================================================
Complete!
#安装cobbler以及相关的软件
[root@localhost yum.repos.d]# yum -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:15 ago on Sat Sep 24 15:22:12 2022.
Dependencies resolved.
#启动服务并设置开机自启
[root@localhost yum.repos.d]# systemctl restart httpd;systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost yum.repos.d]# systemctl enable --now rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
[root@localhost yum.repos.d]# systemctl enable --now tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
[root@localhost yum.repos.d]# systemctl enable --now cobblerd
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
#关闭防火墙和selinux
[root@localhost yum.repos.d]# systemctl disable --now firewalld
[root@localhost yum.repos.d]# setenforce 0
setenforce: SELinux is disabled
#修改server的ip地址为本机ip和next_server的ip改为本机IP
[root@localhost yum.repos.d]# vim /etc/cobbler/settings.yaml
server: 192.168.17.133
next_server: 192.168.17.133
#生成一下加密的密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" 'cobbler123'
$1$22984$ElSCMrSpOsVy2YQOolvJE0
#修改成刚生成的随机密码 cobbler的dhcp功能打开
[root@localhost ~]# vim /etc/cobbler/settings.yaml
default_password_crypted: "$1$22984$ElSCMrSpOsVy2YQOolvJE0"
manage_dhcp: true
#通过cobbler check 核对当前设置是否有问题,只需要解决问题1和问题2、3
[root@localhost share]# 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. 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, and yaboot.
2: reposync is not installed, install yum-utils or dnf-plugins-core
3: yumdownloader is not installed, install yum-utils or dnf-plugins-core
4: debmirror package is not installed, it will be required to manage debian deployments and repositories
5: 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解决办法
[root@localhost share]# yum -y install syslinux*
[root@localhost syslinux]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@localhost syslinux]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@localhost syslinux]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0
#问题2和问题3解决办法
[root@localhost syslinux]# yum -y install yum-utils
#配置DHCP模板文件
[root@localhost syslinux]# vim /etc/cobbler/dhcp.template
subnet 192.168.17.0 netmask 255.255.255.0 {
option routers 192.168.17.2;
option domain-name-servers 8.8.8.8;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.17.120 192.168.17.130;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
#同步cobbler配置
[root@localhost syslinux]# systemctl restart cobblerd.service
[root@localhost syslinux]# systemctl restart httpd
[root@localhost syslinux]# cobbler sync
task started: 2022-09-24_155546_sync
task started (id=Sync, time=Sat Sep 24 15:55:46 2022)
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 shell triggers from /var/lib/cobbler/triggers/change/*
shell triggers finished successfully
*** TASK COMPLETE ***
#挂载镜像
[root@localhost ~]# mount /dev/cdrom /mnt/
#导入镜像
[root@localhost ~]# cobbler import --path=/mnt/ --name=yqz arch=x86_64
#查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
yqz-x86_64
profiles:
yqz-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
#查看指定的镜像信息,指定镜像的name即可
[root@localhost ~]# cobbler distro report --name yqz-x86_64
Name : yqz-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/yqz-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/yqz/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/yqz/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Management Classes : []
OS Version : rhel8
Owners : ['admin']
Redhat Management Key :
Remote Boot Initrd : ~
Remote Boot Kernel : ~
Template Files : {}
#创建kickstarts自动安装脚本
[root@localhost ~]# cobbler profile get-autoinstall --name yqz-x86_64 > /var/lib/cobbler/templates/yqz.ks
#编辑
[root@localhost ~]# vim /var/lib/cobbler/templates/yqz.ks
...
firewall --disable //防火墙关闭
...
%packages
@^minimal-environment //设置安装最小化
#如果是生产环境,那么部署就已经完成,如果是虚拟机就还需执行以下步骤
[root@localhost ~]# cd /usr/share/cobbler/bin/
[root@localhost bin]# ls
migrate-data-v2-to-v3.py migrate-settings.sh mkgrub.sh settings-migration-v1-to-v2.sh
[root@localhost bin]# bash mkgrub.sh
[root@localhost bin]# cd /var/lib/cobbler/loaders/
[root@localhost loaders]# ll
total 72
drwxr-xr-x 2 root root 79 Sep 24 16:19 grub
lrwxrwxrwx 1 root root 31 Sep 24 16:19 ldlinux.c32 -> /usr/share/syslinux/ldlinux.c32
-rw-r--r-- 1 root root 26272 Sep 24 15:44 menu.c32
-rw-r--r-- 1 root root 42376 Sep 24 15:44 pxelinux.0
[root@localhost loaders]# cobbler sync
[root@localhost loaders]# systemctl restart httpd cobblerd rsyncd dhcpd