cobbler自动化安装部署

一、cobbler简介

Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。

Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。

Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
类似于一个教室里面部署多台操作系统时,因手动部署非常繁琐而且还要保持镜像一致性。
使用cobbur可以一键生成镜像,利用镜像从而配置多台操作系统

cobbler官网:https://cobbler.github.io/

1、cobbler集成的服务:

  • PXE服务支持
  • DHCP服务管理
  • DNS服务管理(可选bind,dnsmasq)
  • 电源管理
  • YUM仓库管理
  • TFTP(PXE启动时需要)
  • Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

2、cobbler配置文件详解:
cobbler配置文件目录在/etc/cobbler

配置文件作用
/etc/cobbler/settings.ymlcobbler 主配置文件
/etc/cobbler/iso/
/etc/cobbler/pxepxe模板配置文件
/etc/cobbler/power电源配置文件
/etc/cobbler/user.confweb服务授权配置文件
/etc/cobbler/users.digestweb访问的用户名密码配置文件
/etc/cobbler/dhcp.templatedhcp服务器的的配置模板
/etc/cobbler/dnsmasq.templatedns服务器的配置模板
/etc/cobbler/tftpd.templatetftp服务的配置模板
/etc/cobbler/modules.conf模块的配置文件

3、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仓库存储目录

4、cobbler日志文件:

日志文件路径说明
/var/log/cobbler/installing客户端安装日志
/var/log/cobbler/cobbler.log cobbler日志

5、cobbler命令详解:

cobbler check核对当前设置是否有问题
cobbler list核对当前设置是否有问题
cobbler report列出元素的详细信息
cobbler sync同步配置到数据目录,更改配置最好都要执行下
cobbler reposync同步yum仓库
cobbler distro查看导入的发行版系统信息
cobbler system查看添加的系统信息
cobbler profile查看配置信息

二、cobbur配置

安装cobbler以及相关的软件

[root@localhost ~]# yum module list | grep cobbler
cobbler              3               default [d]                              Versatile Linux deployment server                                                                                                                                                                                                
cobbler              3.3             default [d]                              Versatile Linux deployment server

下载模块工具
[root@localhost ~]# yum -y module enable cobbler:3



下载制作镜像所需的工具
[root@localhost ~]# yum -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon


启动服务
[root@localhost ~]# systemctl restart httpd;systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl restart rsyncd.;systemctl enable rsyncd
Failed to restart rsyncd..service: Unit rsyncd..service not found.
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
[root@localhost ~]# systemctl restart tftp;systemctl enable tftp.socket 
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
[root@localhost ~]# systemctl restart cobblerd.service;systemctl enable cobblerd.service 
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service

关闭防火墙
[root@localhost ~]# systemctl stop firewalld 
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config 
[root@localhost ~]# setenforce 0
[root@localhost ~]# reboot 

设置tftp的ip地址为本机ip

