1. cobbler简介

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

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

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

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

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

Cobbler官网

cobbler集成的服务

  • PXE服务支持
  • DHCP服务管理
  • DNS服务管理(可选bind,dnsmasq)
  • 电源管理
  • Kickstart服务支持
  • YUM仓库管理
  • TFTP(PXE启动时需要)
  • Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

cobbler配置文件详解
cobbler配置文件目录在/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

模块的配置文件

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

cobbler日志文件

日志文件路径

说明

/var/log/cobbler/installing

客户端安装日志

/var/log/cobbler/cobbler.log

cobbler日志

cobbler命令详解

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

2. cobbler服务端部署

//配置yum源和epel源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# yum makecache


//安装cobbler以及相关的软件
yum module list | grep cobbler

cobbler              3               default [d]                              Versatile Linux deployment server                                                                                                                                                                                                
cobbler              3.3             default [d]                              Versatile Linux deployment server             

[root@localhost ~]# dnf module enable cobbler:3 -y

[root@yuli ~]# yum -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon 


//启动服务并设置开机自启
[root@yuli ~]# systemctl restart httpd
[root@yuli ~]# systemctl restart tftp
[root@yuli ~]# systemctl restart cobblerd.service 
[root@yuli ~]# systemctl restart rsyncd
[root@yuli ~]# 
[root@yuli ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@yuli ~]# systemctl enable tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
[root@yuli ~]# systemctl enable cobblerd.service 
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
[root@yuli ~]# systemctl enable rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
[root@yuli ~]# 


//关闭防火墙和selinux
 [root@yuli ~]# systemctl stop firewalld.service 
[root@yuli ~]# systemctl disable firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@yuli ~]# vim /etc/selinux/config 
[root@yuli ~]# setenforce 0
[root@yuli ~]# 
重启Linux系统

 
//修改server的ip地址为本机ip
 //设置tftp的ip地址为本机ip
