运维自动化之系统安装-cobbler

1 cobbler介绍

  • Cobbler:
    • 快速网络安装linux操作系统的服务,支持众多的Linux发行版:Red Hat、Fedora、CentOS、Debian、Ubuntu和SuSE,也可以支持网络安装windows
    • PXE的二次封装,将多种安装参数封装到一个菜单
    • Python编写
    • 提供了CLI和Web的管理形式
  • 安装包:
    • cobbler
  • cobbler服务集成:
    • pxe服务
    • DHCP
    • rsync
    • Http
    • DNS
    • Kickstart
    • IPMI电源官理
  • 检查cobbler环境:
    • cobbler check

2 cobbler工作流程

在这里插入图片描述

- client裸机配置了从网络启动后,开机后会广播包请求DHCP服务器(cobbler server)发送其分配好的一个IP
- DHCP服务器(cobbler server)收到请求后发送responese,包括其ip地址
- client裸机拿到ip后再向cobbler server发送请求OS引导文件的请求
- cobbler server告诉裸机OS引导文件的名字和TFTP server的ip和port
- client裸机通过上面告知的TFTP server地址通信,下载引导文件
- client裸机执行执行该引导文件,确定加载信息,选择要安装的os,期间会再向cobbler server请求kickstart文件和os image
- cobbler server发送请求的kicksfart和os image
- client裸机加载kickstart文件
- client裸机接收os image,安装该os image

3 cobbler 相关术语

  • 发行版:

    • 表示一个操作系统版本,它承载了内核和initrd的信息,以及内核参数等其他数据
  • 配置文件:

    • 包含一个发行版、一个kickstart文件以及可能的存储库,还包含更多特定的内核参数等其他数据
  • 系统:

    • 表示要配置的主机,它包含一个配置文件或一个镜像,还包含IP和 MAC地址、电源管理(地址、凭据、类型)以及更为专业的数据等信息
  • 存储库:

    • 保存一个yum 或rsync存储库的镜像信息
  • 镜像:

    • 可替换一个包含不属于此类别的文件的发行版对象(例如,无法分为内核和initrd 的对象)

4 各种配置目录说明

配置文件目录/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:模块的配置文件

5 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仓库存储目录

日志目录
    /var/log/cobbler/installing:客户端安装日志
    /var/log/cobbler/cobbler.log :cobbler日志

6 cobbler命令介绍

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

7 cobbler重要的参数

/etc/cobbler/settings中重要的参数设置
    default_password_crypted:
        "$1$qEc7ilpP$pg5isoj/mlxTxEslhRvyp/"

    manage_dhcp:1
    manage_tftpd:1
    pxe_just_once:1
    next_server:< tftp服务器的IP地址>
    server:<cobbler服务器的IP地址>

8 cobbler部署

18.1 准备环境
    yum install -y cobbler dhcp tree syslinux
    iptables -F
    systemctl disable firewalld
    setenforce 0
    vim /etc/selinux/config
        SELINUX=permissive

    systemctl enable cobblerd ;systemctl start cobblerd
    systemctl enable tftp ;systemctl start tftp
    systemctl enable httpd;systemctl start httpd
    mount /dev/sr0 /data/centos7/
    mount /dev/sr0 /data/centos6/

18.2 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.

18.3 解决 cobbler check
    cp /etc/cobbler/settings /etc/cobbler/settings.bak; vim /etc/cobbler/settings
        server: 10.0.0.100
        next_server: 10.0.0.100
        default_password_crypted: "1JEeGFV1z$E0l1.prqOhhSzlVeEwmYT."  (使用openssl passwd -1 生成)
        manage_dhcp: 1

    systemctl restart cobblerd
    cobbler get-loaders
        cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/ ; systemctl restart cobblerd (完成后需要科学上网下载个组件再断开)

    cobbler sync
    cobbler自动生成: /var/lib/tftpboot/pxelinux.cfg/default 
    vim /etc/cobbler/dhcp.template 
        subnet 10.0.0.0 netmask 255.255.255.0 {
             option subnet-mask         255.255.255.0;
             range dynamic-bootp        10.0.0.100 10.0.0.254;

    systemctl restart cobblerd; cobbler sync;systemctl restart dhcpd;cobbler check

18.4 cobbler 镜像配置
    cobbler import --path=/data/centos7 --name=centos7.9
    cobbler import --path=/data/centos6 --name=centos6.10
    scp centos7.cfg centos6.cfg 10.0.0.27:/var/lib/cobbler/kickstart/
    cobbler distro
    cobbler distro list

18.5 装机测试
    cobbler sync
    cobbler自动生成应答文件:/etc/httpd/conf.d/cobbler.conf 

18.6 增加自己编辑的应答文件
    vim /var/lib/cobbler/kickstarts/centos*.cfg 
        url --url=$tree

    cobbler profile list
    cobbler profile add --name=centos7.3-ck --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg --distro=centos7.9-x86_64
    cobbler profile add --name=centos6.10-ck --kickstart=/var/lib/cobbler/kickstarts/centos6.cfg --distro=centos6.10-x86_64
    cat /var/lib/tftpboot/pxelinux.cfg/default
    vim /var/lib/cobbler/kickstarts/centos7.cfg
    vim /var/lib/cobbler/kickstarts/centos6.cfg
    cobbler sync

18.7 装机测试
    cobbler profile remove --name=xxxxxxx-x86_64 (可以删除应答文件)

centos6.cfg

# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
url --url=$tree
text
reboot
lang en_US.UTF-8
keyboard us
network --bootproto=dhcp --onboot=on --device=eth0
rootpw  --iscrypted your_root_passwd
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
skipx
logging --level=info
timezone --utc Asia/Shanghai
bootloader --location=mbr
zerombr
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all

part /boot --fstype=ext4 --asprimary --size=1024
part swap --grow --maxsize=2048 --asprimary --size=2048
part / --fstype=ext4 --size=102400
part /data --fstype=ext4 --size=50000

%post
useradd testuser
echo yourpasswd|passwd --stdin testuser
rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=http://10.0.0.100/cobbler/ks_mirror/centos6.10/
gpgcheck=0
EOF
%end

%packages
@core
@server-policy
@workstation-policy
%end

centos7.cfg

#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=$tree
# Use graphical install
text
# Run the Setup Agent on first boot
firstboot --disable
reboot
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on --ipv6=auto --no-activate
network  --hostname=centos7-mini.clk11.com

# Root password
rootpw --iscrypted your_root_passwd
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Disk partitioning information
part /boot --fstype="ext4" --ondisk=sda --size=1024
part / --fstype="ext4" --ondisk=sda --size=100000
part swap --fstype="swap" --ondisk=sda --size=2048
part /data --fstype="ext4" --ondisk=sda --size=50000

%packages
@^minimal
@core

%end

%addon com_redhat_kdump --disable --reserve-mb='auto'

%end
%post
useradd testuser
echo yourpasswd|passwd --stdin testuser
rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=http://10.0.0.100/cobbler/ks_mirror/centos7.9/
gpgcheck=0
EOF
%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

版权声明:本文为kenidi8215原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。