[root@localhost ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.47.137/' /etc/cobbler/settings.yaml
[root@localhost ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.47.137/'  /etc/cobbler/settings.yaml

生成加密的密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" 'redhat'
$1$26868$Ilhvmd6hHsvDcMs2dz9dS.

将新生成的加密密码加入到配置文件
[root@localhost ~]# vim /etc/cobbler/settings.yaml 
default_password_crypted: "$1$26868$Ilhvmd6hHsvDcMs2dz9dS."

将cobbler的dhcp功能打开
[root@localhost ~]# sed -i "s#manage_dhcp: false#manage_dhcp: true#" /etc/cobbler/settings.yaml
[root@localhost ~]# grep 'manage_dhcp:' /etc/cobbler/settings.yaml
manage_dhcp: true
[root@localhost ~]# systemctl restart cobblerd.service 

通过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.


问题1解决办法:
先下载服务,然后将其文件复制一份
[root@localhost ~]# yum -y install syslinux*
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@localhost ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@localhost ~]# ls /var/lib/cobbler/loaders/
menu.c32  pxelinux.0

问题2和问题3解决办法,安装软件包即可
[root@localhost ~]# yum -y install yum-utils

问题4和问题5可以忽略,
因为是debian系统才需要解决,显示使用的是centos8
Debian系统解决办法安装fence-agents

配置DHCP模板文件

[root@localhost ~]# vim /etc/cobbler/dhcp.template 
subnet 192.168.47.0 netmask 255.255.255.0 {
     option routers             192.168.47.2;       //网关
     option domain-name-servers 8.8.8.8;     //DNS
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.47.137 192.168.47.200;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";

同步任务

[root@localhost ~]# systemctl restart httpd cobblerd.service 
[root@localhost ~]# cobbler sync
task started: 2022-09-23_163804_sync
task started (id=Sync, time=Fri Sep 23 16:38:04 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 ***

管理distro
//挂载镜像,导入发行版本的信息

[root@rhel8 ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.


1、导入镜像时报错

[root@Cobbler ~]# cobbler import --path=/mnt/ubuntu16.04/ --name=ubuntu16.04 --arch=x86_64

task started: 2019-02-23_234323_import

task started (id=Media import, time=Sat Feb 23 23:43:23 2019)

Exception occured: <class 'cobbler.cexceptions.CX'>

Exception value: 'Command failed'

Exception Info:

  File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 82, in run

    rc = self._run(self)

  File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 227, in runner

    self.logger

  File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 876, in import_tree

    utils.run_this(rsync_cmd, (spacer, mirror_url, path), self.logger)

  File "/usr/lib/python2.7/site-packages/cobbler/utils.py", line 899, in run_this

    die(logger,"Command failed")

  File "/usr/lib/python2.7/site-packages/cobbler/utils.py", line 114, in die

    raise CX(msg)

!!! TASK FAILED !!!

**如导入镜像时遇到!!! TASK FAILED !!! 错误**

一、则可能是yum仓库配置的阿里云epel源有问题,建议快照恢复在次拉取阿里云仓库,重新配置

二、在启动服务时候保证服务正在运行




//导入镜像
[root@my ~]# cobbler import --path=/mnt/ --name=liutianyang-8 arch=x86_64
task started: 2022-09-24_125830_import
task started (id=Media import, time=Sat Sep 24 12:58:30 2022)
running python triggers from /var/lib/cobbler/triggers/task/import/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/import/pre/*
shell triggers finished successfully
Found a candidate signature: breed=redhat, version=rhel8
Found a matching signature: breed=redhat, version=rhel8
Adding distros from path /var/www/cobbler/distro_mirror/liutianyang-8:
creating new distro: liutianyang-8-x86_64
trying symlink: /var/www/cobbler/distro_mirror/liutianyang-8 -> /var/www/cobbler/links/liutianyang-8-x86_64
creating new profile: liutianyang-8-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/distro_mirror/liutianyang-8 for liutianyang-8-x86_64
processing repo at : /var/www/cobbler/distro_mirror/liutianyang-8/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/liutianyang-8/AppStream
looking for /var/www/cobbler/distro_mirror/liutianyang-8/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/liutianyang-8/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/liutianyang-8/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/liutianyang-8/BaseOS
looking for /var/www/cobbler/distro_mirror/liutianyang-8/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/liutianyang-8/BaseOS/repodata
*** TASK COMPLETE ***

安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-8-x86_64,如果重
复,系统会提示导入失败

查看cobbler镜像列表

[root@my ~]# cobbler list
distros:
   liutianyang-8-x86_64

profiles:
   liutianyang-8-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

//查看详细信息 查看指定的--name 接镜像名
[root@my ~]# cobbler distro report --name liutianyang-8-x86_64
Name                           : liutianyang-8-x86_64
Architecture                   : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/liutianyang-8-x86_64'}
TFTP Boot Files                : {}
Boot loader                    : grub
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/distro_mirror/liutianyang-8/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/distro_mirror/liutianyang-8/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                 : {}

创建kickstarts自动安装脚本

[root@my ~]#  cobbler profile get-autoinstall --name liutianyang-8-x86_64 > /var/lib/cobbler/templates/liutianyang.ks


[root@my templates]# cat liutianyang.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.47.136/cblr/links/liutianyang-8-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.47.136/cobbler/distro_mirror/liutianyang-8/AppStream
repo --name=source-2 --baseurl=http://192.168.47.136/cobbler/distro_mirror/liutianyang-8/BaseOS

# Network information
network --bootproto=dhcp --device=eth0 --onboot=on  

# Reboot after installation
reboot

#Root password
rootpw --iscrypted $1$24638$qrt8ZOTdvZBgot2emu5Q8.
# 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.47.136/cblr/svc/op/yum/profile/liutianyang-8-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.47.136" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.47.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.47.136/cblr/svc/op/autoinstall/profile/liutianyang-8-x86_64" -o /root/cobbler.ks
# End final steps
%end

此时使用虚拟机去安装系统并不会成功 需要做如下操作

[root@my templates]# cd /usr/share/cobbler/bin/
[root@my bin]# ls
migrate-data-v2-to-v3.py  mkgrub.sh
migrate-settings.sh       settings-migration-v1-to-v2.sh
[root@my bin]# bash mkgrub.sh 
[root@my bin]# cd /var/lib/cobbler/loaders/
[root@my loaders]# ll
total 72
drwxr-xr-x 2 root root    79 Sep 24 13:22 grub
lrwxrwxrwx 1 root root    31 Sep 24 13:22 ldlinux.c32 -> /usr/share/syslinux/ldlinux.c32
-rw-r--r-- 1 root root 26272 Sep 24 12:54 menu.c32
-rw-r--r-- 1 root root 42376 Sep 24 12:54 pxelinux.0
[root@my loaders]# cobbler sync
[root@my loaders]# systemctl restart httpd cobblerd rsyncd dhcpd

手动安装

//创建一个虚拟机,然后打开虚拟机
点击回车即可
新建虚拟机
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

自动安装

在这里插入图片描述

定义主机名
在这里插入图片描述

在这里插入图片描述

粘贴
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

同步成功
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于Cobbler的无人值守安装部署,可以按照以下步骤进行操作: 1. 首先,确保你的系统满足Cobbler安装要求,包括适当的硬件配置和操作系统版本。 2. 安装Cobbler软件包。你可以通过包管理器(如yum或apt)来安装Cobbler。 3. 配置Cobbler。编辑Cobbler的配置文件(通常是/etc/cobbler/settings)来设置网络参数、存储路径、DHCP设置等。 4. 导入操作系统镜像。使用cobbler import命令将操作系统镜像导入Cobbler。你需要提供操作系统的ISO文件或网络安装源。 5. 定义系统配置文件。使用cobbler system命令创建系统配置文件,包括主机名、IP地址、MAC地址等信息。 6. 定义配置文件模板。根据你的需求,可以使用cobbler profile命令创建配置文件模板,并将其关联到系统配置文件上。 7. 配置DHCP服务。Cobbler可以自动配置DHCP服务器,以便客户端能够通过网络安装操作系统。 8. 启动Cobbler服务。使用systemctl或service命令启动Cobbler服务,并确保它在系统启动时自动启动。 9. 进行无人值守安装。现在,你可以使用cobbler system命令进行无人值守安装了。根据定义的系统配置文件,Cobbler将自动进行操作系统的安装。 请注意,以上只是一个概述,具体的步骤和命令可能会因为你的系统环境和需求而有所不同。建议你参考Cobbler的官方文档或相关资源,以获取详细的操作指南。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值