cobbler
cobbler
1. cobbler简介
Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
puppet是一种Linux、Unix、windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet的设计目标是简化对这些资源的管理以及妥善处理资源间的依赖关系。
puppet采用C/S星状的结构,所有的客户端和一个或几个服务器交互。每个客户端周期的(默认半个小时)向服务器发送请求,获得其最新的配置信息,保证和该配置信息同步。每个puppet客户端每半小时(可以设置)连接一次服务器端, 下载最新的配置文件,并且严格按照配置文件来配置客户端. 配置完成以后,puppet客户端可以反馈给服务器端一个消息. 如果出错,也会给服务器端反馈一个消息
cobbler官网:https://cobbler.github.io/
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服务端部署
配置yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf *
[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 01:02:12-- https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 58.49.162.241, 58.49.162.239, 58.49.162.238, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|58.49.162.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/Ce 100%[================>] 2.44K --.-KB/s in 0.01s
2022-09-24 01:02:12 (242 KB/s) - '/etc/yum.repos.d/CentOS-Base.repo' saved [2495/2495]
[root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.aliyun.com 398 kB/s | 4.6 MB 00:11
CentOS-8.5.2111 - Extras - mirrors.aliyun.co 9.2 kB/s | 10 kB 00:01
CentOS-8.5.2111 - AppStream - mirrors.aliyun 260 kB/s | 8.4 MB 00:33
Last metadata expiration check: 0:00:01 ago on Sat Sep 24 01:04:53 2022.
epel-release-latest-8.noarch.rpm 65 kB/s | 24 kB 00:00
Dependencies resolved.
=============================================================================
Package Architecture Version Repository Size
=============================================================================
Installing:
epel-release noarch 8-17.el8 @commandline 24 k
Transaction Summary
=============================================================================
Install 1 Package
Total size: 24 k
Installed size: 34 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : epel-release-8-17.el8.noarch 1/1
Running scriptlet: epel-release-8-17.el8.noarch 1/1
Many EPEL packages require the CodeReady Builder (CRB) repository.
It is recommended that you run /usr/bin/crb enable to enable the CRB repository.
Verifying : epel-release-8-17.el8.noarch 1/1
Installed products updated.
Installed:
epel-release-8-17.el8.noarch
Complete!
[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*
安装cobbler以及相关软件
[root@localhost ~]# dnf module list | grep cobbler
Failed to set locale, defaulting to C.UTF-8
cobbler 3 default [d] Versatile Linux deployment server
cobbler 3.3 default [d] Versatile Linux deployment server [root@localhost ~]# dnf -y module enable cobbler:3
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:56 ago on Sat Sep 24 01:07:16 2022.
Dependencies resolved.
=============================================================================
Package Architecture Version Repository Size
=============================================================================
Enabling module streams:
cobbler 3
Transaction Summary
=============================================================================
Complete!
[root@localhost ~]# yum -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon
......
rsync-3.1.3-12.el8.x86_64
rsync-daemon-3.1.3-12.el8.noarch
sscg-2.3.3-14.el8.x86_64
tftp-5.2-24.el8.x86_64
tftp-server-5.2-24.el8.x86_64
xorriso-1.4.8-4.el8.x86_64
Complete!
[root@localhost ~]#
启动服务并设置开机自启
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart rsyncd
[root@localhost ~]# systemctl restart tftp
[root@localhost ~]# systemctl restart cobblerd.service
[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 rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
[root@localhost ~]# systemctl enable tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
[root@localhost ~]# systemctl enable cobblerd.service
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
关闭防火墙和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/sysconfig/selinux
SELINUX=disabled
[root@localhost ~]# reboot
修改配置文件
[root@localhost ~]# vim /etc/cobbler/settings.yaml
......
# (dual homed, etc), you need to read the --server-override section
# of the manpage for how that works.
server: 192.168.29.140(修改server的IP地址为本机ip)
......
# if you do not set this correctly, this will be manifested in TFTP open timeouts.
next_server: 192.168.29.140(修改tftp的IP地址为本机ip)
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."(查看密码)
生成加密的密码并写入到配置文件
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" "redhat"
$1$14721$/5AIr5ydPu3qO4KuttYnT/
[root@localhost ~]# vim /etc/cobbler/settings.yaml
......
default_password_crypted: "$1$14721$/5AIr5ydPu3qO4KuttYnT/"
将cobbler的dhcp功能打开,然后重启cobbler
[root@localhost ~]# vim /etc/cobbler/settings.yaml
......
# set to true to enable Cobbler's DHCP management features.
# the choice of DHCP management engine is in /etc/cobbler/modules.conf
manage_dhcp: true(将false修改为true)
[root@localhost ~]# systemctl restart cobblerd.service
通过cobbler check 核对当前设置是否有问题,并解决问题
[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. 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 ~]# cd /var/lib/cobbler/loaders/
[root@localhost loaders]# ls
[root@localhost loaders]# yum -y install syslinux*
......
Installed:
mtools-4.0.18-14.el8.x86_64
syslinux-6.04-5.el8.x86_64
syslinux-extlinux-6.04-5.el8.x86_64
syslinux-extlinux-nonlinux-6.04-5.el8.noarch
syslinux-nonlinux-6.04-5.el8.noarch
syslinux-tftpboot-6.04-5.el8.noarch
Complete!
[root@localhost loaders]# cd
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@localhost ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@localhost ~]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0
问题2和问题3解决办法
[root@localhost ~]#yum -y install yum-utils
......
Installed:
yum-utils-4.0.21-3.el8.noarch
Complete!
[root@localhost ~]#
问题4和问题5可以忽略,
因为是debian系统才需要解决,显示使用的是centos8
Debian系统解决办法安装fence-agents
配置DHCP模板文件,同步cobbler配置
[root@localhost ~]# vim /etc/cobbler/dhcp.template
......
subnet 192.168.29.0 netmask 255.255.255.0 {
option routers 192.168.29.254;
option domain-name-servers 8.8.8.8;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.29.140 192.168.29.150;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
......
[root@localhost ~]# systemctl restart httpd cobblerd.service
[root@localhost ~]# cobbler sync
......
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 ***
[root@localhost ~]#
1、使用cobblerI具制作centos8镜像, 镜像名称为marui-x86 64
2、 使用cobber手动安装centos8系统
3、 使用cobbler-web自动安装centos8系统
(1)主机名为marui123.example.com
(2)手动指定ip
管理distro
//挂载镜像并导入镜像
[root@localhost ~]# mount /dev/cdrom /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# cobbler import --path=/mnt/ --name=marui arch=x86_64
task started: 2022-09-24_022019_import
task started (id=Media import, time=Sat Sep 24 02:20:19 2022)
running python triggers from /var/lib/cobbler/triggers/task/import/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/import/pre/*
shell triggers finished successfully
Found a candidate signature: breed=redhat, version=rhel8
Found a matching signature: breed=redhat, version=rhel8
Adding distros from path /var/www/cobbler/distro_mirror/marui:
creating new distro: marui-x86_64
trying symlink: /var/www/cobbler/distro_mirror/marui -> /var/www/cobbler/links/marui-x86_64
creating new profile: marui-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/distro_mirror/marui for marui-x86_64
processing repo at : /var/www/cobbler/distro_mirror/marui/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/marui/AppStream
looking for /var/www/cobbler/distro_mirror/marui/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/marui/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/marui/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/marui/BaseOS
looking for /var/www/cobbler/distro_mirror/marui/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/marui/BaseOS/repodata
*** TASK COMPLETE ***
[root@localhost ~]#
/安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-8-x86_64,如果重复,系统会提示导入失败
//查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
marui-x86_64
profiles:
marui-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
[root@localhost ~]#
//查看cobbler镜像列表,查看详细信息 查看指定的--name 接镜像名
[root@localhost ~]# cobbler distro report --name marui-x86_64
Name : marui-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/marui-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/marui/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/marui/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 : {}
[root@localhost ~]#
创建kickstarts自动安装脚本
[root@localhost ~]# cobbler profile get-autoinstall --name marui-x86_64 > /var/lib/cobbler/templates/marui.ks
[root@localhost ~]# vim /var/lib/cobbler/templates/marui.ks
......
# Firewall configuration
firewall --disabled(关闭防火墙)
......
%end
%packages
@^minimal-environment(添加最小化安装)
%end
......
//此时使用虚拟机去安装系统并不会成功 需要做如下操作
[root@localhost ~]# cd /usr/share/cobbler/bin/
[root@localhost bin]# ls
migrate-data-v2-to-v3.py mkgrub.sh
migrate-settings.sh settings-migration-v1-to-v2.sh
[root@localhost bin]# bash mkgrub.sh
+ grub2-mkimage -O arm64-efi -o /var/lib/cobbler/loaders/grub/grubaa64.efi --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr efinet
grub2-mkimage: error: cannot open `/usr/lib/grub/arm64-efi/moddep.lst': No such file or directory.
+ set +x
+ grub2-mkimage -O i386-pc-pxe -o /var/lib/cobbler/loaders/grub/grub.0 --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr chain pxe biosdisk
+ set +x
+ grub2-mkimage -O powerpc-ieee1275 -o /var/lib/cobbler/loaders/grub/grub.ppc64le --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr net ofnet
grub2-mkimage: error: cannot open `/usr/lib/grub/powerpc-ieee1275/moddep.lst': No such file or directory.
+ set +x
+ grub2-mkimage -O x86_64-efi -o /var/lib/cobbler/loaders/grub/grubx64.efi --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr chain efinet
grub2-mkimage: error: cannot open `/usr/lib/grub/x86_64-efi/moddep.lst': No such file or directory.
+ set +x
+ ln -s /usr/share/syslinux/ldlinux.c32 /var/lib/cobbler/loaders/ldlinux.c32
+ set +x
[root@localhost bin]# ls /var/lib/cobbler/loaders/
grub ldlinux.c32 menu.c32 pxelinux.0
[root@localhost bin]# cobbler sync
......
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 ***
[root@localhost bin]# systemctl restart httpd cobblerd.service
手动安装
//创建一个虚拟机,然后打开虚拟机
自动安装
//使用浏览器访问https://192.168.29.140/cobbler_web
//默认登录的用户名和密码都为cobbler
同上创建虚拟机
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通