搭建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模板,然后定义如何针对一种配置文件或 机器配置而替换其中的变量。例如,一个模板可能包含两个变量[Math Processing Error]

domain和machine_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/
cobbler安装
说明:虚拟机网卡采用NAT模式或者仅主机模式,不要使用桥接模式,因为后面会搭建DHCP服务器,在同一个局域网多个DHCP服务会有冲突。
VMware的NAT模式的dhcp服务也关闭,避免干扰。
环境部署
CentOS Linux release 7.7.1908
外网ip:10.0.0.41
搭建
关闭防火墙、selinux等

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux

安装cobbler
配置epel源

yum -y install epel-release

安装cobbler及dhcp httpd xinetd cobbler-web

 yum -y install cobbler cobbler-web tftp-server dhcp httpd xinetd

启动cobbler及httpd并加入开机启动

systemctl start httpd cobblerd
systemctl enable httpd cobblerd

查看安装后相关文件

rpm -ql cobbler



/etc/cobbler                  # 配置文件目录
/etc/cobbler/settings         # cobbler主配置文件,这个文件是YAML格式,Cobbler是python写的程序。
/etc/cobbler/dhcp.template    # DHCP服务的配置模板
/etc/cobbler/tftpd.template   # tftp服务的配置模板
/etc/cobbler/rsync.template   # rsync服务的配置模板
/etc/cobbler/iso              # iso模板配置文件目录
/etc/cobbler/pxe              # pxe模板文件目录
/etc/cobbler/power            # 电源的配置文件目录
/etc/cobbler/users.conf       # Web服务授权配置文件
/etc/cobbler/users.digest     # 用于web访问的用户名密码配置文件
/etc/cobbler/dnsmasq.template # DNS服务的配置模板
/etc/cobbler/modules.conf     # Cobbler模块配置文件
/var/lib/cobbler              # Cobbler数据目录
/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_mirror  # yum源存储目录
/var/log/cobbler              # 日志目录
/var/log/cobbler/install.log  # 客户端系统安装日志
/var/log/cobbler/cobbler.log  # cobbler日志

配置cobbler
检查Cobbler的配置,如果看不到下面的结果,再次重启cobbler

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 other than 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/settings must 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* 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.
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 : ksvalidator was not found, install pykickstart
8 : 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
9 : 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.

看到上面出现的问题,然后一个一个的进行解决,先进行设置为可以动态配置,也可以直接更改配置文件。
设置可以动态修改配置文件

sed -ri '/allow_dynamic_settings:/c\allow_dynamic_settings: 1' /etc/cobbler/settings
grep allow_dynamic_settings /etc/cobbler/settings 
显示:allow_dynamic_settings: 1
systemctl restart cobblerd

逐个解决上面的问题

cobbler setting edit --name=server --value=10.0.0.41(自己IP)
cobbler setting edit --name=next_server --value=10.0.0.41
sed -ri '/disable/c\disable = no' /etc/xinetd.d/tftp
systemctl enable xinetd
systemctl restart xinetd
cobbler get-loaders
systemctl start rsyncd
systemctl enable rsyncd
yum -y install pykickstart
default_password_crypted  #注意:这里设置的密码,也就是后面安装完系统的初始化登录密码
openssl passwd -1 -salt `openssl rand -hex 4` 'admin' (admin 是自己的密码)

cobbler setting edit --name=default_password_crypted --value='$1$675f1d08$oJoAMVxdbdKHjQXbGqNTX0'

在这里插入图片描述

yum -y install fence-agents

解决完成再次查看

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

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

配置DHCP

cobbler setting edit --name=manage_dhcp --value=1

修改cobbler的dhcp模块,不要直接修改dhcp本身的配置文件,因为cobbler会覆盖

vim /etc/cobbler/dhcp.template


subnet 10.0.0.0 netmask 255.255.255.0 { #这里改为分配的网段和掩码
     #option routers             10.0.0.41; #如果有网关,这里改为网关地址
     #option domain-name-servers 223.5.5.5,223.6.6.6; #如果有DNS,这里改为DNS地址
     option subnet-mask         255.255.255.0; #改为分配的IP的掩码
     range dynamic-bootp        10.0.0.100 10.0.0.254; #改为分配的IP的范围
     next-server                $next_server;

同步cobbler配置
同步cobbler配置,它会根据配置自动修改dhcp等服务。

[root@cobbler ~]# cobbler rsync 
No such command: rsync
cobbler sync
······················(内容已省略)
*** TASK COMPLETE ***

这时候创建一个新虚拟机可以获取到如下信息,没有镜像选择,只能从本地启动
导入镜像以及配置
挂载光驱

 mount /dev/sr0 /mnt/

导入镜像(时间较长)

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,如果重复,系统会提示导入失败。
查看镜像,上面是镜像名称,下面是启动菜单。

cobbler list

distros:
CentOS-7.7.1908-x86_64

profiles:
CentOS-7.7.1908-x86_64
同步 Cobbler 配置

systemctl restart cobblerd.service
cobbler sync

测试
创建一台 CentOS 系统(不需要选择镜像)最好选择2G 2核

在这里插入图片描述这样就OK了
全自动无人值守
修改pxe默认启动顺序:var/lib/tftpboot/pxelinux.cfg/default(客户端获取IP地址之后在准备安装之前默认从本地启动)

vim /var/lib/tftpboot/pxelinux.cfg/default
6行改:ONTIMEOUT CentOS-7.7.1908-x86_64
systemctl restart cobblerd.service

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

测试:
默认的20秒过后就可以自动安装了 全自动无人值守!
在这里插入图片描述
定制ks文件
定制ks文件,系统默认的ks文件为/var/lib/cobbler/kickstarts/sample_end.ks,但是默认不符合我们需要,所以得去定制。
可以拷贝默认模板进行修改,也可上传ks文件到此目录下

cd /var/lib/cobbler/kickstarts/
cp sample_end.ks mylinux.ks
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检查。
补充
如果有多块网卡,需要监听其中一块的话,配置如下:

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 check核对当前设置是否有问题
cobbler list列出所有的cobbler元素
cobbler report列出元素的详细信息
cobbler sync同步配置到数据目录,更改配置最好都执行一下
cobbler reposync同步yum仓库
cobbler distro查看导入的发行版系统信息
cobbler system查看添加的系统信息
cobbler profile查看配置信息

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值