cobbler服务端部署
1. 配置yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[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]# yum install -y https://mirrors.aliyun.com/epel/epel-releas
[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*
2.安装cobbler以及相关的软件
[root ~]# dnf module enable cobbler:3 -y
[root ~]# yum -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon
3. 启动服务并设置开机自启
systemctl restart httpd;systemctl enable httpd
systemctl restart rsyncd;systemctl enable rsyncd
systemctl restart tftp; systemctl enabled tftp
systemctl restart cobblerd;systemctl enable cobblerd
4.关闭防火墙和selinux
[root ~]# systemctl stop firewalld
[root ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root ~]# setenforce 0
[root ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/sysconfig/selinux
5. 修改server的ip地址为本机ip
[root ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.253.136/' /etc/cobbler/settings.yaml
6.设置tftp的ip地址为本机ip
[root ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.253.136/' /etc/cobbler/settings.yaml
7. 生成加密的密码
[root ~]# openssl passwd -1 -salt "$RANDOM" 'redhat'
$1$28918$/zM23Txv2uWBkkp4MDXst.
8. 将新生成的加密密码加入到配置文件
[root ~]# vim /etc/cobbler/settings.yaml
default_password_crypted: "$1$28918$/zM23Txv2uWBkkp4MDXst."
9. 将cobbler的dhcp功能打开
[root ~]# sed -i "s#manage_dhcp: false#manage_dhcp: true#" /etc/cobbler/settings.yaml
[root ~]# grep 'manage_dhcp:' /etc/cobbler/settings.yaml
manage_dhcp: true
[root ~]# systemctl restart cobblerd
10. 通过cobbler check 核对当前设置是否有问题
[root ~]# 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.
问题1解决办法:
[root ~]# yum -y install syslinux*
[root ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root ~]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0
问题2,3解决办法:
[root ~]# yum -y install yum-utils
问题4,5解可以忽略:
因为是debian系统才需要解决 Debian系统解决办法安装fence-agents
11. 配置DHCP模板文件
[root ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.253.0 netmask 255.255.255.0 {
option routers 192.168.253.254;
option domain-name-servers 8.8.8.8;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.253.130 192.168.253.140;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
12. 同步cobbler配置
[root@192 ~]# systemctl restart httpd cobblerd
[root@192 ~]# cobbler sync
task started: 2022-09-24_222608_sync
task started (id=Sync, time=Sat Sep 24 22:26:08 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 ***
13. 管理distro
// 挂载镜像
[root ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
//导入镜像
[root ~]# cobbler import --path=/mnt/ --name=rww arch=x86_64
//安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-8-x86_64,如果重复,系统会提示导入失败
//查看cobbler镜像列表
[root ~]# cobbler list
[root ~]# cobbler list
distros:
rww-x86_64
profiles:
rww-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
//查看详细信息 查看指定的--name 接镜像名
[root ~]# cobbler distro report --name rww-x86_64
Name : rww-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/rww-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/rww/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/rww/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 : {}
14. 创建kickstarts自动安装脚本
[root ~]# cobbler profile get-autoinstall --name rww-x86_64 > /var/lib/cobbler/templates/rww.ks
[root ~]# cd /var/lib/cobbler/templates/
[root templates]# pwd
/var/lib/cobbler/templates
[root templates]# vim rww.ks
[root templates]# cat rww.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 --disabled //关闭防火墙
# 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.253.136/cblr/links/rww-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.253.136/cobbler/distro_mirror/rww/AppStream
repo --name=source-2 --baseurl=http://192.168.253.136/cobbler/distro_mirror/rww/BaseOS
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$5309$d2q0eTD30QE/tIOrtxObn0
# 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.253.136/cblr/svc/op/yum/profile/rww-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.253.136" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.253.136" > /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.253.136/cblr/svc/op/autoinstall/profile/rww-x86_64" -o /root/cobbler.ks
# End final steps
%end
15. 此时使用虚拟机去安装系统并不会成功 需要做如下操作
[root ~]# cd /usr/share/cobbler/bin/
[root bin]# ls
migrate-data-v2-to-v3.py mkgrub.sh
migrate-settings.sh settings-migration-v1-to-v2.sh
[root bin]# bash mkgrub.sh
[root bin]# cd /var/lib/cobbler/loaders/
[root loaders]# ll
total 72
drwxr-xr-x 2 root root 79 Sep 24 22:44 grub
lrwxrwxrwx 1 root root 31 Sep 24 22:44 ldlinux.c32 -> /usr/share/syslinux/ldlinux.c32
-rw-r--r-- 1 root root 26272 Sep 24 22:19 menu.c32
-rw-r--r-- 1 root root 42376 Sep 24 22:18 pxelinux.0
[root loaders]# cobbler sync
[root loaders]# systemctl restart httpd cobblerd rsyncd dhcpd
16. 手动安装,创建一个虚拟机,然后打开虚拟机
17.自动安装
使用浏览器访问
默认登录的用户名和密码都为cobbler
点击Actions–Sync,右上角有同步日志
同步日志
重新创建一台虚拟机把刚刚生成的MAC地址复制上去
同步日志