Cobbler无人值守安装系统

1.简介

Cobbler 可以用来快速建立 Linux 网络安装环境,它已将 Linux 网络安装的技术门槛,从大专以上文化水平,成功降低到初中以下,连补鞋匠都能学会
Cobbler是一个Linux服务器安装的服务,可以通过网络启动的方式来快速安装,重装五i服务器和虚拟机,同时还可以管理DHCP,DNS等
Cobbler可以使用命令行方式管理,也提供了基于web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较容易管理。

2.环境准备

在这里插入图片描述

3.安装

3.1安装依赖
[root@ cobbler ~]# yum -y install cobbler cobbler-web tftp-server pykickstart httpd dhcp xinetd debmirror

#具体作用
cobbler #cobbler程序包
cobbler-web #cobbler的web服务包
pykickstart #cobbler检查kickstart语法错误
httpd  #Apache web服务
dhcp  #Dhcp服务
tftp  #tftp服务
xinetd #诸多服务的超级守护进程

#启动cobbler以及httpd并加入开机自启动
[root@ cobbler ~]# systemctl start httpd cobblerd
[root@ cobbler ~]# systemctl enable httpd cobblerd

4.配置cobbler

检查Cobbler的配置,如果看不到下面的结果,就再次重启cobbler

[root@ cobbler ~]# cobbler check    #告诉我们需要完成以下内容
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : 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.
5 : enable and start rsyncd.service with systemctl
6 : comment out 'dists' on /etc/debmirror.conf for proper debian support
7 : comment out 'arches' on /etc/debmirror.conf for proper debian support
8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
9 : 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.
4.1解决问题
[root@ cobbler ~]# sed -ri '/allow_dynamic_settings:/c\allow_dynamic_settings: 1' /etc/cobbler/settings

[root@ cobbler ~]# grep allow_dynamic_settings /etc/cobbler/settings 
allow_dynamic_settings: 1

[root@ cobbler ~]# systemctl restart cobblerd

4.2 具体操作步骤
#1.配置server地址
[root@ cobbler ~]# cobbler setting edit --name=server --value=10.0.0.41   #写自己的本机IP地址

#2.配置next_server地址
[root@ cobbler ~]# cobbler setting edit --name=next_server --value=10.0.0.41   #写自己的本机IP地址

#3.配置xinetd管理tftp
[root@ cobbler ~]# sed -ri '/disable/c\disable = no' /etc/xinetd.d/tftp 
[root@ cobbler ~]# systemctl enable xinetd
[root@ cobbler ~]# systemctl restart xinetd

#4.boot-loaders
[root@ cobbler ~]# cobbler get-loaders
task started: 2020-03-02_205432_get_loaders
task started (id=Download Bootloader Content, time=Mon Mar  2 20:54:32 2020)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***

#5.启动rsync
[root@ cobbler ~]# systemctl start rsyncd
[root@ cobbler ~]# systemctl enable rsyncd

#6和7 .debian support
[root@ cobbler ~]# sed -i 's#@dists="sid";#\#@dists="sid";#gp' /etc/debmirror.conf
[root@ cobbler ~]# sed -i 's#@arches="i386";#\#@arches="i386";#g' /etc/debmirror.conf

#8.default_password_crypted
#注意:这里设置的密码是cobbler安装完系统后,默认root用户初始胡东路密码,用openssl生成一段密码胡加入到cobbler的配置文件中,替换default_password_crypted字段
[root@ cobbler ~]# openssl passwd -1 -salt "root" "123456"
$1$root$j0bp.KLPyr.u9kgQ428D10
#可以编辑cobbler的配置文件来替换密码
[root@ cobbler ~]# vim /etc/cobbler/settings 
default_password_crypted: $1$root$j0bp.KLPyr.u9kgQ428D10.  #这个密码就是刚刚我们使用openssl生成的

#9.安装fencing tools
[root@ cobbler ~]# yum -y install fence-agents

