1. 什么是 Cobbler

Cobbler 是一个基于 pxe 安装原理的,使用 python 编写的实现自动化网络安装的软件,提供了多种安装参数和命令,可以实现批量安装操作系统,甚至有 web 管理界面。

1.1 Cobbler相关服务

  • httpd:提供安装包和 yum 源
  • tftp:提供启动菜单和 bootloader 等相关文件
  • dhcp:自动获取 IP 服务

    2. Cobbler 的使用

    2.1 Cobbler及相关服务安装

    1. [root@centos7 ~]# yum -y install cobbler dhcp
    安装 Cobbler 会自动安装其所依赖的 httpd 和 tftp-server 等其他包。

    2.2 启动服务

    注意:启动cobblerd前最好先启动其他相关服务,否则可能会出现问题
    1. [root@centos7 ~]# systemctl enable --now httpd
    2. [root@centos7 ~]# systemctl enable --now tftp.socket
    3. [root@centos7 ~]# systemctl enable --now cobblerd

    2.3 配置

    使用 cobbler check 命令,并根据命令提示,进行 Cobbler 的配置: ```bash [root@centos7 ~]# 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.

  1. 下载 bootloader 文件:
  2. ```bash
  3. [root@centos7 ~]# cobbler get-loaders

2.3.1 配置说明

