cobbler
文章目录
一、cobbler简介
Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
puppet是一种Linux、Unix、windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet的设计目标是简化对这些资源的管理以及妥善处理资源间的依赖关系。
puppet采用C/S星状的结构,所有的客户端和一个或几个服务器交互。每个客户端周期的(默认半个小时)向服务器发送请求,获得其最新的配置信息,保证和该配置信息同步。每个puppet客户端每半小时(可以设置)连接一次服务器端, 下载最新的配置文件,并且严格按照配置文件来配置客户端. 配置完成以后,puppet客户端可以反馈给服务器端一个消息. 如果出错,也会给服务器端反馈一个消息。
二、cobbler集成的服务:
PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时需要)
Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
三、cobbler配置文件详解
cobbler配置文件目录在/etc/cobbler
配置文件 | 作用 |
---|---|
/etc/cobbler/settings.yaml | 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命令详解
cobbler check #核对当前设置是否有问题
cobbler list #列出所有的cobbler元素
cobbler report #列出元素的详细信息
cobbler sync #同步配置到数据目录,更改配置最好都要执行下
cobbler reposync #同步yum仓库
cobbler distro #查看导入的发行版系统信息
cobbler system #查看添加的系统信息
cobbler profile #查看配置信息
六、cobbler服务端单机配置
//配置yum源
[root@cobbler yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@cobbler yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@cobbler yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@cobbler yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
//安装cobbler以及相关的软件
[root@cobbler ~]# dnf module list |grep cobbler
cobbler 3 default [d] Versatile Linux deployment server
cobbler 3.3 default [d] Versatile Linux deployment server
[root@cobbler ~]# dnf module enable cobbler:3 -y
[root@cobbler ~]# yum -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon
//启动服务并设置开机自启
[root@cobbler ~]# systemctl restart httpd
[root@cobbler ~]# systemctl restart rsyncd
[root@cobbler ~]# systemctl restart tftp
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# systemctl enable httpd
[root@cobbler ~]# systemctl enable rsyncd
[root@cobbler ~]# systemctl enable tftp
[root@cobbler ~]# systemctl enable cobblerd
[root@cobbler ~]# ss -anlt
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 [::]:22 [::]:*
LISTEN 0 128 *:443 *:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 *:80 *:*
//关闭防火墙和selinux
[root@cobbler ~]# systemctl stop firewalld.service
[root@cobbler ~]# systemctl disable firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@cobbler ~]# setenforce 0
[root@cobbler ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/sysconfig/selinux
[root@cobbler ~]#
//修改/etc/cobbler/settings.yaml cobbler主配置文件
[root@cobbler ~]# vim /etc/cobbler/settings.yaml
server: 192.168.174.173 //修改server的ip地址为本机ip
next_server: 192.168.174.173 //设置tftp的ip地址为本机ip
default_password_crypted: "$1$26469$/ytVGuBqQYE/xa9zv78VY/" //将新生成的加密密码加入到配置文件
manage_dhcp: true //将cobbler的dhcp功能打开
//生成加密的密码
[root@cobbler ~]# openssl passwd -1 -salt "$RANDOM" "cobbler123"
$1$26469$/ytVGuBqQYE/xa9zv78VY/ //这是密码加密后的形式
//重启cobbler
[root@cobbler ~]# systemctl restart cobblerd
//通过cobbler check 核对当前设置是否有问题
[root@cobbler ~]# 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@cobbler loaders]# yum -y install syslinux*
[root@cobbler loaders]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@cobbler loaders]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@cobbler loaders]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0
问题2和问题3解决办法
[root@cobbler loaders]# yum -y install yum-utils
问题4和问题5可以忽略,
因为是debian系统才需要解决,显示使用的是centos8
Debian系统解决办法安装fence-agents
//配置DHCP模板文件
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.174.254;
option domain-name-servers 8.8.8.8;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.174.100 192.168.174.110;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
//同步cobbler配置
[root@cobbler ~]# systemctl restart httpd cobblerd.service
[root@cobbler ~]# cobbler sync
task started: 2022-09-25_162956_sync
task started (id=Sync, time=Sun Sep 25 16:29:56 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
....省略....
!!! TASK FAILED !!!
管理distro
//挂载镜像
[root@cobbler ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
//导入镜像
[root@cobbler ~]# cobbler import --path=/mnt/ --name=yy arch=x86_64
//查看cobbler镜像列表
[root@cobbler ~]# cobbler list
distros:
yy-x86_64
profiles:
yy-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
//查看详细信息 查看指定的--name 接镜像名
[root@cobbler ~]# cobbler distro report --name yy-x86_64
Name : yy-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/yy-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/yy/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/yy/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自动安装脚本
[root@cobbler ~]# cobbler profile get-autoinstall --name yy-x86_64 > /var/lib/cobbler/templates/yy.ks
[root@cobbler ~]# cd /var/lib/cobbler/templates/
[root@cobbler templates]# vim yy.ks
…………
firewall --disable //防火墙关闭
…………
%packages
@^minimal-environment //设置最小化安装
…………
//如果是生产环境,那么部署就已经完成,如果是虚拟机就还需执行以下步骤
[root@cobbler templates]# cd /usr/share/cobbler/bin/
[root@cobbler bin]# ls
migrate-data-v2-to-v3.py mkgrub.sh
migrate-settings.sh settings-migration-v1-to-v2.sh
[root@cobbler bin]# bash mkgrub.sh
[root@cobbler bin]# cd /var/lib/cobbler/loaders/
[root@cobbler loaders]# ll
total 72
drwxr-xr-x 2 root root 79 Sep 25 19:54 grub
lrwxrwxrwx 1 root root 31 Sep 25 19:54 ldlinux.c32 -> /usr/share/syslinux/ldlinux.c32
-rw-r--r-- 1 root root 26272 Sep 25 17:58 menu.c32
-rw-r--r-- 1 root root 42376 Sep 25 17:58 pxelinux.0
[root@cobbler loaders]# cobbler sync
[root@cobbler loaders]# systemctl restart httpd cobblerd.service
客户端安装系统
新建一台虚拟机,设置好cpu,内存等配置,无需自行添加镜像。创建好直接开启虚拟机。
需耐心等待,出现如下界面,选择刚刚制作的镜像
大约等待几分钟,密码就是生成的加密密码,我设置的是centos
七、定制安装
//浏览器的地址栏访问cobbler的web界面必须是https+ip+cobbler_web的格式
//默认的用户名与密码都是cobbler
创建虚拟机进行测试
虚拟机设置完成之后直接开启,开启后无需任何操作,他自动会执行直到用户界面,可以看到IP地址就是设置的未使用的IP地址
6xxAA-1664115677734)]
[外链图片转存中…(img-43jcpWru-1664115677735)]
[外链图片转存中…(img-pJYldEHU-1664115677735)]
创建虚拟机进行测试
[外链图片转存中…(img-dzT8uaAV-1664115677735)]
虚拟机设置完成之后直接开启,开启后无需任何操作,他自动会执行直到用户界面,可以看到IP地址就是设置的未使用的IP地址
[外链图片转存中…(img-eRvyXRxB-1664115677736)]