Cobbler
Cobbler简介:
- 快速网络安装linux操作系统的服务,支持众多的Linux发行版: Red Hat、Fedora、 CentOS、 Debian、 Ubuntu和SuSE,也可以支持网络安装windows
- PXE的二次封装,将多种安装参数封装到一个菜单
- Python编写
- 提供了CLI和Web的管理形式
cobbler的工作流程:
- client裸机配置了从网络启动后,开机后会广播包请求DHCP服务器( cobbler server)发送其分配好的一个IP
- DHCP服务器( cobbler server)收到请求后发送responese,包括其ip地址
- client裸机拿到ip后再向cobbler server发送请求OS引导文件的请求
- cobbler server告诉裸机OS引导文件的名字和TFTP server的ip和port
- client裸机通过上面告知的TFTP server地址通信,下载引导文件
- client裸机执行执行该引导文件,确定加载信息,选择要安装的os,期间会再向cobbler server请求kickstart文件和os image
- cobbler server发送请求的kickstart和os iamge
- client裸机加载kickstart文件
- client裸机接收os image,安装该os image
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7f1e6965cce9d40a0326a9c44073fcd4.jpeg)
cobbler命令
cobbler check //核对当前设置是否有问题
cobbler list //列出所有的cobbler元素
cobbler report //列出元素的详细信息
cobbler sync //同步配置到数据目录,更改配置最好都要执行下
cobbler reposync //同步yum仓库
cobbler distro //查看导入的发行版系统信息
cobbler system //查看添加的系统信息
cobbler profile //查看配置信息
cobbler部署
//关闭防火墙和selinux
[root@192 ~]
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@192 ~]
//cobbler服务,selinux必须得是disabled状态,所以要重启
[root@192 ~]
[root@192 ~]
Disabled
//更新yum源,并且安装epel包
[root@192 ~]
% 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 ~]
[root@192 ~]
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 ~]
[root@192 ~]
//安装cobbler以及相关的软件
[root@192 ~]
[root@192 ~]
//启动服务并设置开机自启
[root@192 ~]
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@192 ~]
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
[root@192 ~]
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
[root@192 ~]
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
[root@192 ~]
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 ~]
$1$8101$UcmYY8oMEImwxShqacaOT1
//修改cobbler主配置文件
[root@192 ~]
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 ~]
[root@192 ~]
[root@192 ~]
[root@192 ~]
menu.c32 pxelinux.0
[root@192 ~]
//重启cobbler
[root@192 ~]
[root@192 ~]
LISTEN 0 5 127.0.0.1:25151 0.0.0.0:* users:(("cobblerd",pid=13428,fd=6))
[root@192 ~]
//通过cobbler check 核对当前设置是否有问题
[root@192 ~]
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 ~]
subnet 192.168.159.0 netmask 255.255.255.0 {
option routers 192.168.159.2;
option domain-name-servers 8.8.8.8;
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 ~]
//同步cobbler配置
[root@192 ~]
..........
!!! TASK FAILED !!!
//挂载镜像
[root@192 ~]
//导入镜像
[root@192 ~]
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 ~]
distros:
Centos8-x86_64
profiles:
Centos8-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
[root@192 ~]
//查看详细信息 查看指定的--name 接镜像名
[root@192 ~]
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 ~]
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 ~]
//对脚本进行修改
[root@192 ~]
firewall --disable //防火墙关闭
....
%packages
@^minimal-environment //设置最小化安装
%end
//如果是生产环境,那么部署就已经完成,如果是虚拟机就还需执行以下步骤
[root@192 ~]
[root@192 bin]
migrate-data-v2-to-v3.py migrate-settings.sh mkgrub.sh settings-migration-v1-to-v2.sh
[root@192 bin]
//执行完上一步,去/var/lib/cobbler/loaders/下查看有没有grub与ldlinux.c32文件
[root@192 bin]
[root@192 loaders]
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]
//重启服务
[root@zwl ~]
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6c3ebb0a370b734f3362cc0d24331b1c.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/06d7f55ac00edb5afd728abf42dcc262.png)