cobbler check 的第 1,2,4 项为必须配置项,第 8 项可选,其他选项可以忽略。

  • 1: http 服务器地址。
  • 2: tftp 服务器地址。
  • 3: 为 tftp 服务启动 xinetd 守护进程,centos6 及以下版本需要配置修改,7之后版本无需更改。
  • 4: 下载 tftp 服务所需要的 bootloader 文件,启动菜单等相关文件。
  • 5: rsyncd.service,实现全量及增量的本地或远程数据同步备份服务,可根据需要自行配置。
  • 6: debian 系有关系统配置,redhat 系可以忽略。
  • 7: pykickstart 包的 ksvalidator 命令可以检查 ks 文件语法错误。
  • 8: 默认密码修改。
  • 9: 配置电源项。

    2.3.2 修改配置文件

    1. [root@centos7 ~]# vim /etc/cobbler/settings
    2. server 10.0.0.71
    3. next_server 10.0.0.71

    3. dncp 服务配置

    修改cobbler配置文件/etc/cobbler/settings,让cobbler来管理dhcp服务:
    1. [root@centos7 ~]# vim /etc/cobbler/settings
    2. manage_dhcp: 1
    3. # 修改 dhcp 配置模板文件 /etc/cobbler/dhcp.template,生成dhcp配置文件
    4. subnet 10.0.0.0 netmask 255.255.255.0 {
    5. option routers 10.0.0.2;
    6. option domain-name-servers 223.5.5.5;
    7. option subnet-mask 255.255.255.0;
    8. range dynamic-bootp 10.0.0.160 10.0.0.190;
    9. #修改完配置后重启cobblerd服务,并同步
    10. systemctl restart cobblerd
    11. cobbler sync
    12. #同步后会将/etc/cobbler/dhcp.template复制到/etc/dhcp/dhcpd.conf中,并自动启动dhcp服务
  1. 修改启动菜单标题(可选) ```bash [root@centos7 ~]#cat /etc/cobbler/pxe/pxedefault.template | grep TITLE MENU TITLE Cobbler | http://cobbler.github.io/

sed -ri ‘/TITLE/s#(^[^/]+).*#\1//www.wuvikr.top#’ /etc/cobbler/pxe/pxedefault.template cobbler sync

  1. 完成以上配置后,cobbler的初步配置就算是完成了,接下来是镜像源和KS文件的准备
  2. <a name="5bb16b61"></a>
  3. ### 3. 导入需要安装的系统文件
  4. 可以拷贝iso镜像文件到机器上,也可以使用镜像光盘
  5. ```bash
  6. 1. 挂载镜像到目录
  7. mount /dev/sr0 /mnt/
  8. 2. 导入镜像
  9. cobbler import --name=centos7.8-x86_64 --path=/mnt --arch=x86_64
  10. # --name表示安装源自定义的名字
  11. # --path表示镜像所挂载的目录
  12. # --arch表示指定安装源是32位还是64位,支持的选项有 x86,x86_64,ia64.
  13. #查看导入的镜像列表
  14. cobbler distro list
  15. #查看ks文件菜单列表
  16. cobbler profile list
  17. # 导入镜像后会自动生成一个最小化的安装ks文件菜单,如果觉得自带的ks文件可以满足需求的话就可以跳过下一步了
  18. # 存放ks文件的目录: /var/lib/cobbler/kickstarts/

4. 准备kickstart文件,并关联到指定yum源

  1. 1. 将自己准备好的ks文件放入/var/lib/cobbler/kickstarts/目录下
  2. 2. 删除默认生成的ks文件菜单
  3. cobbler profile remove --name=centos7.8-x86_64
  4. 3. 添加自己准备好的ks文件菜单
  5. cobbler profile add --name=centos7.8.my --distro=centos7.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg
  6. # --name 添加启动菜单的名字
  7. # --distro 关联导入的yum源
  8. # --kickstart 自己定制的ks文件路径
  9. # 查看菜单,ks文件,镜像源详细信息
  10. cobbler profile report --name=centos7.8.my
  11. # 也可以查看/var/lib/tftpboot/pxelinux.cfg/default文件,添加成功后会自动生成一个label
  12. cat /var/lib/tftpboot/pxelinux.cfg/default
  13. LABEL centos7.8.my
  14. kernel /images/centos7.8-x86_64/vmlinuz
  15. MENU LABEL centos7.8.my
  16. append initrd=/images/centos7.8-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://10.0.0.71/cblr/svc/op/ks/profile/centos7.8.my
  17. ipappend 2

到这里 cobbler 就可以开始使用了!

3. Kickstart 文件

kickstart 文件可以使用以下两种方式制作:

  • 根据自己安装好机器后 /root 目录下 anaconda-ks.cfg 文件进行修改。
  • 安装 system-config-kickstart 包,一个图形化的 kickstart 文件制作工具。

    3.2 centos7 kickstart 文件范例:

    ```bash

    platform=x86, AMD64, or Intel EM64T

    version=DEVEL

    Install OS instead of upgrade

    install

    Keyboard layouts

    keyboard —vckeymap=us —xlayouts=’us’

    Root password

    rootpw —iscrypted $6$Ow9n3A86WGKGv8tF$.Jm4iXJLnilU0q/miXxkFD56uF/ZaD6pRzyvNjxt3H55XgA70PpJoWNQZAv3zLTU6vF3RB2qevwpHuRVNzFrI/

    System language

    lang en_US

    System authorization information

    auth —useshadow —passalgo=sha512

    Use text mode install

    text firstboot —disabled

    SELinux configuration

    selinux —disabled

ignoredisk —only-use=sda

Firewall configuration

firewall —disabled

Network information

network —bootproto=dhcp —device=eth0

Reboot after installation

reboot

System timezone

timezone Asia/Shanghai —nontp

Use network installation

url —url=http://10.0.0.81/centos/7/x86_64/os

url —url=$tree cobbler使用这个

System bootloader configuration

bootloader —append=”net.ifnames=0” —location=mbr —boot-drive=sda

Clear the Master Boot Record

zerombr

Partition clearing information

clearpart —all —initlabel

Disk partitioning information

part /boot —fstype=”xfs” —size=1024 part / —fstype=”xfs” —size=10240 part swap —fstype=”xfs” —size=2048 part /data —fstype=”xfs” —size=5120

创建用户wuvikr,密码744123

user —name=wuvikr —password=$6$z96.c6bRe..qZRAi$sxHDL0HLf5vFPvayvSjS2uwMaC/zWFMN3oPokFC5Z2S.wD1X8PDkLShdoZxGDhN51bBn/v7QKvhumknH2Qpya0 —iscrypted —gecos=”wuvikr”

%packages

@^minimal @core kexec-tools

%end

%post rm -rf /etc/yum.repos.d/* cat > /etc/yum.repos.d/CentOS8.repo <<EOF [Packages] name=Base baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/ https://mirrors.huaweicloud.com/centos/7/os/x86_64/ https://mirrors.163.com/centos/7/os/x86_64/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

[epel] name=epel baseurl=https://mirrors.aliyun.com/epel/7/x86_64/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7

[extras] name=extras baseurl=https://mirrors.aliyun.com/centos/7/extras/x86_64/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official EOF %end ```