Cobbler简介和安装

1. cobbler简介

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

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

Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。

Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。

Cobbler官网

http://cobbler.github.io/

cobbler集成的服务

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

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

配置文件作用
/etc/cobbler/settingscobbler 主配置文件
/etc/cobbler/iso/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模块的配置文件

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

cobbler日志文件

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

cobbler命令详解

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

2.部署Cobbler

配置防火墙、selinux、yum源

[root@JLin ~]# systemctl disable --now firewalld
[root@JLin ~]# setenforce 0
setenforce: SELinux is disabled
[root@JLin ~]# rm -rf  /etc/yum.repos.d/*
[root@JLin ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0  26126      0 --:--:-- --:--:-- --:--:-- 26281
[root@JLin ~]#sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo
[root@JLin ~]# yum -y install epel-release

下载工具包

[root@JLin ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart fence-agents debmirror yum-utils syslinux

配置服务

[root@JLin ~]# systemctl start httpd
[root@JLin ~]# systemctl start cobblerd
[root@JLin ~]# systemctl enable httpd
[root@JLin ~]# systemctl enable cobblerd

修改server得ip地址为本机ip地址、修改tftp得ip地址为本机ip地址、开启tftp

[root@JLin ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.23.161/' /etc/cobbler/settings
[root@JLin ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.23.161/' /etc/cobbler/settings
[root@JLin ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp

启动rsync并设置开机自启

[root@JLin ~]# systemctl start rsyncd
[root@JLin ~]# systemctl enable rsyncd

生成加密密码

[root@JLin ~]# openssl passwd -1 -salt "$RANDOM" 'jlin'
$1$16808$FXwhu3WR8uewzCA9zJAqs0
[root@JLin ~]# vim /etc/cobbler/settings
# cobbler has various sample kickstart templates stored
# in /var/lib/cobbler/kickstarts/.  This controls
# what install (root) password is set up for those
# systems that reference this variable.  The factory
# default is "cobbler" and cobbler check will warn if
# this is not changed.
# The simplest way to change the password is to run 
# openssl passwd -1
# and put the output between the "" below.
default_password_crypted: "$1$16808$FXwhu3WR8uewzCA9zJAqs0"
[root@JLin ~]# systemctl restart cobblerd

解决报错(cobbler check)

[root@JLin ~]# cd /var/www/cobbler/ks_mirror
[root@JLin ks_mirror]# 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, you may run 'cobbler get-loaders' to download them, or, 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. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
2 : comment out 'arches' on /etc/debmirror.conf for proper debian support

Restart cobblerd and then run 'cobbler sync' to apply changes.
[root@JLin ~]# vim /etc/debmirror.conf
# @arches="i386";

[root@JLin ~]# 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, you may run 'cobbler get-loaders' to download them, or, 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. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.

Restart cobblerd and then run 'cobbler sync' to apply changes.

配置dchp

[root@JLin ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@JLin ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings 
manage_dhcp: 1
[root@JLin ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.23.0 netmask 255.255.255.0 {
     option routers             192.168.23.161;
     option domain-name-servers 192.168.23.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.23.200 192.168.23.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
// 删除virbr0
[root@JLin network-scripts]# yum -y install fence-agents-virsh.x86_64
[root@JLin network-scripts]# virsh net-destroy default
网络 default 被删除

[root@JLin network-scripts]# virsh net-undefine default
网络 default 已经被取消定义

[root@localhost network-scripts]# systemctl restart libvirtd

[root@JLin ~]# systemctl restart cobblerd
[root@JLin ~]# cobbler sync
task started: 2021-10-13_142419_sync
task started (id=Sync, time=Wed Oct 13 14:24:19 2021)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
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: 
dhcpd -t failed
Exception occured: <class 'cobbler.cexceptions.CX'>
Exception value: 'cobbler trigger failed: cobbler.modules.sync_post_restart_services'
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 181, in runner
    return self.remote.api.sync(self.options.get("verbose",False),logger=self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 763, in sync
    return sync.run()
   File "/usr/lib/python2.7/site-packages/cobbler/action_sync.py", line 144, in run
    utils.run_triggers(self.api, None, "/var/lib/cobbler/triggers/sync/post/*", logger=self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/utils.py", line 928, in run_triggers
    raise CX("cobbler trigger failed: %s" % m.__name__)

!!! TASK FAILED !!!

配置镜像

[root@JLin ~]# mount /dev/sr0  /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@JLin ~]# cobbler import --path=/mnt --name=centos-7 --arch=x86_64
task started: 2021-10-13_143020_import
task started (id=Media import, time=Wed Oct 13 14:30:20 2021)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/centos-7-x86_64:
creating new distro: centos-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos-7-x86_64 -> /var/www/cobbler/links/centos-7-x86_64
creating new profile: centos-7-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/ks_mirror/centos-7-x86_64 for centos-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos-7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos-7-x86_64
looking for /var/www/cobbler/ks_mirror/centos-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos-7-x86_64/repodata
*** TASK COMPLETE ***

查看镜像列表

[root@JLin ~]# cobbler list
distros:
   centos-7-x86_64

profiles:
   centos-7-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

查看脚本

[root@JLin ~]# cat /var/lib/cobbler/kickstarts/centos-7-x86_64.ks
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url  --url=http://192.168.233.161/cobbler/ks_mirror/centos-7-x86_64
$yum_repo_stanza
reboot

rootpw --iscrypted $6$wMDoAuNSqWzjdRxJ$jad9v1zHPEvPiBY5P4ZqCfsVyog2CyqPO7Vqqm4F4T.S.l4FBeh2ujMzfwMHQ19a9I7C3f4dkQkikC1yTQkoW 
selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr

%packages
@^minimal
@core
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

检查语法是否正确

[root@JLin ~]# cobbler validateks
task started: 2021-10-13_143841_validateks
task started (id=Kickstart Validation, time=Wed Oct 13 14:38:41 2021)
----------------------------
osversion: rhel7
checking url: http://192.168.23.161/cblr/svc/op/ks/profile/centos-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.23.161/cblr/svc/op/ks/profile/centos-7-x86_64"
received on stdout: 
received on stderr: 
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***

修改profile

// 将我们新建的ks文件设为默认的kickstarts安装文件
[root@JLin ~]# cobbler profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.ks

// 配置网卡名称为传统网卡名称eth0
[root@JLin ~]# cobbler profile edit --name centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

检查cobbler配置信息

[root@JLin ~]# cobbler profile report
Name                           : centos-7-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : centos-7-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {'biosdevname': '0', 'net.ifnames': '0'}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/centos-7-x86_64.ks
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

同步cobbler

[root@JLin ~]# cobbler sync
task started: 2021-10-13_144115_sync
task started (id=Sync, time=Wed Oct 13 14:41:15 2021)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos-7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
copying distros to tftpboot
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos-7-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos-7-x86_64/initrd.img
Writing template files for centos-7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos-7-x86_64
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: 
dhcpd -t failed
Exception occured: <class 'cobbler.cexceptions.CX'>
Exception value: 'cobbler trigger failed: cobbler.modules.sync_post_restart_services'
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 181, in runner
    return self.remote.api.sync(self.options.get("verbose",False),logger=self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 763, in sync
    return sync.run()
   File "/usr/lib/python2.7/site-packages/cobbler/action_sync.py", line 144, in run
    utils.run_triggers(self.api, None, "/var/lib/cobbler/triggers/sync/post/*", logger=self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/utils.py", line 928, in run_triggers
    raise CX("cobbler trigger failed: %s" % m.__name__)

!!! TASK FAILED !!!

重启服务

[root@JLin ~]# systemctl restart xinetd
[root@JLin ~]# systemctl restart cobblerd
[root@JLin ~]# systemctl restart httpd
[root@JLin ~]# ss -antl
State      Recv-Q Send-Q Local Address:Port                Peer Address:Port              
LISTEN     0      5          127.0.0.1:25151                          *:*                  
LISTEN     0      5                  *:873                            *:*                  
LISTEN     0      128                *:111                            *:*                  
LISTEN     0      5      192.168.122.1:53                             *:*                  
LISTEN     0      128                *:22                             *:*                  
LISTEN     0      128        127.0.0.1:631                            *:*                  
LISTEN     0      100        127.0.0.1:25                             *:*                  
LISTEN     0      5                 :::873                           :::*                  
LISTEN     0      128               :::111                           :::*                  
LISTEN     0      128               :::80                            :::*                  
LISTEN     0      128               :::22                            :::*                  
LISTEN     0      128              ::1:631                           :::*                  
LISTEN     0      100              ::1:25                            :::*                  
LISTEN     0      128               :::443                           :::*

VMware Workstation添加一台新的虚拟机,不选择镜像直接开机,引导进入PXE界面cobbler安装

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汉只只

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值