其他分享
首页 > 其他分享> > cobbler

cobbler

作者:互联网

cobbler

1. cobbler简介

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

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

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

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

cobbler集成的服务

2. Cobbler工作原理

在这里插入图片描述

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     //查看配置信息

3. cobbler服务端部署

//安装epel源
[root@localhost ~]# yum -y install epel-release

//安装依赖包
[root@localhost ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart fence-agents syslinux

//启动服务
[root@localhost ~]# systemctl enable --now httpd 
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl enable --now cobblerd 
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
[root@localhost cobbler]# systemctl enable --now rsyncd 
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

//生成密钥
[root@localhost ~]# openssl passwd -1 
Password: 
Verifying - Password: 
$1$bOpniamj$1YuLQBx.AFuL/b78nACK4/

//修改配置文件
[root@localhost cobbler]# vim settings
server: 192.168.200.151
next_server: 192.168.200.151
default_password_crypted: "$1$bOpniamj$1YuLQBx.AFuL/b78nACK4/"
[root@localhost cobbler]# systemctl restart cobblerd

//修改tftp
[root@localhost cobbler]# vim /etc/xinetd.d/tftp
 disable                 = no

//从centos8上传文件 提供缺失文件
[root@localhost cobbler]# scp  root@192.168.200.150:/var/lib/cobbler/loaders/* .
The authenticity of host '192.168.200.150 (192.168.200.150)' can't be established.
ECDSA key fingerprint is SHA256:6pn/taoSrwdqKNTLndCgj4EL8rogROHK3YHp92C3J3Y.
ECDSA key fingerprint is MD5:0f:51:67:d4:5b:a9:ca:3e:73:99:5b:af:1b:bd:73:53.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.200.150' (ECDSA) to the list of known hosts.
root@192.168.200.150's password: 
COPYING.syslinux         100% 9339     6.2MB/s   00:00    
COPYING.yaboot           100% 9339    13.9MB/s   00:00    
grub-x86_64.efi          100% 9339    10.6MB/s   00:00    
grub-x86.efi             100% 9339    14.4MB/s   00:00    
menu.c32                 100%   26KB  30.5MB/s   00:00    
pxelinux.0               100%   41KB  42.4MB/s   00:00    
README                   100% 9339    15.6MB/s   00:00    
yaboot                   100% 9339    16.2MB/s   00:00    

//同步
[root@localhost cobbler]# cobbler sync
task started: 2021-10-13_072621_sync
task started (id=Sync, time=Wed Oct 13 07:26:21 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 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 shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

//配置dhcp
[root@localhost cobbler]# vim settings 
manage_dhcp: 1
[root@localhost cobbler]# vim dhcp.template
subnet 192.168.200.0 netmask 255.255.255.0 {
     option routers             192.168.200.151;
     option domain-name-servers 192.168.200.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.200.100 192.168.200.254;
     default-lease-time         21600;
     max-lease-time             43200;
     
[root@localhost cobbler]# systemctl restart cobblerd     
[root@localhost cobbler]# cobbler sync
[root@localhost cobbler]# netstat -anulp|grep dhcp
udp        0      0 0.0.0.0:67              0.0.0.0:*                           4964/dhcpd  

//挂载光盘
[root@localhost cobbler]# mount /dev/cdrom /mnt 
mount: /dev/sr0 写保护,将以只读方式挂载

//导入镜像
[root@localhost www]# cobbler import --path=/mnt --name=rhel-7 --arch=x86_64
task started: 2021-10-13_074516_import
task started (id=Media import, time=Wed Oct 13 07:45:16 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/rhel-7-x86_64:
creating new distro: rhel-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/rhel-7-x86_64 -> /var/www/cobbler/links/rhel-7-x86_64
creating new profile: rhel-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/rhel-7-x86_64 for rhel-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/rhel-7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-7-x86_64
looking for /var/www/cobbler/ks_mirror/rhel-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-7-x86_64/repodata
*** TASK COMPLETE ***
[root@localhost cobbler]# cd /var/www/
[root@localhost www]# ls
cgi-bin  cobbler  cobbler_webui_content  html

[root@localhost ks_mirror]# cobbler list 
distros:
   rhel-7-x86_64

profiles:
   rhel-7-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

//创建自动安装脚本
cat > /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks <<'EOF'
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.200.151/cobbler/ks_mirror/centos-7-x86_64
$yum_repo_stanza
reboot

rootpw --iscrypted $6$2WTFvfNvAMgCUPuC$MJgWGzhakgxrRObcEbAwSe8vkz0s//xyiTllGwxRsHHruQhcskO69u2LVTU9u0eemHXH2pzcGawyAJ54R2E/x0

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
EOF

[root@localhost kickstarts]# mv rhel-7-x86_64.ks centos-7-x86_64.ks
[root@localhost kickstarts]# ls
centos-7-x86_64.ks  pxerescue.ks         sample_esxi6.ks
default.ks          sample_autoyast.xml  sample.ks
esxi4-ks.cfg        sample_end.ks        sample_old.seed
esxi5-ks.cfg        sample_esx4.ks       sample.seed
install_profiles    sample_esxi4.ks      sample.seed.28
legacy.ks           sample_esxi5.ks

//检查ks文件语法是否有误
[root@localhost kickstarts]#  cobbler validateks
task started: 2021-10-13_082816_validateks
task started (id=Kickstart Validation, time=Wed Oct 13 08:28:16 2021)
----------------------------
osversion: rhel7
checking url: http://192.168.200.151/cblr/svc/op/ks/profile/rhel-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.200.151/cblr/svc/op/ks/profile/rhel-7-x86_64"
received on stdout: 
received on stderr: 
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***

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

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

//检查当前系统cobbler配置文件信息
[root@localhost kickstarts]# cobbler profile report
Name                           : rhel-7-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : rhel-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
[root@localhost kickstarts]# cobbler sync
[root@localhost kickstarts]# systemctl restart httpd cobblerd
[root@localhost kickstarts]# systemctl start xinetd

4. 客户端安装

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

5.自定义安装

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

//重启服务
[root@localhost ks_mirror]# systemctl restart httpd 
[root@localhost ks_mirror]# systemctl restart cobblerd
[root@localhost ks_mirror]# systemctl restart xinetd
[root@localhost ks_mirror]# cobbler sync 

标签:x86,lib,cobbler,var,root,localhost
来源: https://blog.csdn.net/weixin_46634416/article/details/120752233