一、Cobbler介绍

1.1 关于Cobbler

1、Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
2、Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
3、Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
4、Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet。

 

Cobbler提供以下服务集成:

* PXE服务支持

* DHCP服务管理

* DNS服务管理

* 电源管理

* Kickstart服务支持

* yum仓库管理

* TFTP

* Apache

cobbler官网:http://cobbler.github.io/

二 、 Cobbler部署

环境:Centos7

外网ip:10.0.0.42

说明:虚拟机网卡采用NAT模式或者仅主机模式,不要使用桥接模式,因为后面会搭建DHCP服务器,在同一个局域网多个DHCP服务会有冲突。
VMware的NAT模式的dhcp服务也关闭,避免干扰。

1.2.1 安装

# yum -y install cobbler cobbler-web tftp-server pykickstart httpd dhcp xinetd debmirror        #下载相关依赖包


cobbler                     #cobbler程序包

cobbler-web             #cobbler的web服务包

tftp-server                #cobbler检查kickstart语法错误

httpd                        #Apache    web服务

tftp                           #Dhcp服务

xinetd                      #诸多服务的超级守护进程

# 启动cobbler及httpd并开机启动

[[email protected] c7-42 ~]# systemctl start httpd cobblerd
[[email protected] c7-42 ~]# systemctl status httpd cobblerd

[[email protected] c7-42 ~]# systemctl enable httpd cobblerd

1.2.2 配置cobbler

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

[[email protected] c7-42 ~]# 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 handlex86/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.

看到上面出现的问题,然后一个一个的进行解决,先进行设置为可以动态配置,也可以直接更改配置文件。

[[email protected] c7-42 ~]# sed -ri '/allow_dynamic_settings:/c\allow_dynamic_settings: 1' /etc/cobbler/settings
[[email protected] c7-42 ~]# grep allow_dynamic_settings /etc/cobbler/settings
allow_dynamic_settings: 1
[[email protected] c7-42 ~]# systemctl restart cobblerd

逐个解决上面的问题

#1.配置server地址

[[email protected] c7-42 ~]# cobbler setting edit --name=server --value=10.0.0.42

#2.配置next_server地址

[[email protected] c7-42 ~]# cobbler setting edit --name=next_server --value=10.0.0.42

#3.配置xinetd管理tftp

[[email protected] c7-42 ~]# sed -ri '/disable/c\disable = no' /etc/xinetd.d/tftp
[[email protected] c7-42 ~]# systemctl enable xinetd
[[email protected] c7-42 ~]# systemctl restart xinetd

#4.下载操作系统引导文件

