Cobbler 无人值守安装操作系统

术语

PXE (preboot execute environment,预启动执行环境) 是由 Intel 公司设计的协议,它可以使计算机通过网络启动。


批量装机软件介绍

Redhat系主要有两种Kickstart和Cobbler。

Kickstart是一种无人值守的安装方式。它的工作原理是在安装过程中记录人工干预填写的各种参数,并生成一个名为ks.cfg的文件。如果在自动安装过程中出现要填写参数的情况,安装程序首先会去查找ks.cfg文件,如果找到合适的参数,就采用所找到的参数;如果没有找到合适的参数,便会弹出对话框让安装者手工填写。所以,如果ks.cfg文件涵盖了安装过程中所有需要填写的参数,那么安装者完全可以只告诉安装程序从何处下载ks.cfg文件,然后就去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中的设置重启/关闭系统,并结束安装。

Cobbler集中和简化了通过网络安装操作系统需要使用到的DHCP、TFTP和DNS服务的配置。

Cobbler不仅有一个命令行界面,还提供了一个Web界面,大大降低了使用者的入门水平(web界面不是很好用)

简单的说,Cobbler是对kickstart的封装,简化安装步骤、使用流程,降低使用者的门槛。


Cobbler可以干什么

  • 服务器上架后,可以手动选择需要安装的系统(如:Centos6.8 或 Centos 7.3)
  • 服务器上架后,能够根据需求,安装配置操作系统(如:修改IP地址、主机名、选择安装包)
  • 系统安装后,可以自定义的执行脚本,完成系统基础软件初始化(如:Zabbix安装配置、SaltStack安装配置)
  • 可以当内部YUM源,并在系统安装时进行初始化
  • 可以重装系统
  • Cobbler支持API,可以无缝融合到自建运维平台中
  • Cobbler支持网卡的路由配置、DNS配置、bonding

Cobbler工作原理

其实cobbler的原理,就是kickstart脚本安装原理,简单的说Cobbler是对kickstart的封装,简化安装步骤、使用流程,降低使用者的门槛。

image-20240109111917252


Server端

  1. 启动cobbler服务
  2. 进行cobbler错误检查,执行cobbler check 命令
  3. 进行配置同步,执行 cobbler sync命令
  4. 复制相关启动文件到 TFTP 目录中
  5. 启动 DHCP服务,提供地址分配
  6. DHCP服务分配IP地址
  7. TFTP传输启动文件
  8. Server端接收安装信息
  9. Server端发送ISO镜像与Kickstart文件

