cobbler

1. 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配置)

2.cobbler部署及安装centos7

[root@localhost ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config 
//下载源
[root@localhost ~]# yum -y install epel-release vim
[root@localhost ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart
//开启httpd cobbler,设置开机自启
[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl enable --now cobblerd
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
[root@localhost ~]# ss -antl
State       Recv-Q       Send-Q             Local Address:Port              Peer Address:Port      
LISTEN      0            5                      127.0.0.1:25151                  0.0.0.0:*         
LISTEN      0            128                      0.0.0.0:111                    0.0.0.0:*         
LISTEN      0            32                 192.168.122.1:53                     0.0.0.0:*         
LISTEN      0            128                      0.0.0.0:22                     0.0.0.0:*         
LISTEN      0            5                      127.0.0.1:631                    0.0.0.0:*         
LISTEN      0            128                         [::]:111                       [::]:*         
LISTEN      0            128                            *:80                           *:*         
LISTEN      0            128                         [::]:22                        [::]:*         
LISTEN      0            5                          [::1]:631                       [::]:*         
LISTEN      0            128                            *:443                          *:*         
[root@localhost ~]# cd /etc/cobbler/
[root@localhost cobbler]# ls
auth.conf         genders.template        named.template  secondary.template  zone.template
cheetah_macros    import_rsync_whitelist  power           settings            zone_templates
cobbler_bash      iso                     pxe             tftpd.template
completions       ldap                    reporting       users.conf
dhcp.template     modules.conf            rsync.exclude   users.digest
dnsmasq.template  mongodb.conf            rsync.template  version
[root@localhost cobbler]# vim settings
# if you do not set this correctly, this will be manifested in TFTP open timeouts.
next_server: 192.168.47.160 //设置本机的ip
# of the manpage for how that works.
server: 192.168.47.160
# and put the output between the "" below.
default_password_crypted: "$1$JRkIJtiU$Sl.2/VKpG5NBeltMfIQlV1"  //是下面的密码串,不是给我们用的,给cobbler认证用的
-- 插入 --                                                      
[root@localhost ~]# openssl passwd -1
Password: 
Verifying - Password: 
$1$JRkIJtiU$Sl.2/VKpG5NBeltMfIQlV1
[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 cobbler]# systemctl restart cobblerd
[root@localhost cobbler]# vim /etc/xinetd.d/tftp 
   disable                 = no //修改为no
   
//检查会有很多报错,解决报错   
[root@localhost ~]# 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 : 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@localhost ~]# yum -y install fence-agents
//将以下文件从8copy到7
[root@localhost ~]# cd /var/lib/cobbler/
[root@localhost cobbler]# ls
config                  kickstarts  lock     snippets  web.ss
distro_signatures.json  loaders     scripts  triggers  webui_sessions
[root@localhost cobbler]# cd loaders/
[root@localhost loaders]# ll
总用量 96
-rw-r--r-- 1 root root 9339 1013 18:56 COPYING.syslinux
-rw-r--r-- 1 root root 9339 1013 18:56 COPYING.yaboot
-rw-r--r-- 1 root root 9339 1013 18:56 grub-x86_64.efi
-rw-r--r-- 1 root root 9339 1013 18:56 grub-x86.efi
-rw-r--r-- 1 root root 9339 1013 18:56 menu.c32
-rw-r--r-- 1 root root 9339 1013 18:56 pxelinux.0
-rw-r--r-- 1 root root 9339 1013 18:56 README
-rw-r--r-- 1 root root 9339 1013 18:56 yaboot
//重启,同步
[root@localhost cobbler]# systemctl restart cobblerd
[root@localhost cobbler]# cobbler sync
//将dhcp功能打开
[root@localhost cobbler]# vim settings 
manage_dhcp: 1 //修改为1



[root@localhost cobbler]# vim dhcp.template 
subnet 192.168.47.0 netmask 255.255.255.0 { //修改为自己的网段
     option routers             192.168.47.160; //为自己IP
     option domain-name-servers 192.168.47.2; //dns把当前的网关设为nds
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.47.200 192.168.47.254; //范围有多少就能装几台主机,这里能装55台
     default-lease-time         21600;
     max-lease-time             43200;
//重启再同步一次
[root@localhost cobbler]# systemctl restart cobblerd
[root@localhost cobbler]# cobbler sync

//检查dhcp是否正常
[root@localhost cobbler]# netstat -anulp|grep dhcp
udp        0      0 0.0.0.0:67              0.0.0.0:*                           127784/dhcpd

//导入镜像               
[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# ls /mnt/
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@localhost ~]# cobbler import --path=/mnt --name=centos-7 --arch=x86_64
task started: 2021-10-13_191528_import
task started (id=Media import, time=Wed Oct 13 19:15:28 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@localhost ~]# cd /var/www/cobbler/ks_mirror/
[root@localhost ks_mirror]# ls
centos-7-x86_64  config
//查看cobbler镜像列表
[root@localhost ks_mirror]# cobbler list
distros:
   centos-7-x86_64

profiles:
   centos-7-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:





//创建kickstarts自动安装脚本
[root@localhost ~]# cd /var/lib/cobbler/
[root@localhost cobbler]# mkdir kickstarts
[root@localhost cobbler]# cd kickstarts/
[root@localhost kickstarts]# cat > /var/lib/cobbler/kickstarts/centos-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.47.160/cobbler/ks_mirror/rhel-8-x86_64 //这里是yum仓库,也就是刚刚的镜像位置
$yum_repo_stanza
reboot

rootpw --iscrypted $6$Md1qhEOb7LTFaBP4$nMWWI5baPspIRilBNLNIyBJLPfyFuN/eFcsd7n1.m5Ki1Mu3d.3XxRtn0kvu9PdwSqDIP1DfanDZzqm1AOdm2/    //此处的密码需要修改此处的密码是anaconda-ks.cfg里的密码
,可查看本机下的anaconda-ks.cfg文件,修改其密码


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

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

//查看当前cobbler有哪些配置文件
[root@localhost kickstarts]# cobbler profile list
   centos-7-x86_64
//修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@localhost kickstarts]# 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                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.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 profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.ks
//配置网卡名称为传统网卡名称eth0
[root@localhost kickstarts]# cobbler profile edit --name centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
//同步一下重启
[root@localhost kickstarts]# cobbler sync
task started: 2021-10-13_194321_sync
task started (id=Sync, time=Wed Oct 13 19:43:21 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/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
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: 
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/*
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 ***
[root@localhost kickstarts]# systemctl restart httpd cobblerd
[root@localhost kickstarts]# systemctl restart xinetd



3. 客户端的安装

//把有些文件换成系统文件
[root@localhost kickstarts]# cd /var/lib/cobbler/
[root@localhost cobbler]# ls
config                  kickstarts  lock     snippets  web.ss
distro_signatures.json  loaders     scripts  triggers  webui_sessions
[root@localhost cobbler]# cd loaders/
[root@localhost loaders]# ls
COPYING.syslinux  grub-x86_64.efi  menu.c32    README
COPYING.yaboot    grub-x86.efi     pxelinux.0  yaboot
[root@localhost loaders]# 
[root@localhost loaders]# \cp /usr/share/syslinux/pxelinux.0 .
[root@localhost loaders]# ls
COPYING.syslinux  grub-x86_64.efi  menu.c32    README
COPYING.yaboot    grub-x86.efi     pxelinux.0  yaboot
[root@localhost loaders]# ll
总用量 112
-rw-r--r-- 1 root root  9339 1013 18:56 COPYING.syslinux
-rw-r--r-- 1 root root  9339 1013 18:56 COPYING.yaboot
-rw-r--r-- 2 root root  9339 1013 18:56 grub-x86_64.efi
-rw-r--r-- 2 root root  9339 1013 18:56 grub-x86.efi
-rw-r--r-- 2 root root  9339 1013 18:56 menu.c32
-rw-r--r-- 2 root root 26759 1013 20:08 pxelinux.0
-rw-r--r-- 1 root root  9339 1013 18:56 README
-rw-r--r-- 2 root root  9339 1013 18:56 yaboot
[root@localhost loaders]# \cp /usr/share/syslinux/menu.c32 menu.c32
[root@localhost loaders]# 
[root@localhost loaders]# 
[root@localhost loaders]# 
[root@localhost loaders]# ll
总用量 156
-rw-r--r-- 1 root root  9339 1013 18:56 COPYING.syslinux
-rw-r--r-- 1 root root  9339 1013 18:56 COPYING.yaboot
-rw-r--r-- 2 root root  9339 1013 18:56 grub-x86_64.efi
-rw-r--r-- 2 root root  9339 1013 18:56 grub-x86.efi
-rw-r--r-- 2 root root 55140 1013 20:10 menu.c32
-rw-r--r-- 2 root root 26759 1013 20:08 pxelinux.0
-rw-r--r-- 1 root root  9339 1013 18:56 README
-rw-r--r-- 2 root root  9339 1013 18:56 yaboot


新建虚拟机从pxe启动,若出现以下界面则表示成功:

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

4. 定制安装

定制安装步骤:

统计服务器mac地址
配置cobbler
安装
统计mac地址此处就不赘述了,直接最重要的配置
在 cobbler 的web界面上配置:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
新建一台虚拟机,复制mac地址
在这里插入图片描述
在这里插入图片描述

//同步一下然后重启
[root@localhost ~]# cobbler sync
[root@localhost ~]# systemctl restart xinetd
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart cobblerd

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值