Cobbler 安装与配置

2019/12/18 Linux Ubuntu Cobbler

Cobbler 安装与配置

Cobbler 介绍

Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。

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

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

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

安装

以下操作,皆在 CentOS Linux release 7.7.1908 (Core) 实现。

检测基础环境

# 查看 selinux 和防火墙是否关闭
[root@Cobbler ~] getenforce
Disabled

[root@Cobbler ~] systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

如果 getenfore 的结果不是 Disabled,那么根据 getenforce命令 去关闭 SELinux。

更新yum源

[root@Cobbler ~] curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@Cobbler ~] curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@Cobbler ~] yum clean all
[root@Cobbler ~] yum makecache

安装 cobbler

[root@Cobbler ~] yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd

启动服务

[root@Cobbler ~] systemctl start httpd.service
[root@Cobbler ~] systemctl start cobblerd.service

cobbler check

[root@Cobbler ~] cobbler check

配置 cobbler 开机自启

$ chkconfig httpd on
$ chkconfig cobblerd on
$ chkconfig dhcpd on
$ /etc/init.d/httpd restart
$ /etc/init.d/cobblerd restart
$ /etc/init.d/dhcpd restart

配置 cobbler

[root@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 : 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) power management features. install cman or fence-agents to use them

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

上面指出了八项问题,逐一解决。

[root@Cobbler ~] cp /etc/cobbler/settings{,.ori}  # 备份
[root@Cobbler ~] sed -i 's/server: 127.0.0.1/server: your_address/' /etc/cobbler/settings  # fix 1 
[root@Cobbler ~] sed -i 's/next_server: 127.0.0.1/next_server: your_address/' /etc/cobbler/settings  # fix 2
[root@Cobbler ~] sed 's#yes#no#g' /etc/xinetd.d/tftp -i  # fix 3
[root@Cobbler ~] cobbler get-loaders  # fix 4
[root@Cobbler ~] ls  /var/lib/cobbler/loaders
COPYING.elilo     elilo-ia64.efi   menu.c32    yaboot
COPYING.syslinux  grub-x86_64.efi  pxelinux.0
COPYING.yaboot    grub-x86.efi     README
[root@Cobbler ~] systemctl start rsyncd.service  # fix 5
[root@Cobbler ~] systemctl enable rsyncd.service  # fix 5
[root@Cobbler ~] openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'  # just show 
$1$random-p$AOw9RDIWQm6tfUo9Ediu/0
[root@Cobbler ~] sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'`\"#" /etc/cobbler/settings  # fix 7
[root@Cobbler ~] sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings  # 配置 dhcp 服务
[root@Cobbler ~] sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings  # 防止循环安装
[root@Cobbler ~] sed -i.ori 's#192.168.1#172.16.1#g;22d;23d' /etc/cobbler/dhcp.template  # 修改 dhcp 配置

# 重启一些服务
[root@Cobbler ~] systemctl start rsyncd
[root@Cobbler ~] systemctl enable rsyncd
[root@Cobbler ~] systemctl enable tftp.socket
[root@Cobbler ~] systemctl start tftp.socket
[root@Cobbler ~] systemctl restart cobblerd.service
[root@Cobbler ~] cobbler sync  # 同步配置

配置安装镜像

后面的操作可以完全在命令行中操作,但是部分操作可以在 web 执行,原理都是一样的。

创建配置

配置文件主要分为 ks 或者 preseed 两种,都是纯文本文件,通过标识符和指令完成无人应答安装。

通常,我们在安装操作系统的过程中,需要大量的和服务器交互操作,为了减少这个交互过程,kickstart就诞生了。使用这种kickstart,只需事先定义好一个Kickstart自动应答配置文件ks.cfg(通常存放在安装服务器上),并让安装程序知道该配置文件的位置,在安装过程中安装程序就可以自己从该文件中读取安装配置,这样就避免了在安装过程中多次的人机交互,从而实现无人值守的自动化安装。

但是 ks 是 Redhat 公司推出的,它对于 RHEL 以及 CentOS 更加友好,但相对的,对 Debian 系的支持就不够了。Debian 又推出了 Debian-Installer 系统,遵循这个系统的文件就叫做 seed 配置文件,一个显著的特点就是每行开头出现 d-i。

写 seed 文件

可以根据上述链接获取 seed 文件。

写 ks 文件

可以根据上述链接获取 ks 文件。

导入镜像

无论是命令行还是 web 控制,第一步都是挂载镜像。

挂载镜像:

$ mkdir -p /mnt/ubuntu18
$ mount -t iso9660 -r -o ro,loop /tmp/ubuntu-18.04.3-server-amd64.iso /mnt/ubuntu18

命令行:

$ cobbler import --path=/mnt/ubuntu18 --name=ubuntu-18.04.3 --kickstart=/var/lib/cobbler/kickstarts/ubuntu18043.seed --arch=x86_64
$ cobbler list
distros:
   ubuntu-18.04-hwe-x86_64
   ubuntu-18.04-x86_64

profiles:
   ubuntu-18.04-hwe-x86_64
   ubuntu-18.04-x86_64

systems:

repos:
   ubuntu-18.04-hwe-x86_64
   ubuntu-18.04-x86_64

images:

mgmtclasses:

packages:

files:

通过 import 可以导入镜像,中间会对镜像做一些检测,live 版或者 Desktop 版是无法被导入的。

web 方式:

1. 打开 $cobblerIP/cobbler_web
2. 账户密码默认都是 cobbler
3. 左侧选择 import DVD
4. Prefix 自定义,Arch 选择 x_86-64,Breed 选择 Ubuntu
5. Path 则输入挂载点,也就是 /mnt/ubuntu18
6. 点击 Run,进入 Task Log 查看导入结果

同步并操作

$ cobbler sync

启动虚拟机,以 PXE 方式启动,就可以使用 cobbler 装机了。

遇到的所有问题

  • ProtocolError: <ProtocolError for 127.0.0.1:80/cobbler_api: 404 Not Found>: 注释掉 /etc/httpd/conf/httpd.conf 里的 DocumentRoot
  • Invalid command 'WSGIScriptAliasMatch', perhaps misspelled or defined by: apt-get install libapache2-mod-wsgi
  • Invalid command 'ProxyRequests', perhaps misspelled or defined by a module not included in the server configuration: a2enmod proxy

参考

cobbler 相关

kickstart 相关

杂项

Search

    Table of Contents