Client端

  1. 客户端以PXE模式启动 (PXE客户端(client)这个术语是指机器在PXE启动过程中的角色。一个PXE客户端可以是一台服务器、笔记本电脑或者其他装有PXE启动代码的机器
  2. 客户端获取IP地址 ,客户端通过udp向服务端获取ip地址的。
  3. 通过TFTP服务器获取启动文件,得到文件后才能进入Cobbler安装选择界面
  4. 进入Cobbler安装选择界面
  5. 客户端确定加载信息
  6. 根据配置信息准备安装系统
  7. 加载Kickstart文件
  8. 传输系统安装的其它文件
  9. 进行安装系统

PXE+KS安装全过程

image-20240109113424623

  1. PXE Client向DHCP发送请求 PXE Client从自己的PXE网卡启动,通过PXE BootROM(自启动芯片)会以UDP(简单用户数据报协议)发送一个广播请求,向本网络中的DHCP服务器索取IP;
  2. DHCP服务器提供信息 DHCP服务器收到客户端的请求,验证是否来至合法的PXE Client的请求,验证通过它将给客户端一个“提供”响应,这个“提供”响应中包含了为客户端分配的IP地址、pxelinux启动程序(TFTP)位置,以及配置文件所在位置;
  3. PXE客户端请求下载启动文件 客户端收到服务器的“回应”后,会回应一个帧,以请求传送启动所需文件。这些启动文件包括:pxelinux.0、pxelinux.cfg/default、vmlinuz、initrd.img等文件。
  4. Boot Server响应客户端请求并传送文件 当服务器收到客户端的请求后,他们之间之后将有更多的信息在客户端与服务器之间作应答, 用以决定启动参数。BootROM由TFTP通讯协议从Boot Server下载启动安装程序所必须的文件(pxelinux.0、pxelinux.cfg/default)。default文件下载完成后,会根据该文件中定义的引导顺序,启动Linux安装程序的引导内核。
  5. 请求下载自动应答文件 客户端通过pxelinux.cfg/default文件成功的引导Linux安装内核后,安装程序首先必须确定你通过什么安装介质来安装linux,如果是通过网络安装(NFS, FTP, HTTP),则会在这个时候初始化网络,并定位安装源位置。接着会读取default文件中指定的自动应答文件ks.cfg所在位置,根据该位置请求下载该文件。
  6. 这里有个问题,在第2步和第5步初始化2次网络了,这是由于PXE获取的是安装用的内核以及安装程序等,而安装程序要获取的是安装系统所需的二进制包以及配置文件。因此PXE模块和安装程序是相对独立的,PXE的网络配置并不能传递给安装程序,从而进行两次获取IP地址过程,但IP地址在DHCP的租期内是一样的。
  7. 客户端安装操作系统 将ks.cfg文件下载回来后,通过该文件找到OS Server,并按照该文件的配置请求下载安装过程需要的软件包。 OS Server和客户端建立连接后,将开始传输软件包,客户端将开始安装操作系统。安装完成后,将提示重新引导计算机。

部署Cobbler过程


环境介绍

这里使用 vmware虚拟机进行测试环境的搭建。

1台 Linux 虚拟机作为Server服务端,IP地址:10.0.0.10

1台 客户端虚拟机作为Client端,待安装操作系统


思路:

  1. tftp:压缩内核,引导程序(速度快)
  2. dhcp:自动分配IP地址使client和server端互通
  3. http:iso镜像文件传输
  4. cobbler:自动部署装机

vmware nat 网络调整

image-20240109150247408


创建cobbler虚拟机

image-20240109150459450


安装操作系统及系统初始化

  1. 安装操作系统,这里采用 Centos7.9
  2. 配置IP为:10.0.0.10
  3. 关闭selinux和 firewalld

以上步骤不再详细演示。


配置yum安装软件

root@localhost(10.0.0.10)~> mkdir -pv /etc/yum.repos.d/bak
mkdir: created directory ‘/etc/yum.repos.d/bak’
root@localhost(10.0.0.10)~> mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/

root@localhost(10.0.0.10)~> curl http://mirrors.aliyun.com/repo/Centos-7.repo -o /etc/yum.repos.d/Centos-7.repo
root@localhost(10.0.0.10)~> curl http://mirrors.aliyun.com/repo/epel-7.repo -o /etc/yum.repos.d/epel-7.repo

安装Cobbler软件

Cobbler安装包介绍

# 安装包
cobbler          #cobbler程序包
cobbler-web      #cobbler的web服务包
pykickstart      #cobbler检查kickstart语法错误
httpd            #Apache web服务
dhcp             #Dhcp服务
tftp             #tftp服务
xinetd           #超级守护进程服务

 # cobbler配置文件所在目录:/etc/cobbler
/etc/cobbler                        # 配置文件目录
/etc/cobbler/settings               # cobbler主配置文件
/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模块配置文件

# 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源存储目录

# cobbler日志文
/var/log/cobbler                    # 日志目录
/var/log/cobbler/install.log        # 客户端系统安装日志
/var/og/cobbler/cobbler.log        # cobbler日志

cobbler命令详解

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

服务选型及介绍


DHCP服务

由于我们是实现自动化批量安装部署,所以,能够与其他主机通信是前提,而要想获取IP并实现通信,我们必须要有DHCP服务器为大量的主机提供ip地址才行。


HTTP服务

由于我们要获取安装系统服务的yum源以及内核文件,虚拟根文件,这些文件都是大文件,在传输时我们必须保证其能够安全传输,所以我们选择了HTTP服务,当然了,选择FTP服务也是可以的。


TFTP服务

TFTP是一种文件传输服务,用于服务器与客户端进行文件的传输,不过他只能进行简单的文件传输,这个服务开销不大,所以并不能进行大文件的传输,多用于小文件的传输。他没有FTP那么强大,但是TFTP使用UDP协议传输数据,有些时候比FTP更加方便,它所监听的端口为69。由于我们是在局域网中,系统相对安全,而提供的数据也不是很大,所以TFTP是实现PXE的不二选择。


cobbler安装

yum install -y cobbler cobbler-web dhcp tftp-server pykickstart httpd xinetd python-ctypes

需要启动服务如下:

# 服务自启动:
systemctl enable httpd 
systemctl enable xinetd 
systemctl enable rsyncd 
systemctl enable tftp 
systemctl enable dhcpd
systemctl enable cobblerd

修改cobbler配置文件

修改以下配置项
root@localhost(10.0.0.10)~> vim /etc/cobbler/settings
...
bind_master: 10.0.0.10
next_server: 10.0.0.10
server: 10.0.0.10
manage_dhcp: 1
pxe_just_once: 1

#通过 openssl passwd -1 -salt `openssl rand 15 -base64` '123123' ,该项为客户端安装完成后root密码,这里root密码为:123123
default_password_crypted: "$1$mnDole4r$rR.qmpianI98HUP2GtmXv1"	

allow_dynamic_settings: 1
...

修改DHCP配置文件

这里不是直接修改dhcp 配置文件,而是通过 修改 /etc/cobbler/dhcp.template 来自动生成 /etc/dhcp/dhcpd.conf 文件

root@localhost(10.0.0.10)~> vim /etc/cobbler/dhcp.template
#注意修改为10.0.0.0/24 网段的IP
...
subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.2;
     option domain-name-servers 10.0.0.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
...

启动服务

# 启动服务:
systemctl start httpd 
systemctl start xinetd 
systemctl start rsyncd
systemctl start tftp 
systemctl start cobblerd

同步cobbler服务

root@localhost(10.0.0.10)~> cobbler sync
task started: 2024-01-10_005825_sync
task started (id=Sync, time=Wed Jan 10 00:58:25 2024)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
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/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

查看 dhcp配置文件验证:

root@localhost(10.0.0.10)~> cat /etc/dhcp/dhcpd.conf
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Tue Jan  9 16:58:26 2024)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# ******************************************************************

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;

subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.2;
     option domain-name-servers 10.0.0.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                10.0.0.10;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "grub/grub-x86.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "grub/grub-x86_64.efi";
          } else if option pxe-system-type = 00:09 {
                  filename "grub/grub-x86_64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }

}

# group for Cobbler DHCP tag: default
group {
}

查看 dhcpd服务状态:

root@localhost(10.0.0.10)~> systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2024-01-10 00:58:26 CST; 1min 26s ago
...

检查cobbler运行环境

root@localhost(10.0.0.10)~> 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 haveinstalled 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.
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : 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.

注意:在正式环境中,使用 cobbler为服务器安装操作系统时,由于第一个问题未解决,造成无法进行PXE安装,所有这里需要解决第一个问题。

这里执行 cobbler get-loaders 会出现如下报错信息:

root@localhost(10.0.0.10)~> cobbler get-loaders
No such command: get-loaders

#版本信息
root@localhost(10.0.0.10)~> cobbler version
Cobbler 2.8.5
  source: ?, ?
  build time: Wed Mar 23 13:35:14 2022

既然无法拉取,就直接下载别人做好的文件拷贝到指定目录即可。

通过浏览器打开链接:https://github.com/hbokh/cobbler-loaders/blob/main/files/cobbler-loaders.tar.gz 点击下载:

image-20240109171252605

将下载后的文件上传到服务器解压并拷贝到指定目录:

root@localhost(10.0.0.10)~> tar xf cobbler-loaders.tar.gz -C /

执行check查看

root@localhost(10.0.0.10)~> 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
2 : 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.

通过上面操作,第一个loaders问题得到解决,如上的两个问题直接忽略不会出现问题。


配置TFTP

#修改如下两项配置
root@localhost(10.0.0.10)~> vim /etc/xinetd.d/tftp
...
disable = no
wait = yes
...

重启服务

由于上面做了一系列配置变更,这里需要重新服务

systemctl restart xinetd 
systemctl restart rsyncd
systemctl restart tftp 
systemctl restart cobblerd

配置distro

主要用来定义和设置系统发行版本,里包含了系统的内核,引导文件,以及安装包等内容,就相当于一个LINUX系统的ISO镜像。如:多个发行版本,同一发行版不同版本号。

  • Cobbler 变得可用的第一步为定义 distro,其可以通过为其指定外部的安装引导内核及 ramdisk 文件的方式实现。
  • 如果已经有完成的安装树(如 OS 的安装镜像)则推荐使用 improt 导入的方式进行。
  • 导入镜像

挂载系统镜像文件

由于这里为虚拟机,直接挂载 CD/DVD 即可。

root@localhost(10.0.0.10)~> mkdir -pv /mnt/centos7.9
mkdir: created directory ‘/mnt/centos7.9’
root@localhost(10.0.0.10)~> mount /dev/sr0 /mnt/centos7.9/
mount: /dev/sr0 is write-protected, mounting read-only
root@localhost(10.0.0.10)~> ls /mnt/centos7.9/
CentOS_BuildTag  EFI/  EULA  GPL  images/  isolinux/  LiveOS/  Packages/  repodata/  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL

导入镜像

