Cobbler批量安装主机,部署

一 Cobbler介绍

Cobbler 是一个系统启动服务(boot server),可以通过网络启动(PXE)的方式用来快速安装、重装物理服务器和虚拟机,支持安装不同的 Linux 发行版和 Windows。该工具使用python开发,小巧轻便(才15k行代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP,DNS,以及yum包镜像。

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

二 Cobbler提供以下服务集成

1、PXE服务支持

2、DHCP服务管理

3、DNS服务管理(可选bind,dnsmasq)

4、电源管理

5、Kickstart服务支持

6、yum仓库管理

7、TFTP (PXE启动时需要)

8、Apache(提供kickstart 的安装源,并提供定制化的kickstart配置)

同时,它和apache做了深度整合。通过 cobbler,可以实现对RedHat/Centos/Fedora系统的快速部署,同时也支持Suse 和Debian(Ubuntu)系统,通过配置也支持windows。

三 Cobbler的工作流程

在这里插入图片描述
下面我们来简单的说明一下,

Server端:

第一步,启动Cobbler服务

第二步,进行Cobbler错误检查,执行cobbler check命令

第三步,进行配置同步,执行cobbler sync命令

第四步,复制相关启动文件文件到TFTP目录中

第五步,启动DHCP服务,提供地址分配

第六步,DHCP服务分配IP地址

第七步,TFTP传输启动文件

第八步,Server端接收安装信息

第九步,Server端发送ISO镜像与Kickstart文件

Client端:

第一步,客户端以PXE模式启动

第二步,客户端获取IP地址

第三步,通过TFTP服务器获取启动文件

第四步,进入Cobbler安装选择界面

第五步,客户端确定加载信息

第六步,根据配置信息准备安装系统

第七步,加载Kickstart文件

第八步,传输系统安装的其它文件

第九步,进行安装系统

四 Cobbler部署安装

环境ip地址
centos7192.168.143.145
//关闭防火墙和selinux
  #  systemctl disable --now firewalld
  #  sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
  #  reboot
  #  getenforce 
Disabled
//安装cobbler以及相关的软件
  #  yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart net-tools
//启动服务并设置开机自启  
  #  systemctl enable --now httpd
  #  systemctl enable --now cobblerd
// 修改server的ip地址为本机ip
  #  sed -i 's/^server: 127.0.0.1/server: 192.168.143.145/' /etc/cobbler/settings
  #  sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.143.145/' /etc/cobbler/settings
// 开启tftp
  #  sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp
// 生成加密密码
  #  openssl passwd -1 -salt "$RANDOM" '147258'
// 将密码修改配置文件中
  #  vim /etc/cobbler/settings
  # and put the output between the "" below.
default_password_crypted: "$1$5589$2DKLSK786Ie/i7OjjerJu." //修改此行
//启动rsync并设置开机自启
  #  systemctl enable --now rsyncd
// 重启cobbler
  #  systemctl restart cobblerd
//通过cobbler check 核对当前设置是否有问题
  #  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

Restart cobblerd and then run 'cobbler sync' to apply changes.
// 解决序号2报错
  #  yum -y install fence-agents debmirror yum-utils syslinux
  #  sed -i  's|@dists=.*|#@dists=|'  /etc/debmirror.conf
  #  sed -i  's|@arches=.*|#@arches=|'  /etc/debmirror.conf
// 解决序号1报错
  #  cd /var/lib/cobbler/
  #  ls
//这边loadders未产生文件,这边Xftp,传入 /var/lib/cobbler/中
  #  ll loaders/
       总量 0
//提供loaders/压缩包直链,https://wwe.lanzoui.com/ilf1Cvbcvsd
  #  tar xf loaders.tar.gz 
  #  ll loaders/
  #  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.
//修改cobbler配置文件,让cobbler控制dhcp
  #  sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
//配置dhcp配置文件
  #  vim /etc/cobbler/dhcp.template
  subnet 192.168.143.0 netmask 255.255.255.0 {    //192.168.143.0为本机网段
     option routers             192.168.143.145;    //本机IP
     option domain-name-servers 192.168.143.2;    //本机网段
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.143.200 192.168.143.254;    //获取的IP范围
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
//重启服务并同步配置,改完dhcp必须要sync同步配置
  #  systemctl restart cobblerd
  #  cobbler sync
//检查dhcp是否正常
  #  netstat -anulp|grep dhcp
//导入镜像
  #  mount /dev/cdrom /mnt/
  #  cobbler import --path=/mnt --name=centos-7 --arch=x86_64
  #  ls /var/www/cobbler/ks_mirror/
//查看cobbler镜像列表
  #  cobbler list
//创建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
network  --bootproto=dhcp  --nameserver=223.5.5.5 --activate
url --url=http://192.168.143.145/cobbler/ks_mirror/centos-7-x86_64 //修改为本机IP目录为刚刚生成的导入镜像名
$yum_repo_stanza
reboot

rootpw --iscrypted $6$o.KUbTGeilEbPTwv$.k4r6XZAFPFOTU9G4cYSOUoVcM0UEIfvtMV.iZxsAep5rtXbt9jG9rar8aTT1.ruvbPg/GakalCbSN0UsdQ2c0  //修改为/root/anaconda-ks.cfg中rootpw --iscrypted的root密码

selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr

%packages
@^minimal
@core
kexec-tools
chrony
vim-enhanced
wget
net-tools
tree
bash-com*
%end

services --enabled="chronyd"
%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文件语法是否有误
  #  cobbler validateks
//修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
  #  cobbler profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.ks
//配置网卡名称为传统网卡名称eth0
  #  cobbler profile edit --name centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
//查看配置信息
  #  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                 : {'biosdevname': '0', 'net.ifnames': '0'}    //网卡设为传统命名方式
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/centos-7-x86_64.ks    //使用的kickstarts配置文件的路径,必须为我们新建的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
//同步cobbler
  #  cobbler sync
// loaders缺少文件
  #  cp /usr/share/syslinux/pxelinux.0  /var/lib/cobbler/loaders/
  #  cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
// 重启服务
  #  systemctl restart xinetd cobblerd httpd
  #  ss -atnl
State       Recv-Q Send-Q                                                  Local Address:Port                                                                 Peer Address:Port              
LISTEN      0      5                                                           127.0.0.1:25151                                                                           *:*                  
LISTEN      0      5                                                                   *:873                                                                             *:*                  
LISTEN      0      128                                                                 *:22                                                                              *:*                  
LISTEN      0      5                                                                  :::873                                                                            :::*                        
LISTEN      0      128                                                                :::80                                                                             :::*                  
LISTEN      0      128                                                                :::22                                                                             :::*                  
LISTEN      0      128                                                                :::443                                                                            :::*    

在这里插入图片描述

在这里插入图片描述

五 定制安装

访问http://192.168.143.139/cobbler_web提示没有权限
Forbidden
You don’t have permission to access /cobbler_web on this server.
解决方案
使用https地址访问: https://192.168.143.139/cobbler_web
在浏览器上添加例外或者换成微软浏览器访问
在这里插入图片描述
账号密码都为cobbler
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

// 同步重启
[root@139 systems.d]# cobbler sync
task started: 2021-10-14_153209_sync
task started (id=Sync, time=Thu Oct 14 15:32:09 2021)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos-7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-30-8b-c4
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-20-e0-2a
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/01-00-50-56-30-8B-C4
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/grub/01-00-50-56-20-E0-2A
removing: /var/lib/tftpboot/images/centos-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
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: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-20-e0-2a
generating: /var/lib/tftpboot/grub/01-00-50-56-20-E0-2A
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@139 systems.d]# systemctl restart httpd cobblerd xinetd
[root@139 systems.d]# 

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

web页面配置,文件位置

[root@139 systems.d]# pwd
/var/lib/cobbler/config/systems.d
[root@139 systems.d]# ls
test.json
[root@139 systems.d]# cat test.json 
{"comment": "", "status": "production", "kickstart": "/var/lib/cobbler/kickstarts/centos-7-x86_64.ks", "name_servers_search": [], "ks_meta": {}, "kernel_options_post": {}, "image": "", "redhat_management_key": "<<inherit>>", "virt_path": "<<inherit>>", "power_user": "", "kernel_options": {"biosdevname": "0", "net.ifnames": "0"}, "ctime": 1634195518.830579, "name_servers": ["114.114.114.114"], "mtime": 1634196717.134878, "enable_gpxe": false, "template_files": {}, "gateway": "192.168.143.2", "uid": "MTYzNDE5NTUxOC44MzE5NDE5NTUuMDMxMDY", "virt_auto_boot": 0, "power_type": "amt_ws", "virt_cpus": "<<inherit>>", "mgmt_parameters": "<<inherit>>", "boot_files": {}, "hostname": "servera.example.com", "repos_enabled": false, "mgmt_classes": [], "power_pass": "", "netboot_enabled": true, "ipv6_autoconfiguration": false, "profile": "centos-7-x86_64", "virt_type": "xenpv", "interfaces": {"eth0": {"ipv6_address": "", "interface_type": "", "static": true, "cnames": [], "bridge_opts": "", "management": false, "interface_master": "", "mac_address": "00:50:56:20:E0:2A", "ipv6_prefix": "", "virt_bridge": "xenbr0", "netmask": "255.255.255.0", "bonding_opts": "", "ip_address": "192.168.143.140", "dhcp_tag": "", "ipv6_mtu": "", "static_routes": [], "ipv6_static_routes": [], "if_gateway": "", "dns_name": "", "mtu": "", "connected_mode": false, "ipv6_secondaries": [], "ipv6_default_gateway": ""}}, "power_address": "", "proxy": "<<inherit>>", "fetchable_files": {}, "virt_file_size": "<<inherit>>", "ldap_enabled": false, "monit_enabled": false, "ipv6_default_device": "", "virt_pxe_boot": 0, "virt_disk_driver": "<<inherit>>", "owners": "<<inherit>>", "name": "test", "virt_ram": "<<inherit>>", "power_id": "", "server": "<<inherit>>", "redhat_management_server": "<<inherit>>", "depth": 2, "ldap_type": "authconfig", "template_remote_kickstarts": 0}
[root@139 systems.d]# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值