#解决完问题之后我们再次检查
[root@ cobbler ~]# systemctl restart cobblerd
[root@ cobbler ~]# cobbler sync  #修改cobbler文件后一定要记得同步
task started: 2020-03-02_210723_sync
task started (id=Sync, time=Mon Mar  2 21:07:23 2020)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
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 ***
[root@ cobbler ~]# cobbler check   #出现下面的输出,表示已经解决完我们的问题,可以开始下一步的操作了
No configuration problems found.  All systems go.

5.配置DHCP

[root@ cobbler ~]# cobbler setting edit --name=manage_dhcp --value=1
[root@ cobbler ~]# vim /etc/cobbler/dhcp.template
#修改以下几处 加粗的地方
subnet 10.0.0.0 netmask 255.255.255.0 {  #这里改为分配的网段和子网掩码
     option routers             10.0.0.254; #如果有网关,改为网关的地址
     option domain-name-servers 223.5.5.5; #如果有DNS,改为DNS地址
     option subnet-mask         255.255.255.0;  #改为分配的IP的子网掩码
     range dynamic-bootp        10.0.0.2 10.0.0.200;  #改为分配的IP范围

6.同步cobbler配置

[root@ cobbler ~]# cobbler sync

查看dhcp,查看cobbler是否可以管理dhcp

[root@ cobbler ~]# cat /etc/dhcp/dhcpd.conf 
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Mon Mar  2 13:17:08 2020)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# ******************************************************************

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;

subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.254;
     option domain-name-servers 223.5.5.5;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.2 10.0.0.200;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                10.0.0.41;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "grub/grub-x86.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "grub/grub-x86_64.efi";
          } else if option pxe-system-type = 00:09 {
                  filename "grub/grub-x86_64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }

}

# group for Cobbler DHCP tag: default
group {
}

7.cobbler常用命令

在这里插入图片描述
这个时候创建一个新的虚拟机可以获取如下信息,没有镜像选择,只能从本地启动
在这里插入图片描述
在这里插入图片描述
创建完之后开启此虚拟机,会出现以下图像
在这里插入图片描述

8.cobbler安装centos6.10

注意:我这里这台是centos7系统上配置cobbler,并没有centos6.10镜像,所以需要上传并挂载

8.1创建挂载点并挂载
[root@ cobbler ~]# ll
total 3898372
-rw-------. 1 root root       1277 2019-09-17 22:18 anaconda-ks.cfg
-rw-r--r--  1 root root 3991928832 2020-03-02 21:34 CentOS-6.10-x86_64-bin-DVD1.iso
[root@ cobbler ~]# mkdir /centos6.10
[root@ cobbler ~]# mount -o loop CentOS-6.10-x86_64-bin-DVD1.iso /centos6.10/
mount: /dev/loop0 is write-protected, mounting read-only
=
8.2查看挂在后的目录
[root@ cobbler ~]# ll /centos6.10/
total 566
-r--r--r-- 2 root root     14 2018-06-29 23:37 CentOS_BuildTag
dr-xr-xr-x 3 root root   2048 2018-06-30 00:11 EFI
-r--r--r-- 2 root root    212 2013-11-27 17:36 EULA
-r--r--r-- 2 root root  18009 2013-11-27 17:36 GPL
dr-xr-xr-x 3 root root   2048 2018-06-30 00:20 images
dr-xr-xr-x 2 root root   2048 2018-06-30 00:11 isolinux
dr-xr-xr-x 2 root root 536576 2018-06-30 00:18 Packages
-r--r--r-- 2 root root   1363 2018-06-29 22:33 RELEASE-NOTES-en-US.html
dr-xr-xr-x 2 root root   4096 2018-06-30 00:20 repodata
-r--r--r-- 2 root root   1706 2013-11-27 17:36 RPM-GPG-KEY-CentOS-6
-r--r--r-- 2 root root   1730 2013-11-27 17:36 RPM-GPG-KEY-CentOS-Debug-6
-r--r--r-- 2 root root   1730 2013-11-27 17:36 RPM-GPG-KEY-CentOS-Security-6
-r--r--r-- 2 root root   1734 2013-11-27 17:36 RPM-GPG-KEY-CentOS-Testing-6
-r--r--r-- 1 root root   3380 2018-06-30 00:20 TRANS.TBL
8.3导入镜像
[root@ cobbler ~]# cobbler import --path=/centos6.10 --name=centos6.10 --arch=x86_64
task started: 2020-03-02_213953_import
task started (id=Media import, time=Mon Mar  2 21:39:53 2020)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/centos6.10-x86_64:
creating new distro: centos6.10-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos6.10-x86_64 -> /var/www/cobbler/links/centos6.10-x86_64
creating new profile: centos6.10-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/centos6.10-x86_64 for centos6.10-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos6.10-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos6.10-x86_64
looking for /var/www/cobbler/ks_mirror/centos6.10-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos6.10-x86_64/repodata
*** TASK COMPLETE ***

