搭建Cobbler无人值守安装服务器

Cobbler 介绍

Cobbler是一个Linux服务器快速网络安装的服务,而且在经过调整也可以支持网络安装windows。

该工具使用python开发,小巧轻便(才15k行python代码),可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS,TFTP、RSYNC以及yum仓库、构造系统ISO镜像。

Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。

Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。

Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。

Cobbler客户端Koan支持虚拟机安装和操作系统重新安装,使重装系统更便捷。

Cobbler 用处

使用Cobbler,您无需进行人工干预即可安装机器。Cobbler设置一个PXE引导环境(它还可以使用yaboot支持PowerPC),并控制与安装相关的所有方面,比如网络引导服务(DHCP和TFTP)与存储库镜像。当希望安装一台新机器时,Cobbler可以:

1)使用一个以前定义的模板来配置DHCP服务(如果启用了管理DHCP)
2)将一个存储库(yum或rsync)建立镜像或解压缩一个媒介,以注册一个新操作系统
3)在DHCP配置文件中为需要安装的机器创建一个条目,并使用指定的参数(IP和MAC)
4)在TFTP服务目录下创建适当的PXE文件
5)重新启动DHCP服务来反应新的更改
6)重新启动机器以开始安装(如果电源管理已启动)

Cobbler 支持的系统和功能

Cobbler支持众多的发行版:RedHat、Fedora、CentOS、Debian、Ubuntu和SUSE。当添加一个操作系统(通常通过使用ISO文件)时,Cobbler知道如何解压缩合适的文件并调整网络服务,以正确引导机器。

Cobbler可以使用kickstart模板。基于Red Hat或 Fedora的系统使用kickstart文件来自动化安装流程。通过使用模板,就会拥有基本的kickstart模板,然后定义如何针对一种配置文件或 机器配置而替换其中的变量。例如,一个模板可能包含两个变量 d o m a i n 和 domain和 domainmachine_name.在Cobbler配置中,一个配置文件指定 domain=mydomain.com,并且每台使用该配置文件的机器在machine_name变量中指定其名称。该配置文件的所有机器都使用相同的 kickstart安装且针对domain=mydomain.com进行配置,但每台机器拥有其自己的机器名称。您仍然可以使用kickstart模板 在不同的域中安装其他机器并使用不同的机器名称。

为了协助管理系统,Cobbler可通过fence scripts连接到各个电源管理环境。Cobbler支持apc_snmp、bladecenter、bullpap、drac、 ether_wake、ilo、integrity、ipmilan、ipmitool、lpar、rsa、virsh和wti。要重新安装一台机器,可 运行reboot system foo命令,而且Cobbler会使用必要的 和信息来为您运行恰当的fence scripts(比如机器插槽数)。

除了这些特性,还可以使用一个配置管理系统(CMS)。你有两种选择:该工具内的一个内部系统,或者现成的外部CMS,比如Chef或 Puppet。借助内部系统,你可以指定文件模板,这些模板会依据配置参数进行处理(与kickstart模板的处理方式一样),然后复制到你指定的位 置。如果必须自动将配置文件部署到特定机器,那么此功能很有用

使用koan客户端,Cobbler可从客户端配置虚拟机并重新安装系统。

cobbler官网:http://cobbler.github.io/

部署环境
CentOS Linux release 7.7.1908
外网ip:10.0.0.43

搭建

1、环境初始化
关闭 selinux 和防火墙

