Cobbler无人值守自动安装多版本系统

Cobbler无人值守自动安装多版本系统

基础环境配置

centos8
修改网卡文件
《Cobbler无人值守自动安装多版本系统》
修改虚拟主机配置
《Cobbler无人值守自动安装多版本系统》

修改主机网卡配置
《Cobbler无人值守自动安装多版本系统》

cobbler必备的软件包

  • cobbler #cobbler程序包
  • cobbler-web #cobbler的web服务包
  • pykickstart #cobbler检查kickstart语法错误
  • httpd #Apache web服务
  • dhcp #dhcp服务
  • tftp-server #tftp服务
  • pykickstart #自动应答
  • rsync-daemon #rsync服务,cobbler同步

cobbler软件安装

# 配置阿里云源的epel源和Base源(需要联网操作执行)
dnf install epel-release

# 安装Cobbler所需的软件
yum -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync-daemon

#查看和启动cobbler模块
dnf module list | grep cobbler
cobbler              3               default [d]                              Versatile Linux deployment server                                        
cobbler              3.3             default                                  Versatile Linux deployment server         

dnf module enable cobbler:3


# 安装图形化界面,方便后续的kickstarts文件的生成(可选择,有桌面可不选)
nohup yum groupinstall -y "Server with GUI" & 

# 启动Cobbler等相关依赖服务
systemctl enable --now cobblerd httpd tftp

#dhcpd 服务可能启动会报错,DHCP会在后面进行配置
# 查看端口
netstat -auntlp | grep 25151
关闭selinux,重启生效
[root@vmware1 yum.repos.d]# getenforce
Enforcing

[root@vmware1 yum.repos.d]# cat /etc/selinux/config 
#SELINUX=enforcing
SELINUX=disabled
永久修改主机名
hostnamectl set-hostname Cobbler

reoot重启主机

cobbler环境配置

检查状态