#用到的参数解释
# --path  镜像路径
# --name  为安装源定义一个名字
# --arch 指定安装源是32位 64位 ia64 目前支持的选项有x86/x86_64/ia64
# 安装源的唯一标识就是根据name参数来定义,本例导入成功后,安装源的唯一标识就是centos6.10,如果名字重复,就会导入失败
8.4查看导入后镜像信息
[root@ cobbler ~]# cobbler distro report ==name=centos6.10-x86_64
Name                           : centos6.10-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/centos6.10-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos6.10-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos6.10-x86_64'}
Management Classes             : []
OS Version                     : rhel6
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

8.5查看profile信息
[root@ cobbler ~]# cobbler profile report --name=centos6.10-x86_64
Name                           : centos6.10-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : centos6.10-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

8.6编辑centos6.10镜像的kickstart文件
[root@ cobbler ~]# cd /var/lib/cobbler/kickstarts/

[root@ cobbler kickstarts]# cp sample_end.ks centos6.10.ks

[root@ cobbler kickstarts]# vim centos6.10.ks
 
# This kickstart file should only be used with EL > 5 and/or Fedora > 7.
# For older versions please use the sample.ks kickstart file.
# Install OS instead of upgrade
install
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# System timezone
timezone  Asia/ShangHai
#Root password
rootpw --iscrypted $default_password_crypted
# System authorization information
auth  --useshadow  --enablemd5
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Use network installation
url --url=$tree

# Clear the Master Boot Record
zerombr
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
part /boot --fstype=ext4 --size=200
part swap --fstype=swap --size=2048
part / --fstype=ext4 --grow --size=200 --asprimary

# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Do not configure the X Window System
skipx
# Run the Setup Agent on first boot
firstboot --disable
# Reboot after installation
reboot


%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end

%packages
$SNIPPET('func_install_if_enabled')
@core
@base
tree
nmap
wget
lftp
lrzsz
telnet
%end

%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end

%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps

sed -ri "/^#UseDNS/c\UseDNS no" /etc/ssh/sshd_config
sed -ri "/^GSSAPIAuthentication/c\GSSAPIAuthentication no" /etc/ssh/sshd_config
%end

8.7同步Cobbler配置

[root@ cobbler kickstarts]# cobbler sync
task started: 2020-03-02_215627_sync
task started (id=Sync, time=Mon Mar  2 21:56:27 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos6.10-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos6.10-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying files for distro: centos6.10-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos6.10-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos6.10-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos6.10-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos6.10-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos6.10-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos6.10-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos6.10-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos6.10-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos6.10-x86_64/initrd.img
Writing template files for centos6.10-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos6.10-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 ***
8.8开始进行测试

选择这个就可以了
在这里插入图片描述
出现这样表示安装成功了在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值