[[email protected] c7-42 ~]# cobbler get-loaders
task started: 2020-05-07_155211_get_loaders
task started (id=Download Bootloader Content, time=Thu May  7 15:52:11 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

[[email protected] c7-42 ~]# systemctl start rsyncd
[[email protected] c7-42 ~]# systemctl enable rsyncd

#6和7.debian support

[[email protected] c7-42 ~]# sed -i 's#@dists="sid";#\#@dists="sid";#gp' /etc/debmirror.conf
[[email protected] c7-42 ~]# sed -i 's#@arches="i386";#\#@arches="i386";#g' /etc/debmirror.conf

#8. default_ password_ crypted                    #注意:这里设置的密码,也就是后面安装完系统的初始化登录密码

[[email protected] c7-42 ~]# openssl passwd -1 -salt `openssl rand -hex 4` '123456'
$1$a9fd9e61$utZcTBQcN.ClUyLsm7RF90
[[email protected] c7-42 ~]# cobbler setting edit --name=default_password_crypted --value='$1$a9fd9e61$utZcTBQcN.ClUyLsm7RF90'

#9. 安装fencing tools

[[email protected] c7-42 ~]# yum -y install fence-agents

解决完成再次查看

[[email protected] c7-42 ~]# systemctl restart cobblerd.service

[[email protected] c7-42 ~]# cobbler sync                      #同步cobbler配置

[[email protected] c7-42 ~]# cobbler check
No configuration problems found.  All systems go.                    #说明已经没有任何问题了

1.2.3 配置DHCP

[[email protected] c7-42 ~]# cobbler setting edit --name=manage_dhcp --value=1

[[email protected] c7-42 ~]# 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地址
     option subnet-mask         255.255.255.0;                             #ip的掩码
     range dynamic-bootp        10.0.0.100 10.0.0.200;                #分配的ip范围

修改完配置文件一定要同步

[[email protected] c7-42 ~]# cobbler sync 

task started: 2020-05-07_161334_sync
task started (id=Sync, time=Thu May  7 16:13:34 2020)
running pre-sync triggers
cleaning trees
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/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 images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
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: 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 ***

这时候创建一个新虚拟机可以获取到如下信息,没有镜像选择,只能从本地启动

Cobbler安装服务器

1.2.4 cobbler命令帮助

命令 说明
cobbler check 核对当前设置是否有问题
cobbler list 列出所有的cobbler元素
cobbler report 列出元素的详细信息
cobbler sync 同步配置到数据目录,更改配置最好都执行一下
cobbler reposync 同步yum仓库
cobbler distro 查看导入的发行版系统信息
cobbler system 查看添加的系统信息
cobbler profile 查看配置信息

1.2.5 cobbler配置安装centos6.x

由于我这里是在系统centos7上面配置的cobbler,所以上传了一个centos6的镜像并进行挂载。

1. 创建挂载点,并进行挂载

[[email protected] c7-42 ~]# ls
anaconda-ks.cfg  CentOS-6.10-x86_64-bin-DVD1.iso

[[email protected] c7-42 ~]# mkdir /centos6

[[email protected] c7-42 ~]# mount -o loop CentOS-6.10-x86_64-bin-DVD1.iso /centos6/

2. 查看挂载后的目录

[[email protected] c7-42 ~]# ls /centos6/

3. 导入镜

[[email protected] c7-42 ~]# cobbler import --path=/centos6 --name=centos6.10 --arch=x86_64

# --path 镜像路径

# --name为安装源定义一个名字

# --arch指定安装源是32位、64位、 ia64, 目前支持的选项有: x86 |x86_ 64|ia64

#安装源的唯标示就是根据name参数来定义 ,本例导入成功后,安装源的唯一标示就是: centos6.10,如果重复,系统会提示导入失败。

4. 查看导入后的镜像

# [[email protected] c7-42 ~]# cobbler distro report --name=centos6.10-x86_64

Cobbler安装服务器

5. copy一份profile文件(ks),进行修改

[[email protected] c7-42 ~]# cd /var/lib/cobbler/kickstarts/

[[email protected] c7-42 kickstarts]# cp sample_end.ks centos6.10.ks

[[email protected] c7-42 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

6. 编辑centos6镜像说使用的kickstart文件

# 动态编辑指定的kickstart文件

[[email protected] c7-42 kickstarts]# cobbler profile edit --name=centos6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.10.ks

# 验证是否更改成功

[[email protected] c7-42 kickstarts]# cobbler profile report --name=centos6.10-x86_64 |grep Kickstart
Kickstart                      : /var/lib/cobbler/kickstarts/centos6.10.ks
Kickstart Metadata             : {}

7. 同步cobbler配置

注意:系统镜像文件centos6.8.ks ,每修改一次都要进行同步。

[[email protected] c7-42 kickstarts]# cobbler sync

8. 测试

Cobbler安装服务器

选择centos6.10-x86_64进行安装,会按照kickstart文件安装并启动

Cobbler安装服务器

Cobbler安装服务器

1.2.6 cobbler Web界面配置

web界面有很多功能,包括上传镜像、编辑kickstart、 等等很多在命令行操作的都可以在web界面直接操作。在上面已经安装了

cobbler-web软件,

访问地址: https://10.0.0.42/cobbler _web 即可

默认账号为:cobbler

密码也为:cobbler

Cobbler安装服务器

Cobbler安装服务器

 

相关文章:

  • 2022-01-20
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2021-05-22
  • 2021-08-23
  • 2021-09-17
猜你喜欢
  • 2022-12-23
  • 2021-11-16
  • 2021-12-31
  • 2021-11-14
  • 2021-04-25
  • 2022-02-16
  • 2021-04-29
相关资源
相似解决方案