cobbler部署

cobbler

一、cobbler简介

Cobbler可以用来快速构建Linux网络安装环境,大大简化Linux网络安装的配置流程。相比PXE的安装方式,cobbler配置简单,并且可以提供多个版本的操作系统以供选择。cobbler采用了基于命令行的方式进行管理,也提供了web管理界面,还提供了API接口,以方便二次开发使用。

二、cobbler对应关系

Cobbler的配置结构基于一组注册的对象。每个对象表示一个与另一个实体相关联的实体。当一个对象指向另一个对象时,它就继承了被指向对象的数据,并可覆盖或者添加更多特定信息。

1、发行版。 发行版表示一个操作系统,承载了内核和initrd的信息(开机自启服务的信息),以及其他内核参数。
2、配置文件。 配置文件包括一个发行版、一个kickstart文件以及可能的存储库,还包括更多特定的内核参数等其他数据。
3、系统。 表示要配给的设备。包括一个配置文件、一个系统镜像、IP和MAC地址,电源管理等其他信息。
4、镜像。 可以替换一个包含不属此类别的文件的发行版对象。
5、存储库。 保存一个YUM或者是rsync存储库镜像信息。

三、cobbler工作原理

cobbler工作原理如下图所示:

cobbler在启动后,需要首先进行自身的检查,检查无误后,就可以统筹开启TFTP、DHCP等的各种服务,等到客户端链接。客户端开机后,需要PXE启动的会使用DHCP协议向cobbler请求IP地址,cobbler在给客户端提供IP地址的同时也会告知客户端其下一跳的IP地址。之后客户端会使用TFTP协议请求加载文件,引导客户端启动并安装系统。同时,为了防止设备被重复安装,cobbler还会记录下该设备的安装信息,当该设备再次接入时,cobbler便不会再对其进行引导。

cobbler部署

#先关闭防火墙和selinux
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# setenforce 0
//cobbler服务,selinux必须得是disabled状态,所以要重启
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
[root@localhost ~]# reboot

#配置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 ~]# 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 enable --now httpd
[root@localhost ~]# systemctl enable --now rsyncd
[root@localhost ~]# systemctl enable --now tftp
[root@localhost ~]# systemctl enable --now cobblerd