root@localhost(10.0.0.10)~> cobbler import --path=/mnt/centos7.9 --name=CentOS-7.9-x86_64  --arch=x86_64
task started: 2024-01-10_012008_import
task started (id=Media import, time=Wed Jan 10 01:20:08 2024)
Found a candidate signature: breed=suse, version=opensuse15.0
Found a candidate signature: breed=suse, version=opensuse15.1
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.9-x86_64:
creating new distro: CentOS-7.9-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-7.9-x86_64 -> /var/www/cobbler/links/CentOS-7.9-x86_64
creating new profile: CentOS-7.9-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.9-x86_64 for CentOS-7.9-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-7.9-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7.9-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-7.9-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7.9-x86_64/repodata
*** TASK COMPLETE ***

查看distro配置

root@localhost(10.0.0.10)~> cobbler distro list	#查看镜像列表
   CentOS-7.9-x86_64
   
# 镜像存放目录,Cobbler 会将镜像中的所有安装文件拷贝到本地一份,放在 /var/www/cobbler/ks_mirror 下的 CentOS-7.9-x86_64目录下。
# 因此 /var/www/cobbler 目录必须具有足够容纳安装文件的空间。
root@localhost(10.0.0.10)~> ll /var/www/cobbler/ks_mirror/
total 0
0 drwxr-xr-x 2 root root  36 2024-01-10 01:20:36 config/
0 drwxr-xr-x 8 root root 254 2020-11-03 22:53:51 CentOS-7.9-x86_64/

root@localhost(10.0.0.10)~> cobbler distro report	#查看详细信息
Name                           : CentOS-7.9-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        :
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/CentOS-7.9-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/CentOS-7.9-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7.9-x86_64'}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}


自定义配置 profile

定义自动安装的应答文件,主要用来定义kickstart配置文件,安装时依据配置文件进行定制化安装,配置此项时要和distro进行关联。

root@localhost(10.0.0.10)~> cobbler distro report
Name                           : CentOS-7.9-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        :
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/CentOS-7.9-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/CentOS-7.9-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7.9-x86_64'}	#镜像路径
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}


root@localhost(10.0.0.10)~> cobbler profile report
Name                           : CentOS-7.9-x86_64
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : CentOS-7.9-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks	#关联的ks应答文件
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 :
Internal proxy                 :
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      :
Virt RAM (MB)                  : 512
Virt Type                      : kvm


准备ks文件

可通过如下模板文件进行修改即可:

重点需要修改的地方为:磁盘分区 autopart 部分,往往在自动安装时,无法应答而需要人工干预的也是这部分的应答配置项。

# This kickstart file should only be used with EL > 5 and/or Fedora > 7.
# For older versions please use the sample.ks kickstart file.

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --passalgo=sha512
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# graphical
# Firewall configuration
firewall --disabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8  --addsupport=zh_CN.UTF-8
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot

#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
# autopart
part /boot --fstype="xfs" --asprimary  --size=2048
part /home --fstype="xfs" --asprimary --size=1024
part swap --fstype="swap" --size=1024
part / --fstype="xfs" --grow --asprimary --size=1

%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end

%packages
$SNIPPET('func_install_if_enabled')
@^minimal
@core

%end

%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end

%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
%end

将修改后的文件保存如下:

root@localhost(10.0.0.10)~> vim /var/lib/cobbler/kickstarts/CentOS-7-x86_64.ks.cfg

动态编辑指定新的ks文件

注意:该步骤非常重要!

root@localhost(10.0.0.10)~> cobbler profile edit  --name=CentOS-7.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.ks.cfg

#查看配置信息
root@localhost(10.0.0.10)~> cobbler profile report
Name                           : CentOS-7.9-x86_64
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : CentOS-7.9-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/CentOS-7-x86_64.ks.cfg	#ks文件已经更新
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 :
Internal proxy                 :
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      :
Virt RAM (MB)                  : 512
Virt Type                      : kvm


#每次修改都需要执行一次 sync
root@localhost(10.0.0.10)~> cobbler sync

到此,cobbler server端已配置完成。


client客户端装系统

新建一台虚拟机,注意网络选择为 nat 模式。

注意:如果这里是物理机的安装,则需要开机选择网络启动的方式。

image-20240109174018971

选择 CentOS-7.9-x86_64 即可开始安装操作系统。

安装完成后,查看分区信息:

image-20240109180154938


Cobbler 与 win10 结合的无人值守请参考 https://anjia0532.github.io/2019/02/22/cobbler-win10-win-server-2019/



参考链接

https://zhuanlan.zhihu.com/p/375918700

https://zhuanlan.zhihu.com/p/465121509

https://github.com/hbokh/cobbler-loaders/blob/main/files/cobbler-loaders.tar.gz


--- EOF ---
posted @ 2024-02-21 11:20  hukey  阅读(298)  评论(0编辑  收藏  举报