cobbler部署(CentOS 7~8)
文章目录
1. cobbler简介
Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack
Cobbler官网手册:cobbler.readthedocs.io
cobbler集成的服务
- PXE服务支持
- DHCP服务管理
- DNS服务管理(可选bind,dnsmasq)
- 电源管理
- Kickstart服务支持
- YUM仓库管理
- TFTP(PXE启动时需要)
- Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
cobbler命令详解
命令 | 说明 |
---|---|
cobbler check | 核对当前设置是否有问题 |
cobbler list | 列出所有的cobbler元素 |
cobbler report | 列出元素的详细信息 |
cobbler sync | 同步配置到数据目录,更改配置最好都要执行下 |
cobbler reposync | 同步yum仓库 |
cobbler distro | 查看导入的发行版系统信息 |
cobbler system | 查看添加的系统信息 |
cobbler profile | 查看配置信息 |
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日志 |
2. cobbler服务端部署
2.1 CentOS7系统部署
主机IP | 已配置 | 系统 |
---|---|---|
192.168.10.104 | yum源、epel源 | Centos7 |
关闭防火墙和selinux
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
安装cobbler以及相关的软件
[root@localhost ~]# yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart
# 启动服务并设置开机自启
[root@localhost ~]# systemctl enable --now httpd
[root@localhost ~]# systemctl enable --now cobblerd
[root@localhost ~]# systemctl enable --now rsyncd
修改server、tftp的ip地址为本机ip,开启dhcp,密码加密
# 生成加密密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" '123456'
$1$21705$jh1Vn8HkBBwjg0KihvWEl.
# 将新生成的密码加入配置文件
[root@localhost ~]# vim /etc/cobbler/settings
...
server: 192.168.10.104 #修改为本机IP
...
next_server: 192.168.10.104
...
manage_dhcp: 1 #开动dhcp
...
default_password_crypted: "$1$21705$jh1Vn8HkBBwjg0KihvWEl." #密码加密
...
配置dhcp的网络模板设置
[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.10.0 netmask 255.255.255.0 { #本机网段
option routers 192.168.10.104; #本机IP地址或网关
option domain-name-servers 192.168.10.2; #dns
option subnet-mask 255.255.255.0; #子网掩码
range dynamic-bootp 192.168.10.150 192.168.1.155; #IP动态分配范围
default-lease-time 21600; #默认租期
max-lease-time 43200; #最大默认租期
next-server $next_server;
配置tftp
vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no #默认disable状态,改成no不是这个状态,就是开启
per_source = 11
cps = 100 2
flags = IPv4
}
通过cobbler check 核对当前设置是否有问题
# 安装代理包
[root@localhost ~]# yum -y install fence-agents
# 重启服务
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart cobblerd
# cobbler语法检测
# 这两个是关于debian系统的错误,可以忽略
[root@localhost ~]# 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, elilo.efi, and yaboot.
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
Restart cobblerd and then run 'cobbler sync' to apply changes.
配置完,必须同步sync配置
[root@localhost ~]# cobbler sync
task started: 2022-08-12_024208_sync
task started (id=Sync, time=Fri Aug 12 02:42:08 2022)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
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 ~]# yum -y install net-tools
[root@localhost ~]# netstat -anulp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 11690/dhcpd
导入centos7镜像
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]#
[root@localhost ~]# cobbler import --path=/mnt --name=centos7 --arch=x86_64
task started: 2022-08-12_024636_import
task started (id=Media import, time=Fri Aug 12 02:46:36 2022)
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/centos7-x86_64:
creating new distro: centos7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7-x86_64 -> /var/www/cobbler/links/centos7-x86_64
creating new profile: centos7-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/centos7-x86_64 for centos7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7-x86_64
looking for /var/www/cobbler/ks_mirror/centos7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7-x86_64/repodata
*** TASK COMPLETE ***
//说明:
--path //镜像路径
--name //为安装源定义一个名字
--arch //指定安装源平台
# 查看导入镜像目录(ks_mirror)的内容
[root@localhost ~]# ls /var/www/cobbler/ks_mirror/centos7-x86_64/
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
# 查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
centos7-x86_64
profiles:
centos7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
创建kickstarts自动安装脚本
脚本是根据anaconda-ks.cfg
文件写的
[root@localhost ~]# cat anaconda-ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512 #身份验证和算法,算法采用sha512格式
# Use CDROM installation media
cdrom #使用光盘安装的
# Use graphical install
graphical #安装方式,图形化
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda #有多个磁盘的话,忽略,只安装sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us' #键盘格式
# System language
lang en_US.UTF-8 #系统语言
# Network information #网络类型和主机名
network --bootproto=dhcp --device=ens33 --ipv6=auto --activate
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted #本机加密过后的密码 $6$dT2ovTS5e9ns3Kkb$dWVA9m.jeR6W8acad1P3NGhKK6H/5PKq8heRHykC1JsGOT4hISlAZ.TzuNTwdKNbM2QfkDKxxhn3uSDiw1orl0
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp #系统时区
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel #清空所有分区
%packages
@^minimal
@core
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%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
[root@localhost ~]# vim /var/lib/cobbler/kickstarts/centos7-x86_64.ks
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.10.104/cobbler/ks_mirror/centos7-x86_64
$yum_repo_stanza
reboot
rootpw --iscrypted $6$dT2ovTS5e9ns3Kkb$dWVA9m.jeR6W8acad1P3NGhKK6H/5PKq8heRHykC1JsGOT4hISlAZ.TzuNTwdKNbM2QfkDKxxhn3uSDiw1orl0
selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr
%packages
@^minimal
@core
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%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
检查ks文件语法是否有误
[root@localhost ~]# cobbler validateks
task started: 2022-08-12_042351_validateks
task started (id=Kickstart Validation, time=Fri Aug 12 04:23:51 2022)
----------------------------
osversion: rhel7
checking url: http://192.168.10.104/cblr/svc/op/ks/profile/centos7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.10.104/cblr/svc/op/ks/profile/centos7-x86_64"
received on stdout:
received on stderr:
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***
# 查看当前cobbler有哪些配置文件
[root@localhost ~]# cobbler profile list
centos7-x86_64
修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
配置网卡名称为传统网卡名称eth0
[root@localhost ~]# cobbler profile edit --name centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7-x86_64.ks
[root@localhost ~]# cobbler profile edit --name centos7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
检查当前系统cobbler配置文件信息
[root@localhost ~]# cobbler profile report
Name : centos7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : centos7-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/centos7-x86_64.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
同步cobbler
[root@localhost ~]# cobbler sync
task started: 2022-08-12_043207_sync
task started (id=Sync, time=Fri Aug 12 04:32:07 2022)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
copying distros to tftpboot
copying files for distro: centos7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7-x86_64/initrd.img
Writing template files for centos7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos7-x86_64
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 ***
服务端服务重启
[root@localhost ~]# systemctl restart xinetd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 :::873 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::443 :::*
2.1.1 客户端安装
新建一个名字为test的虚拟机,内存2G,使用物理驱动,网路nat模式
选择centos7-x86_64进行自动安装
2.2 CentOS8系统部署
主机IP | 系统 |
---|---|
192.168.10.105 | CentOS8 |
关闭防火墙和selinux
[root@CentOS_8 ~]# systemctl disable --now firewalld
[root@CentOS_8 ~]# setenforce 0
[root@CentOS_8 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
使用系统自带的yum源安装相关软件包
[root@CentOS_8 ~]# ls /etc/yum.repos.d/
CentOS-Stream-AppStream.repo CentOS-Stream-Extras.repo CentOS-Stream-PowerTools.repo
CentOS-Stream-BaseOS.repo CentOS-Stream-HighAvailability.repo CentOS-Stream-RealTime.repo
CentOS-Stream-Debuginfo.repo CentOS-Stream-Media.repo
# 安装epel源
[root@CentOS_8 ~]# dnf -y install epel-release
# 开启cobbler模块
[root@CentOS_8 ~]# dnf module list | grep cobbler
cobbler 3 default [d] Versatile Linux deployment server
cobbler 3.3 default Versatile Linux deployment server
[root@CentOS_8 ~]# dnf -y module enable cobbler:3
[root@CentOS_8 ~]# dnf -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync-daemon yum-utils syslinux syslinux-extlinux syslinux-tftpboot
# 开启服务并设置开机自启
[root@CentOS_8 ~]# systemctl enable --now httpd cobblerd rsyncd dhcpd tftp
修改server、tftp的ip地址为本机ip,开启dhcp,密码加密
[root@CentOS_8 ~]# openssl passwd -1 -salt "$RANDOM" '123456'
$1$12291$mMbbgyuR2u13fVli3rrCF/
# 将新生成的密码加入配置文件
[root@CentOS_8 ~]# vim /etc/cobbler/settings.yaml
...
server: 192.168.10.105 #修改为本机IP
...
next_server: 192.168.10.105
...
manage_dhcp: true #开动dhcp
...
default_password_crypted: "$1$28304$TkeLqaZJ6KciT2p79UFxC/" #加密过后的密码
配置dhcp的网络模板设置
[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.10.0 netmask 255.255.255.0 { #本机网段
option routers 192.168.10.105; #本机IP地址或网关
option domain-name-servers 192.168.10.2; #dns
option subnet-mask 255.255.255.0; #子网掩码
range dynamic-bootp 192.168.10.155 192.168.1.160; #IP动态分配范围
default-lease-time 21600; #默认租期
max-lease-time 43200; #最大默认租期
next-server $next_server;
# 重启服务
[root@CentOS_8 ~]# systemctl restart httpd cobblerd
复制配置文件到/var/lib/cobbler/loaders/
目录内,并执行脚本
[root@CentOS_8 ~]# cp /usr/share/syslinux/pxelinux.0 /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@CentOS_8 ~]# /usr/share/cobbler/bin/mkgrub.sh
[root@CentOS_8 ~]# ls /var/lib/cobbler/loaders/
grub ldlinux.c32 menu.c32 pxelinux.0
同步sync配置
[root@CentOS_8 ~]# cobbler sync
......(省略)
running python trigger cobbler.modules.managers.genders
running shell triggers from /var/lib/cobbler/triggers/change/*
shell triggers finished successfully
*** TASK COMPLETE ***
挂载镜像并导入
[root@CentOS_8 ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@CentOS_8 ~]# ls /mnt/
AppStream BaseOS EFI images isolinux LICENSE media.repo TRANS.TBL
[root@CentOS_8 ~]# cobbler import --name=centos8 --arch=X86_64 --path=/mnt
......(省略)
need to process repo/comps: /var/www/cobbler/distro_mirror/centos8-x86_64/BaseOS
looking for /var/www/cobbler/distro_mirror/centos8-x86_64/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/centos8-x86_64/BaseOS/repodata
*** TASK COMPLETE ***
列出镜像
[root@CentOS_8 ~]# cobbler list
distros:
centos8-x86_64
profiles:
centos8-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
[root@CentOS_8 ~]# cobbler distro report
Name : centos8-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/centos8-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/centos8-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/centos8-x86_64/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 : {}
自动生成ks文件内容
[root@CentOS_8 ~]# cobbler profile get-autoinstall --name centos8-x86_64
# 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 --enabled
# 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.10.105/cblr/links/centos8-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.10.105/cobbler/distro_mirror/centos8-x86_64/AppStream
repo --name=source-2 --baseurl=http://192.168.10.105/cobbler/distro_mirror/centos8-x86_64/BaseOS
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$28304$TkeLqaZJ6KciT2p79UFxC/
# 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
%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.10.105/cblr/svc/op/yum/profile/centos8-x86_64" --output /etc/yum.repos.d/cobbler-config.repo
# End yum configuration
# Start post_install_network_config generated code
# End post_install_network_config generated code
# Start download cobbler managed config files (if applicable)
# End download cobbler managed config files (if applicable)
# Start koan environment setup
echo "export COBBLER_SERVER=192.168.10.105" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.10.105" > /etc/profile.d/cobbler.csh
# End koan environment setup
$SNIPPET('redhat_register')
# Begin cobbler registration
# cobbler registration is disabled in /etc/cobbler/settings.yaml
# End cobbler registration
# Enable post-install boot notification
# Start final steps
curl "http://192.168.10.105/cblr/svc/op/autoinstall/profile/centos8-x86_64" -o /root/cobbler.ks
# End final steps
%end
将生成的ks文件内容写入/var/lib/cobbler/templates/
目录下
[root@CentOS_8 ~]# cd /var/lib/cobbler/templates/
[root@CentOS_8 templates]# vim centos8.ks
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
......(省略)
# 自动安装
[root@CentOS_8 ~]# cobbler validate-autoinstalls
task started: 2022-08-13_182323_validate_autoinstall_files
task started (id=Automated installation files validation, time=Sat Aug 13 18:23:23 2022)
running python triggers from /var/lib/cobbler/triggers/task/validate_autoinstall_files/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/validate_autoinstall_files/pre/*
shell triggers finished successfully
*** TASK COMPLETE ***
修改profile,配置网卡名称为传统网卡名称
[root@CentOS_8 ~]# cobbler profile edit --name centos8-x86_64 --autoinstall centos8.ks
[root@CentOS_8 ~]# cobbler profile edit --name centos8-x86_64 --kernel-options 'net.ifnames=0 biosdevname=0'
[root@CentOS_8 ~]# cobbler profile report --name centos8-x86_64
Name : centos8-x86_64
Automatic Installation Template : centos8.ks
Automatic Installation Metadata : {}
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : centos8-x86_64
Enable gPXE? : False
Enable PXE Menu? : True
Fetchable Files : {}
DHCP Filename Override : <<inherit>>
Kernel Options : {'net.ifnames': '0', 'biosdevname': '0'}
Kernel Options (Post Install) : {}
Management Classes : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Next Server Override : <<inherit>>
Owners : ['admin']
Parent Profile :
Proxy :
Red Hat Management Key : <<inherit>>
Repos : []
Server Override : <<inherit>>
Template Files : {}
Virt Auto Boot : True
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
同步并重启服务
[root@CentOS_8 ~]# cobbler sync
[root@CentOS_8 ~]# systemctl restart httpd cobblerd dhcpd
2.2.1 客户端安装
新建一个名字为test_8的虚拟机,内存2G,硬盘30G,使用物理驱动,网路nat模式
3. 定制安装
定制安装步骤:
- 统计服务器mac地址
- 配置cobbler
- 安装
在 cobbler 的web界面上配置
用户名和密码都是cobbler
添加新系统