cobbler
cobbler简介
Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
cobbler集成的服务:
PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时需要)
Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
cobbler配置文件详解
cobbler配置文件目录在/etc/cobbler
配置文件 | 作用 |
---|---|
/etc/cobbler/settings | cobbler 主配置文件 |
/etc/cobbler/iso/ | iso模板配置文件 |
/etc/cobbler/pxe | pxe模板配置文件 |
/etc/cobbler/power | 电源配置文件 |
/etc/cobbler/user.conf | web服务授权配置文件 |
/etc/cobbler/users.digest | web访问的用户名密码配置文件 |
/etc/cobbler/dhcp.template | dhcp服务器的的配置模板 |
/etc/cobbler/dnsmasq.template | dns服务器的配置模板 |
/etc/cobbler/tftpd.template | tftp服务的配置模板 |
/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.log | cobbler日志 |
cobbler的作用
服务器上架后,可以手动选择需要安装的系统(如:Centos7 或 Centos 8)
服务器上架后,能够根据需求,安装配置操作系统(如:修改IP地址、主机名、选择安装包)
系统安装后,可以自定义的执行脚本,完成系统基础软件初始化(如:Zabbix安装配置、SaltStack安装配置)
可以当内部YUM源,并在系统安装时进行初始化
可以重装系统
Cobbler支持API,可以无缝融合到自建运维平台中
Cobbler支持网卡的路由配置、DNS配置、bonding
cobbler命令
cobbler check //核对当前设置是否有问题
cobbler list //列出所有的cobbler元素
cobbler report //列出元素的详细信息
cobbler sync //同步配置到数据目录,更改配置最好都要执行下
cobbler reposync //同步yum仓库
cobbler distro //查看导入的发行版系统信息
cobbler system //查看添加的系统信息
cobbler profile //查看配置信息
cobbler服务端部署
配置源
[root@cl ~]# cd /etc/yum.repos.d/
[root@cl ~]# rm -rf *
[root@cl ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@cl yum.repos.d]# ls
CentOS-Base.repo
[root@cl yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@cl yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@cl yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@cl yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@cl ~]# dnf clean all
[root@cl ~]# dnf makecache
安装cobbler以及相关软件
[root@master ~]# dnf module list | grep cobbler //过滤系统上面是否有cobbler安装包
cobbler 3 default [d] Versatile Linux deployment server
cobbler 3.3 default [d] Versatile Linux deployment server
[root@master ~]# dnf -y module enable cobbler:3
[root@master ~]# dnf -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon
启动服务并设置开机自启
[root@master ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@master ~]# systemctl enable --now rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
[root@master ~]# systemctl enable --now tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
[root@master ~]# systemctl enable --now cobblerd.service
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
关闭防火墙和selinux并重启系统
[root@master ~]# systemctl stop firewalld.service
[root@master ~]# vim /etc/selinux/config
SELINUX=disabled
[root@master ~]# setenforce 0
setenforce: SELinux is disabled
[root@master ~]# systemctl disable --now firewalld.service
[root@master ~]# reboot
查看重启的访问是否起来
[root@master ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabl>
Active: active (running) since Sun 2022-09-25 13:59:59 CST; 11s ago
Docs: man:httpd.service(8)
Main PID: 940 (httpd)
Status: "Started, listening on: port 443, port 80"
Tasks: 231 (limit: 50536)
Memory: 53.9M
CGroup: /system.slice/httpd.service
├─ 940 /usr/sbin/httpd -DFOREGROUND
├─1562 /usr/sbin/httpd -DFOREGROUND
├─1563 (wsgi:cobbler_w -DFOREGROUND
├─1564 /usr/sbin/httpd -DFOREGROUND
├─1565 /usr/sbin/httpd -DFOREGROUND
└─1566 /usr/sbin/httpd -DFOREGROUND
Sep 25 13:59:57 master systemd[1]: Starting The Apache HTTP Server...
Sep 25 13:59:59 master systemd[1]: Started The Apache HTTP Server.
Sep 25 14:00:03 master httpd[940]: Server configured, listening on: port 443, port 80
[root@master ~]# systemctl status rsyncd
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disab>
Active: active (running) since Sun 2022-09-25 13:59:57 CST; 31s ago
Main PID: 1008 (rsync)
Tasks: 1 (limit: 50536)
Memory: 812.0K
CGroup: /system.slice/rsyncd.service
└─1008 /usr/bin/rsync --daemon --no-detach
Sep 25 13:59:57 master systemd[1]: Started fast remote file copy program daemon.
[root@master ~]# systemctl status tftp
● tftp.service - Tftp Server
Loaded: loaded (/usr/lib/systemd/system/tftp.service; indirect; vendor preset: disabl>
Active: inactive (dead)
Docs: man:in.tftpd
[root@master ~]# systemctl status cobblerd.service
● cobblerd.service - Cobbler Helper Daemon
Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; enabled; vendor preset: dis>
Active: active (running) since Sun 2022-09-25 13:59:57 CST; 56s ago
Process: 932 ExecStartPost=/usr/bin/touch /usr/share/cobbler/web/cobbler.wsgi (code=ex>
Main PID: 931 (cobblerd)
Tasks: 1 (limit: 50536)
Memory: 39.1M
CGroup: /system.slice/cobblerd.service
└─931 /usr/bin/python3 -s /usr/bin/cobblerd -F
Sep 25 13:59:57 master systemd[1]: Starting Cobbler Helper Daemon...
Sep 25 13:59:57 master systemd[1]: Started Cobbler Helper Daemon.
生成加密的密码
[root@master ~]# openssl passwd -1 -salt "$RANDOM" "redhat"
$1$32099$Nt2bru6kaYII0xr7LgwOl.
修改配置文件并将生成的密码写入其中然后重启cobbler服务
[root@master ~]# vim /etc/cobbler/settings.yaml
# (dual homed, etc), you need to read the --server-override section
# of the manpage for how that works.
server: 192.168.58.130
# of the Cobbler server here so that PXE booting guests can find it
# if you do not set this correctly, this will be manifested in TFTP open timeouts.
next_server: 192.168.58.130
# and put the output between the "" below.
default_password_crypted: "$1$32099$Nt2bru6kaYII0xr7LgwOl."
# set to true to enable Cobbler's DHCP management features.
# the choice of DHCP management engine is in /etc/cobbler/modules.conf
manage_dhcp: true
[root@master ~]# systemctl restart cobblerd.service
通过cobbler check 核对当前设置是否有问题,并解决问题
[root@master ~]# 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@master ~]# cd /var/lib/cobbler/loaders/
[root@master loaders]# ls
[root@master loaders]# dnf -y install syslinux*
[root@master loaders]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@master loaders]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@master loaders]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0
问题2,3:
[root@master ~]# dnf -y install yum-utils
问题4和问题5可以忽略,
因为如果使用的是debian系统才需要解决,使用的是centos8就可以不用解决
Debian系统解决办法安装fence-agents
配置DHCP模板文件,同步cobbler配置
[root@master ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.58.0 netmask 255.255.255.0 {
option routers 192.168.58.255;
option domain-name-servers 192.168.58.255;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.58.100 192.168.58.110;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
class "pxeclients"
[root@master ~]# systemctl restart httpd cobblerd.service
[root@master ~]# cobbler sync
task started: 2022-09-25_142930_sync
task started (id=Sync, time=Sun Sep 25 14:29:30 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@master loaders]# mount /dev/cdrom /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@master loaders]# cobbler import --path=/mnt/ --name=chenlang arch=x86_64
task started: 2022-09-25_162607_import
task started (id=Media import, time=Sun Sep 25 16:26:07 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/chenlang:
creating new distro: chenlang-x86_64
trying symlink: /var/www/cobbler/distro_mirror/chenlang -> /var/www/cobbler/links/chenlang-x86_64
creating new profile: chenlang-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/chenlang for chenlang-x86_64
processing repo at : /var/www/cobbler/distro_mirror/chenlang/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/chenlang/AppStream
looking for /var/www/cobbler/distro_mirror/chenlang/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/chenlang/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/chenlang/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/chenlang/BaseOS
looking for /var/www/cobbler/distro_mirror/chenlang/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/chenlang/BaseOS/repodata
*** TASK COMPLETE ***
列出cobbler镜像列表
[root@master ~]# cobbler list
distros:
chenlang-x86_64
profiles:
chenlang-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
查看详细信息 查看指定的–name 接镜像名
[root@master ~]# cobbler distro report --name chenlang-x86_64
Name : chenlang-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/chenlang-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/chenlang/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/chenlang/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自动安装脚本
# Firewall configuration
firewall --disabled //关闭防火墙
%packages
@^minimal-environment //添加最小化安装
%end
此时使用虚拟机去安装系统并不会成功 需要做如下操作
[root@master ~]# cd /usr/share/cobbler/bin/
[root@master bin]# ls
migrate-data-v2-to-v3.py migrate-settings.sh mkgrub.sh settings-migration-v1-to-v2.sh
[root@master bin]# bash mkgrub.sh
+ grub2-mkimage -O arm64-efi -o /var/lib/cobbler/loaders/grub/grubaa64.efi --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr efinet
grub2-mkimage: error: cannot open `/usr/lib/grub/arm64-efi/moddep.lst': No such file or directory.
+ set +x
+ grub2-mkimage -O i386-pc-pxe -o /var/lib/cobbler/loaders/grub/grub.0 --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr chain pxe biosdisk
+ set +x
+ grub2-mkimage -O powerpc-ieee1275 -o /var/lib/cobbler/loaders/grub/grub.ppc64le --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr net ofnet
grub2-mkimage: error: cannot open `/usr/lib/grub/powerpc-ieee1275/moddep.lst': No such file or directory.
+ set +x
+ grub2-mkimage -O x86_64-efi -o /var/lib/cobbler/loaders/grub/grubx64.efi --prefix= all_video boot cat configfile echo true font gfxmenu gfxterm gzio halt iso9660 jpeg minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test video fat loadenv linux btrfs ext2 xfs jfs reiserfs tftp http luks gcry_rijndael gcry_sha1 gcry_sha256 mdraid09 mdraid1x lvm serial regexp tr chain efinet
grub2-mkimage: error: cannot open `/usr/lib/grub/x86_64-efi/moddep.lst': No such file or directory.
+ set +x
+ ln -s /usr/share/syslinux/ldlinux.c32 /var/lib/cobbler/loaders/ldlinux.c32
+ set +x
[root@master bin]# ls /var/lib/cobbler/loaders/
grub ldlinux.c32 menu.c32 pxelinux.0
[root@master bin]# cobbler sync
task started: 2022-09-25_163457_sync
task started (id=Sync, time=Sun Sep 25 16:34:57 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/www/cobbler/images/chenlang-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/system
removing: /var/lib/tftpboot/grub/system_link
removing: /var/lib/tftpboot/grub/grub.cfg
removing: /var/lib/tftpboot/grub/local_efi.cfg
removing: /var/lib/tftpboot/grub/local_legacy.cfg
removing: /var/lib/tftpboot/grub/local_powerpc-ieee1275.cfg
removing: /var/lib/tftpboot/grub/x86_64_menu_items.cfg
removing: /var/lib/tftpboot/images/chenlang-x86_64
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 files for distro: chenlang-x86_64
trying hardlink /var/www/cobbler/distro_mirror/chenlang/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/chenlang-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/chenlang/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/chenlang-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: chenlang-x86_64
trying hardlink /var/www/cobbler/distro_mirror/chenlang/images/pxeboot/vmlinuz -> /var/www/cobbler/images/chenlang-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/chenlang/images/pxeboot/initrd.img -> /var/www/cobbler/images/chenlang-x86_64/initrd.img
Writing template files for chenlang-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
processing boot_files for distro: chenlang-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:
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 ***
[root@master bin]# systemctl restart httpd cobblerd.service
创建一个虚拟机来测试
手动选择下面的选项
自动安装,使用浏览器访问https://192.168.222.250/cobbler_web
默认登录的用户名和密码都为cobbler