[root@yuli ~]# vim /etc/cobbler/settings.yaml 
[root@yuli ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.119.157/' /etc/cobbler/settings.yaml
[root@yuli ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.119.157/'  /etc/cobbler/settings.yaml


 # by systems during the install process, it must be the address
# or hostname of the system as those systems can see the server.
# if you have a server that appears differently to different subnets
# (dual homed, etc), you need to read the --server-override section
# of the manpage for how that works.
server: 192.168.119.157

# If set to true, all commands will be forced to use the localhost address
# instead of using the above value which can force commands like
# cobbler sync to open a connection to a remote address if one is in the
# configuration and would traceback.

# if using Cobbler with manage_dhcp, put the IP address
# of the Cobbler server here so that PXE booting guests can find it
# if you do not set this correctly, this will be manifested in TFTP open timeouts.
next_server: 192.168.119.157

# settings for power management features.  optional.
# see https://github.com/cobbler/cobbler/wiki/Power-management to learn more
# choices (refer to codes.py):
#    apc_snmp bladecenter bullpap drac ether_



 
//生成加密的密码
 [root@yuli ~]# openssl passwd -1 -salt "$RANDOM" 'redhat'
$1$14933$cHhbbIfL.PRFRqKLjYMVt1           //这是密码加密后的形式


 //将新生成的加密密码加入到配置文件
[root@yuli ~]# vim /etc/cobbler/settings.yaml 

 # The simplest way to change the password is to run
# openssl passwd -1
# and put the output between the "" below.
default_password_crypted: "$1$14933$cHhbbIfL.PRFRqKLjYMVt1"

# the default template type to use in the absence of any
# other detected template. If you do not specify the template
# with '#template=<template_type>' on the first line of your

//将cobbler的dhcp功能打开
 [root@yuli ~]# vim /etc/cobbler/settings.yaml 

 # set to true to enable Cobbler's DHCP management features.
# the choice of DHCP management engine is in /etc/cobbler/modules.conf
manage_dhcp: true

# set to true to enable Cobbler's DNS management features.
# the choice of DNS mangement engine is in /etc/cobbler/modules.conf
manage_dns: false



//重启cobbler
[root@yuli ~]# systemctl restart cobblerd.service 
[root@yuli ~]# systemctl restart httpd


 
//通过cobbler check 核对当前设置是否有问题
 [root@yuli ~]# cobbler check
The following are potential configuration items that you may want to fix:

1: some network boot-loaders are missing from /var/lib/cobbler/loaders. 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, and yaboot.
2: reposync is not installed, install yum-utils or dnf-plugins-core
3: yumdownloader is not installed, install yum-utils or dnf-plugins-core
4: debmirror package is not installed, it will be required to manage debian deployments and repositories
5: 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@localhost ~]# 



 问题1解决办法:
 [root@yuli ~]# cd /var/lib/cobbler/loaders
[root@yuli loaders]# ls
[root@yuli loaders]# yum -y install syslinux* 
[root@yuli ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@yuli ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@yuli ~]# 

 
 问题2和问题3解决办法:
 [root@yuli ~]# yum -y install yum-utils


问题4和问题5可以忽略,
因为是debian系统才需要解决,显示使用的是centos8
Debian系统解决办法安装fence-agents


//配置DHCP模板文件
[root@yuli ~]# vim /etc/cobbler/dhcp.template 

subnet 192.168.119.0 netmask 255.255.255.0 {
     option routers             192.168.119.2;  #这里是网关请查看自己的网关
     option domain-name-servers 8.8.8.8;         #这里是DNS
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.119.100 192.168.119.200;    #创建虚拟机的网络范围
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;


//同步cobbler配置
[root@yuli ~]# systemctl restart httpd
[root@yuli ~]# 
[root@yuli ~]# systemctl restart cobblerd.service 
[root@yuli ~]#  cobbler sync
task started: 2022-09-25_165448_sync
task started (id=Sync, time=Sun Sep 25 16:54:48 2022)
running python triggers from /var/lib/cobbler/triggers/task/sync/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/sync/pre/*
shell triggers finished successfully
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/system
removing: /var/lib/tftpboot/grub/system_link
removing: /var/lib/tftpboot/grub/images
copying bootloaders
running: ['rsync', '-rpt', '--copy-links', '--exclude=.cobbler_postun_cleanup', '/var/lib/cobbler/loaders/', '/var/lib/tftpboot']
received on stdout: 
received on stderr: 
running: ['rsync', '-rpt', '--copy-links', '--exclude=README.grubconfig', '/var/lib/cobbler/grub_config/', '/var/lib/tftpboot']
received on stdout: 
received on stderr: 
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
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/*
shell triggers finished successfully
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running python trigger cobbler.modules.managers.genders
running shell triggers from /var/lib/cobbler/triggers/change/*
shell triggers finished successfully
*** TASK COMPLETE ***

管理distro
//挂载镜像
[root@yuli ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@yuli ~]# ls /mnt/
AppStream  BaseOS  EFI  images  isolinux  LICENSE  media.repo  TRANS.TBL
[root@yuli ~]# 


//导入镜像
[root@yuli ~]# cobbler import --path=/mnt/ --name=yuli arch=x86_64 
task started: 2022-09-25_170010_import
task started (id=Media import, time=Sun Sep 25 17:00:10 2022)
running python triggers from /var/lib/cobbler/triggers/task/import/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/import/pre/*
shell triggers finished successfully
Found a candidate signature: breed=redhat, version=rhel8
Found a matching signature: breed=redhat, version=rhel8
Adding distros from path /var/www/cobbler/distro_mirror/yuli:
creating new distro: yuli-x86_64
trying symlink: /var/www/cobbler/distro_mirror/yuli -> /var/www/cobbler/links/yuli-x86_64
creating new profile: yuli-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/distro_mirror/yuli for yuli-x86_64
processing repo at : /var/www/cobbler/distro_mirror/yuli/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/yuli/AppStream
looking for /var/www/cobbler/distro_mirror/yuli/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/yuli/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/yuli/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/yuli/BaseOS
looking for /var/www/cobbler/distro_mirror/yuli/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/yuli/BaseOS/repodata
*** TASK COMPLETE ***



//安装源的唯一标示就是根据name参数来定义,
本例导入成功后,安装源的唯一标示就是:yuli-x86_64,如果重复,系统会提示导入失败



//查看cobbler镜像列表
[root@yuli ~]# cobbler list
distros:
   yuli-x86_64

profiles:
   yuli-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:
[root@yuli ~]# 



//查看详细信息  查看指定的--name 接镜像名
[root@yuli ~]# cobbler distro report --name  yuli-x86_64 
Name                           : yuli-x86_64
Architecture                   : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/yuli-x86_64'}
TFTP Boot Files                : {}
Boot loader                    : grub
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/distro_mirror/yuli/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/distro_mirror/yuli/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Management Classes             : []
OS Version                     : rhel8
Owners                         : ['admin']
Redhat Management Key          : 
Remote Boot Initrd             : ~
Remote Boot Kernel             : ~
Template Files                 : {}





//创建kickstarts自动安装脚本
[root@yuli ~]# cobbler profile get-autoinstall --name yuli-x86_64 > /var/lib/cobbler/templates/centos8.ks
[root@yuli ~]# 

[root@yuli ~]# vim  /var/lib/cobbler/templates/centos8.ks
# Sample kickstart file for current EL, Fedora based distributions.

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disable                     #关闭防火墙
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=http://192.168.119.157/cblr/links/yuli-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.119.157/cobbler/distro_mirror/yuli/AppStream
repo --name=source-2 --baseurl=http://192.168.119.157/cobbler/distro_mirror/yuli/BaseOS

# Network information
network --bootproto=dhcp --device=eth0 --onboot=on  

# Reboot after installation
reboot

#Root password
rootpw --iscrypted $1$14933$cHhbbIfL.PRFRqKLjYMVt1
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  America/New_York
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
autopart

%pre
set -x -v
exec 1>/tmp/ks-pre.log 2>&1

# Once root's homedir is there, copy over the log.
while : ; do
    sleep 10
    if [ -d /mnt/sysimage/root ]; then
        cp /tmp/ks-pre.log /mnt/sysimage/root/
        logger "Copied %pre section log to system"
        break
    fi
done &



# Enable installation monitoring

%end

%packages
@^minimal-environment            #设置最小安装
%end

%post --nochroot
set -x -v
exec 1>/mnt/sysimage/root/ks-post-nochroot.log 2>&1

%end

%post
set -x -v
exec 1>/root/ks-post.log 2>&1

# Start yum configuration
curl "http://192.168.119.157/cblr/svc/op/yum/profile/yuli-x86_64" --output /etc/yum.repos.d/cobbler-config.repo

# End yum configuration


//此时使用虚拟机去安装系统并不会成功  需要做如下操作
[root@yuli ~]# cd /usr/share/cobbler/bin/
[root@yuli bin]# ls
migrate-data-v2-to-v3.py  migrate-settings.sh  mkgrub.sh  settings-migration-v1-to-v2.sh
[root@yuli bin]# ls /var/lib/cobbler/loaders/
menu.c32  pxelinux.0
[root@yuli bin]# bash mkgrub.sh 
[root@yuli bin]# ls /var/lib/cobbler/loaders/
grub  ldlinux.c32  menu.c32  pxelinux.0
[root@yuli bin]# 
[root@yuli bin]# systemctl restart httpd
[root@yuli bin]# systemctl restart cobblerd.service

手动安装,创建一个新的虚拟机

cobbler介绍 cobbler官网_配置文件

cobbler介绍 cobbler官网_网络_02

cobbler介绍 cobbler官网_cobbler介绍_03

cobbler介绍 cobbler官网_cobbler介绍_04

cobbler介绍 cobbler官网_网络_05

cobbler介绍 cobbler官网_cobbler介绍_06

cobbler介绍 cobbler官网_运维_07

cobbler介绍 cobbler官网_cobbler介绍_08

cobbler介绍 cobbler官网_linux_09

密码是Redhat

cobbler介绍 cobbler官网_配置文件_10

自动安装,一个新的虚拟机

使用浏览器访问https://192.168.119.157/cobbler_web
默认登录的用户名和密码都为cobbler

cobbler介绍 cobbler官网_运维_11

cobbler介绍 cobbler官网_配置文件_12

cobbler介绍 cobbler官网_cobbler介绍_13

cobbler介绍 cobbler官网_配置文件_14

cobbler介绍 cobbler官网_cobbler介绍_15

cobbler介绍 cobbler官网_网络_16

cobbler介绍 cobbler官网_配置文件_17

cobbler介绍 cobbler官网_cobbler介绍_18

cobbler介绍 cobbler官网_cobbler介绍_19

cobbler介绍 cobbler官网_网络_20

cobbler介绍 cobbler官网_运维_21

cobbler介绍 cobbler官网_网络_22

cobbler介绍 cobbler官网_linux_23

cobbler介绍 cobbler官网_配置文件_24

cobbler介绍 cobbler官网_运维_25

cobbler介绍 cobbler官网_运维_26

cobbler介绍 cobbler官网_cobbler介绍_27

cobbler介绍 cobbler官网_配置文件_28

安装完成,登录
账号root
密码redhat
新的虚拟机的IP地址是刚才设置的192.168.119.150

cobbler介绍 cobbler官网_配置文件_29