[root@c7 ~]# systemctl stop firewalld
[root@c7 ~]# systemctl disable firewalld
[root@c7 ~]# setenforce 0
[root@c7 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

2、安装配置 Cobbler
首先安装 epel-release,Cobbler 和 tftp-server 在 base 源中是没有的

[root@c7 ~]# yum -y install epel-release

安装 Cobbler 其实有一部分软件会被当做依赖进行安装上去,比如 tftp 和 httpd 服务,我们这里为了方便可以一并安装,避免后续出现相关问题。

[root@c7 ~]# yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd

软件作用说明
cobbler #Cobbler 程序包
cobbler-web #Cobbler 的 Web 服务包
pykickstart #Cobbler 检查 kickstart 语法错误
httpd #Apache Web 服务

Cobbler 工作目录介绍

[root@c7 ~]# ls /etc/cobbler/
auth.conf         import_rsync_whitelist  pxe                 users.conf
cheetah_macros    iso                     reporting           users.digest
cobbler_bash      ldap                    rsync.exclude       version
completions       modules.conf            rsync.template      zone.template
dhcp.template     mongodb.conf            secondary.template  zone_templates
dnsmasq.template  named.template          settings
genders.template  power                   tftpd.template
/etc/cobble配置文件目录
/etc/cobbler/settingsCobbler 主配置文件,这个文件是 YAML 栺式,Cobbler 是 python 写的程序。
/etc/cobbler/dhcp.templateDHCP服务的配置模板
/etc/cobbler/tftpd.templatetftp 服务的配置模板
/etc/cobbler/rsync.templatersync 服务的配置模板
/etc/Cobbler/isoiso 模板配置文件目录
/etc/cobbler/pxepxe 模板文件目录
/etc/cobbler/power电源的配置文件目录
/etc/cobbler/users.confWeb 服务授权配置文件
/etc/cobbler/users.digest用于 Web 访问的用户名密码配置文件
/etc/cobbler/dnsmasq.templateDNS 服务的配置模板
/etc/cobbler/modules.confCobbler 模块配置文件
/var/lib/cobblerCobbler 数据目录
/var/lib/cobbler/config配置文件
/var/lib/cobbler/kickstarts默认存放 kickstart 文件
/var/lib/cobbler/loaders存放的各种引导程序
/var/www/cobbler系统安装镜像目录
/var/www/cobbler/ks_mirror导入的系统镜像列表
/var/www/cobbler/images导入的系统镜像启动文件
/var/www/cobbler/repo_mirroryum 源存储目录
/var/log/cobbler日志目录
/var/log/cobbler/install.log客户端系统安装日志
/var/log/cobbler/cobbler.logCobbler 日志

3、检查配置

首先启动 Cobbler 和 httpd 服务

[root@c7 ~]# systemctl start cobblerd.service httpd

检查

[root@c7 ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something otherthan localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settingsmust be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : 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* versionof the syslinux package installed and can ignore this message entirely.  Filesin 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.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
8 : fencing tools were not found, and are required to use the (optional) powermanagement features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.

4、解决检查出的问题

问题 1:修改 server 地址为 10.0.0.43

[root@c7 ~]# vim /etc/cobbler/settings
390行改: server: 10.0.0.43  

问题 2:修改 next_server 地址为 10.0.0.43

[root@c7 ~]# vim /etc/cobbler/settings
278行改: next_server: 10.0.0.43 
298行改:pxe_just_once: 1 #防止循环安装

问题 3:修改 tftp 服务被 xinetd 服务管理

[root@c7 ~]# sed -i '14s/= yes/= no/'  /etc/xinetd.d/tftp

顺便修改 xinetd 和 tftpd 服务开机启动

[root@c7 ~]# systemctl start xinetd tftp && systemctl enable xinetd tftp

问题 4:下载操作系统引导文件

[root@c7 ~]# cobbler get-loaders
task started: 2020-05-03_111956_get_loaders
task started (id=Download Bootloader Content, time=Sun May  3 11:19:56 2020)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***

问题 5:修改 rsyncd 服务为开机自启动状态并启用它。

[root@c7 ~]# systemctl start rsyncd && systemctl enable rsyncd

问题 6:关于 debian 相关部署管理配置,忽略。
debmirror package is not installed, it will be required to manage debian
deployments and repositories # debmirror 包尚未安装,需要它来管理 debian 部署和存储库
问题 7:修改操作系统默认密码

[root@c7 ~]# openssl passwd -1 -salt 'root' '123456'
$1$root$j0bp.KLPyr.u9kgQ428D10
[root@c7 ~]# vim /etc/cobbler/settings
101行改:default_password_crypted: "$1$root$j0bp.KLPyr.u9kgQ428D10"

注:root 为用户描述,123456 为密码
问题 8:电源管理相关服务,忽略。

5、DHCP 配置

修改完以上配置就可以检查 DHCP 配置了,由于 Cobbler 自动管理 DHCP 服务,我们只需要修改 Cobbler 中的模板配置文件即可。

[root@c7 ~]# vim /etc/cobbler/dhcp.template
#下面是要修改的地方
subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.254;
     option domain-name-servers 223.5.5.5,223.6.6.6;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.110;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

注:配置默认为 192.168.1.0 网段,具体要看你的装机 vlan 划分,我的网段为10.0.0.0。
注:默认网关地址为 192.168.1.5,这里需要改成你自己局域网中的网关。
$next_server 为变量值为我们前面修改的主配置文件中的地址 10.0.0.43。

修改 Cobbler 管理 dhcp 服务

[root@c7 ~]# vim /etc/cobbler/settings
242行改:manage_dhcp: 1

同步配置文件,需要先重启 Cobblerd

[root@c7 ~]# systemctl restart cobblerd.service
[root@c7 ~]# cobbler sync
task started: 2020-05-03_113412_sync
task started (id=Sync, time=Sun May  3 11:34:12 2020)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
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 ***

注意观察 DHCP 服务是否启动。

重新检查,剩下 2 个可以忽略的问题。

[root@c7 ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : fencing tools were not found, and are required to use the (optional) powermanagement features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.

6、导入镜像以及配置

挂载光驱

[root@c7 ~]# mount /dev/sr0 /mnt/

导入镜像(时间较长)

[root@c7 ~]# cobbler import --path=/mnt/ --name=CentOS-7.7.1908 --arch=x86_64
task started: 2020-05-03_113947_import
task started (id=Media import, time=Sun May  3 11:39:47 2020)
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.7.1908-x86_64:
creating new distro: CentOS-7.7.1908-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-7.7.1908-x86_64 -> /var/www/cobbler/links/CentOS-7.7.1908-x86_64
creating new profile: CentOS-7.7.1908-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.7.1908-x86_64 for CentOS-7.7.1908-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-7.7.1908-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7.7.1908-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-7.7.1908-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7.7.1908-x86_64/repodata
*** TASK COMPLETE ***

参数:
–path 镜像路径
–name 为安装源定义一个名字
–arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7.7.1908,如果重复,系统会提示导入失败。

查看镜像,上面是镜像名称,下面是启动菜单。

[root@c7 ~]# cobbler list
distros:
   CentOS-7.7.1908-x86_64

profiles:
   CentOS-7.7.1908-x86_64

同步 Cobbler 配置

[root@c7 ~]# systemctl restart cobblerd.service
[root@c7 ~]# cobbler sync

7、测试

创建一台 CentOS 系统(不需要选择镜像)
保证相同私有网络,并且最好2G内存,内存小的话会在安装时报空间不够出现下图的错误
在这里插入图片描述

在这里插入图片描述
耐心等待安装时间较长,出现下图代表已经安装完成
在这里插入图片描述
8、全自动无人值守

修改pxe默认启动顺序:var/lib/tftpboot/pxelinux.cfg/default(客户端获取IP地址之后在准备安装之前默认从本地启动)

[root@c7 kickstarts]# vim /var/lib/tftpboot/pxelinux.cfg/default
6行改:ONTIMEOUT CentOS-7.7.1908-x86_64
[root@c7 kickstarts]# systemctl restart cobblerd.service

将ONTIMEOUT 修改成想要安装的系统名称(自己制作好的那个),否则客户端在启动安装的过程中会选择localhost导致安装失败。
注意:这时修改之后重启客户端即可,切记重启之后一定不要执行cobbler sync,否则修改的配置文件将失效。如果想要其永久性生效
需要修改:vim /etc/cobbler/pxe/pxedefault.template,把上面的字段改为安装系统的名称:ONTIMEOUT CentOS-7.7.1908-x86_64

测试:
默认的20秒过后就可以自动安装了 全自动无人值守!
在这里插入图片描述
9、定制ks文件

定制ks文件,系统默认的ks文件为/var/lib/cobbler/kickstarts/sample_end.ks,但是默认不符合我们需要,所以得去定制。
可以拷贝默认模板进行修改,也可上传ks文件到此目录下

[root@c7 kickstarts]# cd /var/lib/cobbler/kickstarts/
[root@c7 kickstarts]# cp sample_end.ks mylinux.ks
[root@c7 kickstarts]# vim mylinux.ks

修改完成后一定要通过: cobbler profile edit --name=CentOS-7.7.1908-x86_64 --distro=CentOS-7.7.1908-x86_64 --kickstart=/var/lib/cobbler/kickstarts/mylinux.ks
命令指定.ks文件,否则系统会找默认的ks文件。可以用cobbler report检查。

10、补充

如果有多块网卡,需要监听其中一块的话,配置如下:

vim /etc/sysconfig/dhcpd
# $ cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/
# $ vi /etc/systemd/system/dhcpd.service
# $ ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid <your_interface_name(s)>
# 注意上面一步,写的时候没有不带"<>"这个符号,否则会报错!
# $ systemctl --system daemon-reload
# $ systemctl restart dhcpd.service

cobbler命令详解

# cobbler
usage
=====
cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... 
        [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]
# cobbler import --help  # 导入镜像帮助
Usage: cobbler [options]
Options:
  -h, --help            show this help message and exit
  --arch=ARCH           OS architecture being imported
  --breed=BREED         the breed being imported
  --os-version=OS_VERSION
                        the version being imported
  --path=PATH           local path or rsync location
  --name=NAME           name, ex 'RHEL-5'
  --available-as=AVAILABLE_AS
                        tree is here, don't mirror
  --kickstart=KICKSTART_FILE
                        assign this kickstart file
  --rsync-flags=RSYNC_FLAGS
                        pass additional flags to rsync
#其它命令
cobbler check    核对当前设置是否有问题
cobbler list     列出所有的cobbler元素
cobbler report   列出元素的详细信息
cobbler sync     同步配置到数据目录,更改配置最好都要执行下
cobbler reposync 同步yum仓库
cobbler distro   查看导入的发行版系统信息
cobbler system   查看添加的系统信息
cobbler profile  查看配置信息

Cobbler的web管理界面
https://10.0.0.43/cobbler_web
默认用户名:cobbler
默认密码 :cobbler
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于Cobbler的无人安装部署,可以按照以下步骤进行操作: 1. 首先,确保你的系统满足Cobbler安装要求,包括适当的硬件配置和操作系统版本。 2. 安装Cobbler软件包。你可以通过包管理器(如yum或apt)来安装Cobbler。 3. 配置Cobbler。编辑Cobbler的配置文件(通常是/etc/cobbler/settings)来设置网络参数、存储路径、DHCP设置等。 4. 导入操作系统镜像。使用cobbler import命令将操作系统镜像导入Cobbler。你需要提供操作系统的ISO文件或网络安装源。 5. 定义系统配置文件。使用cobbler system命令创建系统配置文件,包括主机名、IP地址、MAC地址等信息。 6. 定义配置文件模板。根据你的需求,可以使用cobbler profile命令创建配置文件模板,并将其关联到系统配置文件上。 7. 配置DHCP服务。Cobbler可以自动配置DHCP服务器,以便客户端能够通过网络安装操作系统。 8. 启动Cobbler服务。使用systemctl或service命令启动Cobbler服务,并确保它在系统启动时自动启动。 9. 进行无人安装。现在,你可以使用cobbler system命令进行无人安装了。根据定义的系统配置文件,Cobbler将自动进行操作系统的安装。 请注意,以上只是一个概述,具体的步骤和命令可能会因为你的系统环境和需求而有所不同。建议你参考Cobbler的官方文档或相关资源,以获取详细的操作指南。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值