zl程序教程

您现在的位置是:首页 >  系统

当前栏目

docker cobbler批量部署Linux/windows系统(二)——筑梦之路

2023-09-14 09:09:36 时间

上篇:https://blog.csdn.net/qq_34777982/article/details/116782745

前面使用docker部署好了cobbler服务端,本篇将接着上篇来实现批量部署安装centos/ubuntu系统。

这里补充下cobbler支持的操作系统说明:

1.cobbler由redhat公司开发,容器基础镜像使用centos兼容性更好;

2.检查cobbler支持的版本:

cobbler signature report --name=ubuntu
cobbler signature report --name=debian
cobbler signature report --name=centos
cobbler signature report --name=windows

没有列出的表示不支持,不建议使用cobbler批量部署。

3.Windows系统的自动安装需要配合相关的Autounattend.xml自动应答文件进行。

参考文章:https://www.cnblogs.com/pluse/p/8316914.html

https://blog.csdn.net/wfs1994/article/details/81041772

centos 7为例:

上传镜像iso文件到服务器/opt/iso/
mkdir -p /opt/iso
mount -t iso9660 -o loop,ro  CentOS-7-x64-Minimal-1708.iso /mnt/centos7/

cobbler 导入:

cobbler import --path=/mnt/centos7/ --arch=x86_64 --name=centos7

导入镜像的同时,cobbler会自动生成该镜像的 profile 和 distro,可以通过 list 和 report 命令来查看细节,如下:
cobbler list
cobbler report

默认使用的应答文件/var/lib/cobbler/kickstarts/sample_end.ks

自定义ks应答文件:
#centos7.ks
auth  --useshadow  --enablemd5
bootloader --location=mbr
clearpart --all --initlabel
graphical
firewall --enabled
firstboot --disable
keyboard us
lang zh_CN
url --url=$tree
$yum_repo_stanza
$SNIPPET('network_config')
reboot
 
#Root password
rootpw --iscrypted $default_password_crypted
selinux --disabled
skipx
timezone  Asia/Shanghai
install
zerombr
autopart
 
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
$SNIPPET('pre_anamon')
%end
 
%packages
$SNIPPET('func_install_if_enabled')
%end
 
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
 
%post
$SNIPPET('log_ks_post')
$yum_config_stanza
$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')
$SNIPPET('post_anamon')
$SNIPPET('kickstart_done')
%end

此处是一个简单的示例,具体语法参考:https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/installation_guide/sect-kickstart-syntax
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/installation_guide/sect-kickstart-syntax#sect-kickstart-commands
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/installation_guide/s1-kickstart2-options
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/

ubuntu 16.04 为例:
上传ubuntu 16.04 server镜像到/opt/iso
mount -t iso9660 -o loop,ro ubuntu-16.04.3-server-x64.iso /mnt/ubuntu16

cobbler 导入:
cobbler import --name=ubuntu16 --path=/mnt/ubuntu16/ --breed=ubuntu

#注意区别不同操作系统导入的命令

检查:
cobbler list
cobbler report

默认使用的自动应答文件/var/lib/cobbler/kickstarts/sample.seed

自定义ks:
#ubuntu16.ks
d-i debian-installer/locale string zh_CN

d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/toggle select No toggling
d-i keyboard-configuration/layoutcode string us
d-i keyboard-configuration/variantcode string

d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string $myhostname


d-i time/zone string Asia/Shanghai
d-i clock-setup/cst boolean true
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server  string ntp.ubuntu.com

d-i mirror/country string manual
d-i mirror/http/hostname string $http_server
d-i mirror/http/directory string $install_source_directory
d-i mirror/http/proxy string

d-i live-installer/net-image string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs

d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-partitioning/confirm_write_new_label boolean true

d-i partman-auto/choose_recipe select atomic


d-i passwd/root-login boolean true
d-i passwd/root-password-crypted password $default_password_crypted

d-i passwd/make-user boolean false

$SNIPPET('preseed_apt_repo_config')

tasksel tasksel/first multiselect standard

d-i pkgsel/include string ntp ssh wget

d-i grub-installer/grub2_instead_of_grub_legacy boolean true
d-i grub-installer/bootdev string default

d-i debian-installer/add-kernel-opts string $kernel_options_post

d-i finish-install/reboot_in_progress note


d-i preseed/early_command string wget -O- \
   http://$http_server/cblr/svc/op/script/$what/$name/?script=preseed_early_default | \
   /bin/sh -s


d-i preseed/late_command string wget -O- \
   http://$http_server/cblr/svc/op/script/$what/$name/?script=preseed_late_default | \
   chroot /target /bin/sh -s

根据实际情况修改。
官方示例:https://www.debian.org/releases/buster/example-preseed.txt

################################################################
ubuntu是基于debian的,因此这里批量部署debian系统也类似!!!!!!