基于CentOS8操作cobbler批量装机
- 1. cobbler简介
- 2. cobbler服务端部署
- 3. 客户端安装
- 4. 定制安装
- 5.报错信息
1. cobbler简介
Cobbler
是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP
,DNS
等。
Cobbler
可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler
是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler
内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
Cobbler
官网
cobbler集成的服务
- PXE服务支持
- DHCP服务管理
- DNS服务管理(可选bind,dnsmasq)
- 电源管理
- Kickstart服务支持
- YUM仓库管理
- TFTP(PXE启动时需要)
- Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
cobbler配置文件详解cobbler
配置文件目录在/etc/cobbler
配置文件 | 作用 |
/etc/cobbler/settings.yaml | 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 //查看配置信息
系统平台 | IP |
centos8 redhat8 | 192.168.229.148 |
2. cobbler服务端部署
关闭防火墙跟SElinux
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@localhost ~]# grep 'SELINUX=disabled' /etc/selinux/config
SELINUX=disabled
//配置yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# curl -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
// epel源
[root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[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*
// 查找cobbler, 并开启,
[root@localhost ~]# dnf module list|grep cobbler
cobbler 3 default [d] Versatile Linux deployment server
cobbler 3.3 default Versatile Linux deployment server
开启 cobbler , 注意要跟上版本
[root@localhost ~]# dnf module enable cobbler:3
Last metadata expiration check: 0:09:18 ago on Sat 13 Aug 2022 09:51:23 PM CST.
Dependencies resolved.
======================================================================
Package Architecture Version Repository Size
======================================================================
Enabling module streams:
cobbler 3
Transaction Summary
======================================================================
Is this ok [y/N]: y
Complete!
// 没有开启cobbler 模块是找不到的
[root@localhost ~]# dnf list all|grep cobbler
cobbler.noarch 3.2.2-11.module_el8+14161+f12890f2 epel-modular
cobbler-tests.noarch 3.2.2-11.module_el8+14161+f12890f2 epel-modular
cobbler-web.noarch 3.2.2-11.module_el8+14161+f12890f2 epel-modul
[root@localhost ~]# dnf list all|grep rsync
rsync.x86_64 3.1.3-12.el8 @base # 下载这个包
librsync.x86_64 2.3.2-1.el8 epel
librsync-devel.x86_64 2.3.2-1.el8 epel
librsync-doc.noarch 2.3.2-1.el8 epel
rsync-bpc.x86_64 3.1.3.0-1.el8 epel
rsync-daemon.noarch 3.1.3-12.el8 base # 下载这个包
//安装cobbler以及相关的软件
[root@localhost ~]# dnf -y install httpd dhcp-server tftp tftp-server cobbler cobbler-web pykickstart rsync-daemon rsync
安装过程略....
//启动服务并设置开机自启
[root@localhost ~]# systemctl enable --now tftp
[root@localhost ~]# systemctl enable --now dhcpd
[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl enable --now cobblerd
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 5 127.0.0.1:25151 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 *:443 *:*
[root@localhost ~]#
[root@localhost ~]# cd /etc/cobbler/
[root@localhost cobbler]# ls
auth.conf logging_config.conf secondary.template
boot_loader_conf modules.conf settings.d
cheetah_macros mongodb.conf settings.yaml //在8 里叫这个名字
dhcp.template named.template users.conf
dnsmasq.template ndjbdns.template users.digest
genders.template reporting version
import_rsync_whitelist rsync.exclude zone.template
iso rsync.template zone_templates
//修改server的ip地址为本机ip
[root@localhost ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.229.148/' /etc/cobbler/settings.yaml
//设置tftp的ip地址为本机ip
[root@localhost ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.229.148/' /etc/cobbler/settings.yaml
//启动rsync并设置开机自启
[root@localhost ~]# systemctl enable --now rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
[root@localhost ~]# systemctl status rsyncd
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; v>
Active: active (running) since Sat 2022-08-13 22:25:50 CST; 6s ago
//生成加密的密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" 'agan9639@'
746gpDrgEIXdIwdIUq3X3V// //这是密码加密后的形式
# 这个密码是给系统用的不必在意
//将新生成的加密密码加入到配置文件
[root@localhost ~]#sed -i '/default_password_crypted.*/c default_password_crypted: "746gpDrgEIXdIwdIUq3X3V//"' /etc/cobbler/settings.yaml
[root@localhost ~]# grep 'default_password_crypted.*' /etc/cobbler/settings.yaml
default_password_crypted: "746gpDrgEIXdIwdIUq3X3V//"
//重启cobbler
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 5 127.0.0.1:25151 0.0.0.0:*
LISTEN 0 5 0.0.0.0:873 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 *:443 *:*
//通过cobbler check 核对当前设置是否有问题
[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, 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.
//以上4和5是关于debian系统的错误,请忽略
现在解决123问题
[root@localhost ~]# dnf list all|grep syslinux
syslinux.x86_64 6.04-5.el8 base // 下载这个包解决第一个问题
syslinux-extlinux.x86_64 6.04-5.el8 base
syslinux-nonlinux.noarch 6.04-5.el8 base
syslinux-tftpboot.noarch 6.04-5.el8 base
[root@localhost ~]#
[root@localhost ~]# ls /usr/share/syslinux/menu.c32
/usr/share/syslinux/menu.c32 # 复制到/var/lib/cobbler/loaders
[root@localhost ~]# ls /usr/share/syslinux/pxelinux.0
/usr/share/syslinux/pxelinux.0 # 复制到/var/lib/cobbler/loaders
复制这两个文件menu.c32 pxelinux.0 到/var/lib/cobbler/loaders
[root@localhost ~]# cd /usr/share/syslinux/
[root@localhost syslinux]# cp menu.c32 pxelinux.0 /var/lib/cobbler/loaders/
[root@localhost ~]# ls /var/lib/cobbler/loaders
menu.c32 pxelinux.0
执行这个脚本
[root@localhost ~]# /usr/share/cobbler/bin/mkgrub.sh
...省略N
[root@localhost ~]# ls /var/lib/cobbler/loaders
grub ldlinux.c32 menu.c32 pxelinux.0
多出的这两个文件,是开启需要的,没有启动不了
[root@localhost ~]# dnf list all| grep yum-utils
yum-utils.noarch 4.0.21-3.el8 base // 这个包解决2和3的问题
[root@localhost ~]#
[root@localhost ~]# dnf -y install yum-utils syslinux
# 再检查一次
[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, 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.
# 1 的问题包 已经下载了所以可以忽略它
//配置cobbler dhcp
//修改cobbler配置文件,让cobbler控制dhcp
[root@localhost ~]# sed -i 's/^manage_dhcp: false/manage_dhcp: true/' /etc/cobbler/settings.yaml
[root@localhost ~]# sed -n '/manage_dhcp: true/p' /etc/cobbler/settings.yaml
manage_dhcp: true
//配置dhcp
[root@localhost ~]# vim /etc/cobbler/dhcp.template
.... //此处为省略内容
subnet 192.168.229.0 netmask 255.255.255.0 {
option routers 192.168.229.2; // 网关
option domain-name-servers 114.114.114.114; //此处为系统安装好后指定的dns地址
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.229.10 192.168.229.250; // 分配网段
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
.... //此处为省略内容
//重启服务并同步配置,改完dhcp必须要sync同步配置
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync
...省略N
*** TASK COMPLETE *** # 看到这个表示成功
//检查dhcp是否正常
[root@localhost ~]# ss -an|grep 67
udp UNCONN 0 0 0.0.0.0:67 0.0.0.0:*
udp ESTAB 0 0 192.168.229.148%ens160:68 192.168.229.254:67
//导入centos8镜像
[root@localhost ~]# mount /dev/cdrom /mnt/ # 挂载
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 874M 0 874M 0% /dev
tmpfs 893M 0 893M 0% /dev/shm
tmpfs 893M 8.7M 885M 1% /run
tmpfs 893M 0 893M 0% /sys/fs/cgroup
/dev/mapper/cs-root 17G 2.0G 16G 12% /
/dev/sda1 1014M 215M 800M 22% /boot
tmpfs 179M 0 179M 0% /run/user/0
/dev/sr0 11G 11G 0 100% /mnt
[root@localhost ~]# cobbler import --path=/mnt --name=centos8 --arch=x86_64
.....省略N
*** TASK COMPLETE ***
//说明:
--path //镜像路径
--name //为安装源定义一个名字
--arch //指定安装源平台
//安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7-x86_64,如果重复,系统会提示导入失败
//查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
centos8-x86_64
profiles:
centos8-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
# 自动生成安装脚本
[root@localhost ~]# 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.229.148/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.229.148/cobbler/distro_mirror/centos8-x86_64/AppStream
repo --name=source-2 --baseurl=http://192.168.229.148/cobbler/distro_mirror/centos8-x86_64/BaseOS
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted 746gpDrgEIXdIwdIUq3X3V//
# 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.229.148/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.229.148" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.229.148" > /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.229.148/cblr/svc/op/autoinstall/profile/centos8-x86_64" -o /root/cobbler.ks
# End final steps
%end
//把生成的自动安装脚本复制到centos8里
[root@localhost ~]# cd /var/lib/cobbler/templates/
[root@localhost templates]# vim centos8.ks
....省略N
firewall --disabled # 把enabled 修改为disabled
# Run the Setup Agent on first boot
firstboot --disable
...省略N
rootpw --iscrypted 746gpDrgEIXdIwdIUq3X3V//
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Shanghai --isUtc --nontp # 地区改为亚洲上海
# Install OS instead of upgrade
install
# Clear the Master Boot Record
...省略N
%packages
@^minimal-environment # 这个跟系统一样,也就跟anaconda-ks.cfg 这个文件里的@^minimal-environment 一样
%end
...省略N
%end
# 验证自动安装
[root@localhost ~]# cobbler validate-autoinstalls
task started: 2022-08-13_233559_validate_autoinstall_files
task started (id=Automated installation files validation, time=Sat Aug 13 23:35:59 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 ***
//查看当前cobbler有哪些配置文件
[root@localhost ~]# cobbler profile list
centos8-x86_64
//修改profile,将我们新建的ks文件设为默认的autoinstall安装文件
[root@localhost ~]# cobbler profile edit --name centos8-x86_64 --autoinstall=centos8.ks
//配置网卡名称为传统网卡名称eth0
[root@localhost ~]# cobbler profile edit --name centos8-x86_64 --kernel-options='net.ifnames=0 biosdevname=0'
//检查当前系统cobbler配置文件信息
# cobbler distro report --name=fedora17-x86_64 // 如果有多个要带上名字
[root@localhost ~]# cobbler profile report
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
//同步cobbler
[root@localhost ~]# cobbler sync
...省略N
*** TASK COMPLETE ***
//为避免发生未知问题,先把服务端所有服务重启
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart cobblerd.service
[root@localhost ~]# systemctl restart rsyncd
[root@localhost ~]# systemctl restart dhcpd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 5 127.0.0.1:25151 0.0.0.0:*
LISTEN 0 5 0.0.0.0:873 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 *:443 *:*
3. 客户端安装
新建虚拟机
4. 定制安装
定制安装步骤:
- 统计服务器mac地址
- 配置cobbler
- 安装
统计mac地址此处就不赘述了,直接最重要的配置
在 cobbler 的web界面上配置:
同步配置并重启相关服务:
[root@localhost ~]# cobbler sync
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart cobblerd
最后开机自动会安装系统
5.报错信息