[root@cobbler ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : 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.
5 : comment out 'dists' on /etc/debmirror.conf for proper debian support
6 : comment out 'arches' on /etc/debmirror.conf for proper debian support
7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one

Restart cobblerd and then run 'cobbler sync' to apply changes.
[root@cobbler ~]# openssl passwd -1 -salt $(openssl rand -hex 4)
Password:此处输入密码123456,该密码用于修改配置
$1$cf763228$od3Yyf5tUhN71/tZiYLGr1

修改settings.yaml文件

vim /etc/cobbler/settings.yaml
注意冒号后的空格
#修改默认密码
default_password_crypted: "$1$cf763228$od3Yyf5tUhN71/tZiYLGr1"

#  tftp服务器的 IP 地址 
next_server: 192.168.126.21
#  cobbler服务器的 IP 地址 
server: 192.168.126.21
# 设置为1,表示通过cobbler生成dhcpd.conf配置文件(可选择)
 manage_dhcp:treu
# 设置为1,防止重复安装系统(可选择)
 pxe_just_once: true 

dhcp配置

vim /etc/cobbler/dhcp.template

subnet 192.168.1.0 netmask 255.255.255.0 { 网段和掩码
     option routers             192.168.1.5;   网关
     option domain-name-servers 192.168.1.1;   DNS地址
     option subnet-mask         255.255.255.0; 子网掩码
     range dynamic-bootp        192.168.1.100 192.168.1.254; Ip范围
     default-lease-time         21600;
     max-lease-time             43200;


修改为

subnet 192.168.126.0 netmask 255.255.255.0 {
     option routers             192.168.168.2;
     option domain-name-servers 8.8.8.8;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.126.60 192.168.126.90;
     default-lease-time         21600;
     max-lease-time             43200;

systemctl restart httpd cobblerd
 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: comment out 'dists' on /etc/debmirror.conf for proper debian support
5: comment out 'arches' on /etc/debmirror.conf for proper debian support

Restart cobblerd and then run 'cobbler sync' to apply changes.
//安装包 解决报错解决报错
dnf -y install yum-utils
dnf -y install syslinux
dnf -y install syslinux-extlinux syslinux-tftpboot
cp /usr/share/syslinux/pxelinux.0 /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
//复制这两个文件到这个目录里面

ls /var/lib/cobbler/loaders/
menu.c32  pxelinux.0
[root@localhost ~]# ./usr/share/cobbler/bin/mkgrub.sh
//执行这个脚本

[root@localhost ~]# ls /var/lib/cobbler/loaders/
grub  ldlinux.c32  menu.c32  pxelinux.0
#用于同步配置到cobbler的数据目录,对于cobbler的任何更改,都应该在更改后执行这条命令用于同步。
#进行自动同步文件 
 cobbler sync
 出现下面表示成功
 *** TASK COMPLETE *** 

《Cobbler无人值守自动安装多版本系统》

文件放入虚拟机的方法

1、安装VMware-tool直接拖进虚拟机
2、开启虚拟机共享文件夹
3、rzsz命令
4、其他网络方法

方法1:
将iso文件放入/mnt/目录下
mkdir /mnt/cdroom8
mount -r /mnt/CentOS-8.1.1911-x86_64-dvd1.iso /mnt/centos8/

方法2:将光驱中的内容进行挂载
1)设置CD/DVD设备状态勾选已连接
2)使用df -h命令查看光盘是否挂载,即是否有/dev/sr*的盘符

[root@localhost ~]# mount /dev/cdrom /mnt
mount: /mnt: 在 /dev/sr0 上找不到媒体.

《Cobbler无人值守自动安装多版本系统》

[root@localhost ~]# mount /dev/cdrom /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# ls /mnt/
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 import --name=CentOS7-X86_64 --arch=X86_64 --path=/mnt
task started: 2024-05-07_203615_import
task started (id=Media import, time=Tue May  7 20:36:15 2024)
cobbler/distro_mirror/CentOS7-X86_64-x86_64/repodata
*** TASK COMPLETE ***
--path表示镜像所挂载的目录
--name表示为安装源定义的名字
--arch(不需要写这个参数)表示指定安装源是32位还是64位,目前支持的选项:x86,x86_64,ia64
 //查看导入结果
[root@localhost ~]# cobbler list
distros:
   CentOS7-X86_64-x86_64

profiles:
   CentOS7-X86_64-x86_64

systems:
repos:
images:
mgmtclasses:
packages:
files:
[root@localhost ~]# cobbler distro report
Name                           : CentOS7-X86_64-x86_64
Architecture                   : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS7-X86_64-x86_64'}
TFTP Boot Files                : {}
Boot loader                    : grub
Breed                          : redhat
Comment                        :
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/distro_mirror/CentOS7-X86_64-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/distro_mirror/CentOS7-X86_64-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Redhat Management Key          :
Remote Boot Initrd             : ~
Remote Boot Kernel             : ~
Template Files                 : {}

镜像存放位置
[root@localhost ~]# ls /var/www/cobbler
《Cobbler无人值守自动安装多版本系统》

默认安装系统

此时默认生成的是最小化安装
若是按步骤做的这里,最小化的安装 root 密码就应该是 123456 可以在 Cobbler 安装出来的系统使用该密码进行登录

创建虚拟机,不指定iso文件,稍后安装的方式即可,启动虚拟机就会有安装界面,注意虚拟机的cpu线程和内存不要给太小,不然安装会出错

《Cobbler无人值守自动安装多版本系统》
《Cobbler无人值守自动安装多版本系统》

《Cobbler无人值守自动安装多版本系统》
《Cobbler无人值守自动安装多版本系统》

《Cobbler无人值守自动安装多版本系统》

《Cobbler无人值守自动安装多版本系统》

cobbler的web管理页面

访问web管理页面,注意只能是https访问,http访问会403
https://192.168.126.51/cobbler_web
用户名密码都是cobbler
《Cobbler无人值守自动安装多版本系统》

《Cobbler无人值守自动安装多版本系统》

下面是定制化加强版(有时间再研究)

  //查看导入的镜像
[root@localhost ~]# cobbler distro list
   CentOS7-X86_64-x86_64

[root@localhost ~]# cobbler profile list
   CentOS7-X86_64-x86_64
#若觉得不能满足生产需要,需要删除默认生成的菜单,然后重新制作kisckstart 文件

配置 kisckstart 无人值守安装脚本(是使用python编写的软件包)
yum -y install system-config-kickstart

#进入图形界面执行
system-config-kickstart
#后续操作就直接跟 kickstart 的向导进行配置

参考

【Linux集群教程】15 集群装机 – Cobbler 简介和搭建 https://blog.csdn.net/weixin_40274679/article/details/127450032
Centos8部署cobbler https://blog.csdn.net/Mingzi540/article/details/126315453

点赞

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注