Cobbler

Cobbler

Cobbler简介:

  • 快速网络安装linux操作系统的服务,支持众多的Linux发行版: Red Hat、Fedora、 CentOS、 Debian、 Ubuntu和SuSE,也可以支持网络安装windows
  • PXE的二次封装,将多种安装参数封装到一个菜单
  • Python编写
  • 提供了CLI和Web的管理形式

cobbler的工作流程:

  1. client裸机配置了从网络启动后,开机后会广播包请求DHCP服务器( cobbler server)发送其分配好的一个IP
  2. DHCP服务器( cobbler server)收到请求后发送responese,包括其ip地址
  3. client裸机拿到ip后再向cobbler server发送请求OS引导文件的请求
  4. cobbler server告诉裸机OS引导文件的名字和TFTP server的ip和port
  5. client裸机通过上面告知的TFTP server地址通信,下载引导文件
  6. client裸机执行执行该引导文件,确定加载信息,选择要安装的os,期间会再向cobbler server请求kickstart文件和os image
  7. cobbler server发送请求的kickstart和os iamge
  8. client裸机加载kickstart文件
  9. client裸机接收os image,安装该os image

在这里插入图片描述

cobbler命令

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

cobbler部署

//关闭防火墙和selinux
[root@192 ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@192 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
//cobbler服务,selinux必须得是disabled状态,所以要重启
[root@192 ~]# reboot
[root@192 ~]# getenforce
Disabled
//更新yum源,并且安装epel包
[root@192 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0  14940      0 --:--:-- --:--:-- --:--:-- 14940
[root@192 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@192 ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
Repository extras is listed more than once in the configuration
CentOS-8.5.2111 - Base - mirrors.aliyun.com                                         569 kB/s | 4.6 MB     00:08
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                                        72 kB/s |  10 kB     00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                                    376 kB/s | 8.4 MB     00:23
epel-release-latest-8.noarch.rpm                                                     59 kB/s |  24 kB     00:00
Dependencies resolved.
====================================================================================================================
 Package                      Architecture           Version                     Repository                    Size
====================================================================================================================
Installing:
 epel-release                 noarch                 8-17.el8                    @commandline                  24 k

Transaction Summary
====================================================================================================================
Install  1 Package

Total size: 24 k
Installed size: 34 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                            1/1
  Installing       : epel-release-8-17.el8.noarch                                                               1/1
  Running scriptlet: epel-release-8-17.el8.noarch                                                               1/1
Many EPEL packages require the CodeReady Builder (CRB) repository.
It is recommended that you run /usr/bin/crb enable to enable the CRB repository.

  Verifying        : epel-release-8-17.el8.noarch                                                               1/1

Installed:
  epel-release-8-17.el8.noarch

Complete!
[root@192 ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@192 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
//安装cobbler以及相关的软件
[root@192 ~]# dnf -y module enable cobbler:3
[root@192 ~]# dnf -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon syslinux* yum-utils
//启动服务并设置开机自启
[root@192 ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@192 ~]# systemctl enable --now rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
[root@192 ~]# systemctl enable --now tftp.socket
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
[root@192 ~]# systemctl enable --now cobblerd.service
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
[root@192 ~]# ss -antl
State        Recv-Q       Send-Q             Local Address:Port               Peer Address:Port       Process
LISTEN       0            128                      0.0.0.0:22                      0.0.0.0:*
LISTEN       0            5                      127.0.0.1:25151                   0.0.0.0:*
LISTEN       0            5                        0.0.0.0:873                     0.0.0.0:*
LISTEN       0            128                            *:80                            *:*
LISTEN       0            128                         [::]:22                         [::]:*
LISTEN       0            128                            *:443                           *:*
LISTEN       0            5                           [::]:873                        [::]:*
[root@192 ~]#
//生成加密的密码
[root@192 ~]# openssl passwd -1 -salt "$RANDOM" 'centos'
$1$8101$UcmYY8oMEImwxShqacaOT1
//修改cobbler主配置文件
[root@192 ~]# vim /etc/cobbler/settings.yaml
next_server: 192.168.159.129
server: 192.168.159.129
default_password_crypted: "$1$8101$UcmYY8oMEImwxShqacaOT1"
manage_dhcp: true
//通过syslinux*包生成引导文件,我们将引导文件复制到/var/lib/cobbler/loaders/目录下
[root@192 ~]# vim /etc/cobbler/settings.yaml
[root@192 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@192 ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@192 ~]# ls /var/lib/cobbler/loaders/
menu.c32  pxelinux.0
[root@192 ~]#
//重启cobbler
[root@192 ~]# systemctl restart cobblerd.service
[root@192 ~]# ss -anltp |grep 25151
LISTEN 0      5          127.0.0.1:25151      0.0.0.0:*    users:(("cobblerd",pid=13428,fd=6))                      
[root@192 ~]#
//通过cobbler check 核对当前设置是否有问题
[root@192 ~]# 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: debmirror package is not installed, it will be required to manage debian deployments and repositories
3: 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.
[root@192 ~]#
##这里这三个报错没有关系
//配置DHCP模板文件
[root@192 ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.159.0 netmask 255.255.255.0 {                      
     option routers             192.168.159.2;                     #网关
     option domain-name-servers 8.8.8.8;                         #DNS
     option subnet-mask         255.255.255.0;                   #子网掩码
     range dynamic-bootp        192.168.1.100 192.168.1.254;     #地址池
     default-lease-time         21600;
     max-lease-time             43200; 
     next-server                $next_server;
//重启服务,生效配置     
[root@192 ~]# systemctl restart cobblerd.service
//同步cobbler配置
[root@192 ~]# cobbler sync
..........
!!! TASK FAILED !!!
//挂载镜像
[root@192 ~]# mount /dev/sr0 /mnt/
//导入镜像
[root@192 ~]# cobbler import --path=/mnt/ --name=Centos8 arch=x86_64
task started: 2022-09-25_154510_import
task started (id=Media import, time=Sun Sep 25 15:45:10 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/zwl:
creating new distro: zwl-x86_64
trying symlink: /var/www/cobbler/distro_mirror/zwl -> /var/www/cobbler/links/zwl-x86_64
creating new profile: zwl-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/zwl for zwl-x86_64
processing repo at : /var/www/cobbler/distro_mirror/zwl/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/zwl/AppStream
looking for /var/www/cobbler/distro_mirror/zwl/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/zwl/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/zwl/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/zwl/BaseOS
looking for /var/www/cobbler/distro_mirror/zwl/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/zwl/BaseOS/repodata
*** TASK COMPLETE ***
[root@192 ~]#
[root@192 ~]# cobbler list
distros:
   Centos8-x86_64

profiles:
  Centos8-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:
[root@192 ~]#
//查看详细信息  查看指定的--name 接镜像名
[root@192 ~]# cobbler import --path=/mnt/ --name=Centos8 arch=x86_64
task started: 2022-09-25_154943_import
task started (id=Media import, time=Sun Sep 25 15:49:43 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/zwl:
skipping import, as distro name already exists: zwl-x86_64
No distros imported, bailing out
*** TASK COMPLETE ***
[root@192 ~]#
[root@192 ~]# cobbler distro report --name zwl-x86_64
Name                           : zwl-x86_64
Architecture                   : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/Centos8-x86_64'}
TFTP Boot Files                : {}
Boot loader                    : grub
Breed                          : redhat
Comment                        :
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/distro_mirror/zwl/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/distro_mirror/zwl/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                 : {}

[root@192 ~]#
//创建kickstarts自动安装脚本(文件以.ks结尾)
[root@192 ~]# cobbler profile get-autoinstall --name Centos8-x86_64 > /var/lib/cobbler/templates/Centos8.ks	
//对脚本进行修改
[root@192 ~]# vim /var/lib/cobbler/templates/Centos8.ks
firewall --disable      //防火墙关闭
....
%packages
@^minimal-environment    //设置最小化安装
%end
//如果是生产环境,那么部署就已经完成,如果是虚拟机就还需执行以下步骤
[root@192 ~]# cd /usr/share/cobbler/bin/
[root@192 bin]# ls
migrate-data-v2-to-v3.py  migrate-settings.sh  mkgrub.sh  settings-migration-v1-to-v2.sh
[root@192 bin]# bash mkgrub.sh
//执行完上一步,去/var/lib/cobbler/loaders/下查看有没有grub与ldlinux.c32文件
[root@192 bin]# cd /var/lib/cobbler/loaders/
[root@192 loaders]# ll
total 72
drwxr-xr-x 2 root root    79 Sep 25 15:57 grub
lrwxrwxrwx 1 root root    31 Sep 25 15:57 ldlinux.c32 -> /usr/share/syslinux/ldlinux.c32
-rw-r--r-- 1 root root 26272 Sep 25 15:07 menu.c32
-rw-r--r-- 1 root root 42376 Sep 25 15:07 pxelinux.0
[root@192 loaders]#
//同步
[root@192 loaders]# cobbler sync
//重启服务
[root@zwl ~]# systemctl restart httpd cobblerd rsyncd

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值