#修改server的ip地址为本机ip
[root@localhost ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.111.139/' /etc/cobbler/settings.yaml

#修改tftp的ip地址为本机ip
[root@localhost ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.111.139/' /etc/cobbler/settings.yaml

#生成加密的密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" 'cobbler123'
$1$19347$.N/4En3JI0k2gUp8mvULQ/

#将新生成的加密密码加入到配置文件
[root@localhost ~]# vim /etc/cobbler/settings.yaml
default_password_crypted: "$1$19347$.N/4En3JI0k2gUp8mvULQ/"         //修改为刚生成的加密的密码

#将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

#重启cobbler
[root@localhost ~]# systemctl restart cobblerd

#通过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和问题三的解决办法:
[root@localhost ~]# yum -y install yum-utils

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

#配置DHCP模板文件
[root@localhost ~]# vim /etc/cobbler/dhcp.template
 23 subnet 192.168.111.0 netmask 255.255.255.0 {
 24      option routers             192.168.111.255;
 25      option domain-name-servers 8.8.8.8;
 26      option subnet-mask         255.255.255.0;
 27      range dynamic-bootp        192.168.111.100 192.168.111.110;
 28      default-lease-time         21600;
 29      max-lease-time             43200;
 30      next-server                $next_server;

#同步cobbler配置
[root@localhost ~]# systemctl restart httpd cobblerd
[root@localhost ~]# cobbler sync
task started: 2022-09-24_163754_sync
task started (id=Sync, time=Sat Sep 24 16:37:54 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@localhost ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.

#导入镜像
[root@localhost ~]# cobbler import --path=/mnt/ --name=zxr arch=x86_64
task started: 2022-09-24_164154_import
task started (id=Media import, time=Sat Sep 24 16:41:54 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/zxr:
creating new distro: zxr-x86_64
trying symlink: /var/www/cobbler/distro_mirror/zxr -> /var/www/cobbler/links/zxr-x86_64
creating new profile: zxr-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/zxr for zxr-x86_64
processing repo at : /var/www/cobbler/distro_mirror/zxr/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/zxr/AppStream
looking for /var/www/cobbler/distro_mirror/zxr/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/zxr/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/zxr/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/zxr/BaseOS
looking for /var/www/cobbler/distro_mirror/zxr/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/zxr/BaseOS/repodata
*** TASK COMPLETE ***

#查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
   zxr-x86_64

profiles:
   zxr-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

#查看详细信息
[root@localhost ~]# cobbler distro report --name zxr-x86_64
Name                           : zxr-x86_64
Architecture                   : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/zxr-x86_64'}
TFTP Boot Files                : {}
Boot loader                    : grub
Breed                          : redhat
Comment                        :
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/distro_mirror/zxr/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/distro_mirror/zxr/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自动安装脚本(文件以.ks结尾,勿tab)
[root@localhost ~]# cobbler profile get-autoinstall --name zxr-x86_64 > /var/lib/cobbler/templates/zxr.ks
#对脚本进行修改
[root@localhost ~]# vim /var/lib/cobbler/templates/zxr.ks
..........................

firewall --disable              //关闭防火墙
.........................

%packages
@^minimal-environment           //设置为最小化

#查看一下
[root@localhost ~]# cat /var/lib/cobbler/templates/zxr.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 --disable
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.111.139/cblr/links/zxr-x86_64
If any cobbler repo definitions were referenced in the kickstart profile, include them here.

repo --name=source-1 --baseurl=http://192.168.111.139/cobbler/distro_mirror/zxr/AppStream
repo --name=source-2 --baseurl=http://192.168.111.139/cobbler/distro_mirror/zxr/BaseOS

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

Reboot after installation
reboot

#Root password
rootpw --iscrypted $1$19347$.N/4En3JI0k2gUp8mvULQ/
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

%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.111.139/cblr/svc/op/yum/profile/zxr-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.111.139" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.111.139" > /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.111.139/cblr/svc/op/autoinstall/profile/zxr-x86_64" -o /root/cobbler.ks
End final steps
%end

#如果是真实环境,那么部署就已经完成,如果是虚拟机就还需执行以下步骤
[root@localhost ~]# cd /usr/share/cobbler/bin/
[root@localhost bin]# ls
migrate-data-v2-to-v3.py  migrate-settings.sh  mkgrub.sh  settings-migration-v1-to-v2.sh
[root@localhost bin]# bash mkgrub.sh
[root@localhost bin]# cd /var/lib/cobbler/loaders/
[root@localhost loaders]# ll
total 72
drwxr-xr-x. 2 root root    79 Sep 24 16:57 grub
lrwxrwxrwx. 1 root root    31 Sep 24 16:57 ldlinux.c32 -> /usr/share/syslinux/ldlinux.c32
-rw-r--r--. 1 root root 26272 Sep 24 16:31 menu.c32
-rw-r--r--. 1 root root 42376 Sep 24 16:31 pxelinux.0

#进行同步
[root@localhost loaders]# cobbler sync

#重启服务
[root@localhost loaders]# systemctl restart httpd cobblerd rsyncd dhcpd

进行测试

安装一个空壳centos8的虚拟机,不需要给镜像
进来后就发现可以自动获取ip选择我们刚才上传的镜像

cobbler部署
正在安装包
cobbler部署
安装完成,登录查看ip
cobbler部署

web界面自动安装

cobbler部署
cobbler部署
cobbler部署
cobbler部署
cobbler部署
cobbler部署
cobbler部署
cobbler部署

Original: https://www.cnblogs.com/Their-own/p/16726055.html
Author: 事愿人为
Title: cobbler部署

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/611264/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • DevOps

    Docker: ## 安装Docker yum remove docker docker-client docker-client-latest docker-common doc…

    数据库 2023年6月9日
    064
  • 2022-8-20 数据库连接池

    1. 概念:其实就是一个容器(集合),存放数据库连接的容器。 当系统初&#x59CB…

    数据库 2023年6月14日
    0101
  • Linux–>进程管理

    基本介绍 在Linux中, 每个执行程序都称为一个进程。每一个进程都会分配一个ID号(pid,进程号) 每个进程都可能以俩种方式存在的。分别是 前台与 后台,所谓前台进程就是用户目…

    数据库 2023年6月14日
    094
  • 工厂模式

    工厂模式是java中最常用的设计模式之一,这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式。在工厂模式中,我们在创建对象时不会对客户端暴露创建逻辑,并且是通过使用一…

    数据库 2023年6月11日
    082
  • leetcode 437. Path Sum III 路径总和 III(中等)

    一、题目大意 给定一个二叉树的根节点 root ,和一个整数 targetSum ,求该二叉树里节点值之和等于 targetSum 的 路径 的数目。 路径 不需要从根节点开始,也…

    数据库 2023年6月16日
    086
  • 渗透攻防Web篇-深入浅出SQL注入

    1 背景 京东SRC(Security Response Center)收录大量外部白帽子提交的sql注入漏洞,漏洞发生的原因多为sql语句拼接和Mybatis使用不当导致。 2 …

    数据库 2023年5月24日
    092
  • 单点登录(SSO)

    1 基础知识 单点登录机制(SSO)允许用户登录应用程序一次,并访问所有相关的系统,而不需要单独登录它们。 由于 SSO,用户只需登录一次即可使用服务,并自动登录到所有相关应用程序…

    数据库 2023年6月14日
    0147
  • 分享一例同一系统里不同服务之间通信的设计方案

    优付系统结构如下。一个数据库之上,有商户接口(RestAPI)、运营后台(OMS)、商户门户这3个独立SSM应用,三者有各自不同的功能处理逻辑。 现在呢,要做一个补偿工具。当付款单…

    数据库 2023年6月9日
    0124
  • Linux 下安装 redis

    2、使用命令下载: 3、将文件拷贝到安装目录 /usr/local 目录下 4、进入 /usr/local 目录下,解压安装包 5、进入解压后的目录 6、编译,将 redis 安装…

    数据库 2023年6月14日
    082
  • FastDFS安装和简介详细总结

    1、fastDFS简介 1 FastDFS是用c语言编写的一款开源的分布式文件系统。 2 FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用…

    数据库 2023年6月14日
    0105
  • 2022-8-11 网络编程(网络通信)

    网络协议 通过计算机网络可以使多台计算机实现连接,位于同一个网络中的计算机在进行连接和通信时需要遵守一定的规则,这就好比在道路中行驶的汽车一定要遵守交通规则一样。在计算机网络中,这…

    数据库 2023年6月14日
    095
  • .NetCore2.0引用DLL报System.InvalidOperationException: Can not find compilation library location for package ‘XXX’

    .NET CORE 2.0 MVC项目引用类库出现:System.InvalidOperationException: Can not find compilation libra…

    数据库 2023年6月14日
    094
  • MySQL并行复制(MTS)原理(完整版)

    MySQL 5.6并行复制架构 MySQL 5.7并行复制原理 Master 组提交(group commit) 支持并行复制的GTID slave LOGICAL_CLOCK(由…

    数据库 2023年5月24日
    094
  • 大连交通大学课程共享

    如本页面访问适配不佳,阅读体验不好可访问公众号页面(适配更好)。公众号页面:https://mp.weixin.qq.com/s/5g2-Izrygm6WhKiT3z1yow 设立…

    数据库 2023年6月11日
    074
  • gorm 版本对比

    两个版本 github.com/jinzhu/gorm v1.9.16 gorm.io/gorm v1.21.3 Open // jinzhu func Open(dialect …

    数据库 2023年6月9日
    0107
  • 模板语法之标签

    语法 {% 开始标签 %} …. {% 结束…

    数据库 2023年6月14日
    0120
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球