cobbler自动化部署

cobbler

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

节点规划

IP主机名节点
192.168.16.10cobblercobbler节点

cobbler部署

1.系统环境配置

  虚拟机网卡采用 NAT 模式,不能使用桥接模式,因为下面的步骤我们会搭建DHCP服务器,在同一个局域网多个DHCP服务会有冲突。VMware的NAT模式的DHCP服务关闭,避免干扰

在这里插入图片描述
  关闭防火墙、selinux服务、修改主机名、配置DNS:

[root@localhost ~]# systemctl stop firewalld && systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

[root@localhost ~]# hostnamectl set-hostname cobbler
[root@localhost ~]# bash
[root@cobbler ~]#
[root@cobbler ~]# echo "nameserver 114.114.114.114" >> /etc/resolv.conf
[root@cobbler ~]# reboot

2.安装cobbler

  配置epel源,安装cobbler及dhcp httpd xinetd cobbler-web,启动cobbler及httpd并加入开机启动并查看查看安装的文件:

[root@cobbler ~]# yum install -y epel-release
[root@cobbler ~]# yum -y install cobbler cobbler-web tftp-server dhcp httpd xinetd
[root@cobbler ~]# systemctl start cobblerd httpd
[root@cobbler ~]# systemctl enable cobblerd httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@linux-node1 ~]# rpm -ql cobbler
/etc/cobbler                  # 配置文件目录
/etc/cobbler/settings         # cobbler主配置文件,这个文件是YAML格式,Cobbler是python写的程序。
/etc/cobbler/dhcp.template    # DHCP服务的配置模板
/etc/cobbler/tftpd.template   # tftp服务的配置模板
/etc/cobbler/rsync.template   # rsync服务的配置模板
/etc/cobbler/iso              # iso模板配置文件目录
/etc/cobbler/pxe              # pxe模板文件目录
/etc/cobbler/power            # 电源的配置文件目录
/etc/cobbler/users.conf       # Web服务授权配置文件
/etc/cobbler/users.digest     # 用于web访问的用户名密码配置文件
/etc/cobbler/dnsmasq.template # DNS服务的配置模板
/etc/cobbler/modules.conf     # Cobbler模块配置文件

/var/lib/cobbler              # Cobbler数据目录
/var/lib/cobbler/config       # 配置文件
/var/lib/cobbler/kickstarts   # 默认存放kickstart文件
/var/lib/cobbler/loaders      # 存放的各种引导程序

/var/www/cobbler              # 系统安装镜像目录
/var/www/cobbler/ks_mirror    # 导入的系统镜像列表
/var/www/cobbler/images       # 导入的系统镜像启动文件
/var/www/cobbler/repo_mirror  # yum源存储目录

/var/log/cobbler              # 日志目录
/var/log/cobbler/install.log  # 客户端系统安装日志
/var/log/cobbler/cobbler.log  # cobbler日志

3.配置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 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : ksvalidator was not found, install pykickstart
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.

  查看结果,解决出现的几个问题,为了防止配置错误,先把配置文件进行备份,在把配置设为可动态配置:

[root@cobbler ~]# cp /etc/cobbler/settings /etc/cobbler/settings.bak
[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

  根据检查出的结果,进行解决问题:

1.server		# Cobbler服务器的IP
[root@cobbler ~]# sed -i 's/server: 127.0.0.1/server: 192.168.16.10/' /etc/cobbler/settings

2.next_server
[root@cobbler ~]# sed -i 's/next_server: 127.0.0.1/next_server: 192.168.16.10/' /etc/cobbler/settings

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

4. cobbler get-loaders
[root@cobbler ~]# cobbler get-loaders

5. rsyncd.service
[root@cobbler ~]# systemctl restart rsyncd
[root@cobbler ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

6. debmirror package
这个是可选项,可以忽略

7. pykickstart
[root@cobbler ~]# yum install -y pykickstart

8. default_password_crypted		#设置新装系统的默认root密码000000。random-phrase-here为干扰码
[root@cobbler ~]# openssl passwd -1 -salt 'qwer' '000000'
$1$qwer$GOwxwyfk7RTYwp2PMTHr50
[root@cobbler ~]# cobbler setting edit --name=default_password_crypted --value='$1$qwer$GOwxwyfk7RTYwp2PMTHr50'

9. fence-agents
[root@cobbler ~]# yum -y install fence-agents

  重启cobbler,再次检查cobbler配置:

[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : 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.

  由此可见,问题解决完成。

4.配置DHCP

  修改cobbler的dhcp模版,不能直接修改dhcp本身的配置文件,因为cobbler会覆盖:

[root@cobbler ~]# cobbler setting edit --name=manage_dhcp --value=1
[root@cobbler ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.16.0 netmask 255.255.255.0 {			#改为分配的网段和掩码
     option routers             192.168.16.10;		#改为网关地址
     option domain-name-servers 114.114.114.114;		#改为DNS地址
     option subnet-mask         255.255.255.0;		#改为分配的IP的掩码
     range dynamic-bootp        192.168.16.11 192.168.16.254;		#改为分配的IP的范围

5.同步cobbler配置

[root@cobbler ~]# cobbler sync
task started: 2021-01-13_231318_sync
task started (id=Sync, time=Wed Jan 13 23:13:18 2021)
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 ***

6.cobbler配置安装centos7.2

6.1 创建挂载点,进行挂载

[root@cobbler ~]# mkdir /centos7.2
[root@cobbler ~]# mount /dev/cdrom /centos7.2/
mount: /dev/sr0 写保护,将以只读方式挂载

6.2 导入镜像

[root@cobbler ~]# cobbler import --path=/centos7.2 --name=centos7.2 --arch=x86_64
task started: 2021-01-13_232740_import
task started (id=Media import, time=Wed Jan 13 23:27:40 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/centos7.2-x86_64:
creating new distro: centos7.2-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7.2-x86_64 -> /var/www/cobbler/links/centos7.2-x86_64
creating new profile: centos7.2-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/centos7.2-x86_64 for centos7.2-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7.2-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7.2-x86_64
looking for /var/www/cobbler/ks_mirror/centos7.2-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7.2-x86_64/repodata
*** TASK COMPLETE ***

6.3 查看导入后镜像信息

[root@cobbler ~]# cobbler distro report --name=centos7.2-x86_64
Name                           : centos7.2-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/centos7.2-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos7.2-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos7.2-x86_64'}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

6.4 查看profile信息

[root@cobbler ~]# cobbler profile report --name=centos7.2-x86_64
Name                           : centos7.2-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : centos7.2-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

6.5 导入ks文件,进行修改

[root@cobbler ~]# cd /var/lib/cobbler/kickstarts/
[root@cobbler kickstarts]# rz -E
rz waiting to receive.
[root@cobbler kickstarts]# cp ks centos7.ks

6.6 编辑centos7镜像所使用的kickstart文件

[root@cobbler kickstarts]# cobbler profile edit --name=centos7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.ks 
[root@cobbler kickstarts]# cobbler profile report --name=centos7.2-x86_64 |grep Kickstart
Kickstart                      : /var/lib/cobbler/kickstarts/centos7.ks
Kickstart Metadata             : {}

6.7 同步cobbler配置

[root@cobbler kickstarts]# cobbler sync
task started: 2021-01-14_001801_sync
task started (id=Sync, time=Thu Jan 14 00:18:01 2021)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos7.2-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/centos7.2-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: centos7.2-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.2-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7.2-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.2-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7.2-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos7.2-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.2-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7.2-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.2-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7.2-x86_64/initrd.img
Writing template files for centos7.2-x86_64
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos7.2-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 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 ***

7.cobbler web管理界面安装centos7.4

  访问cobbler网址,登录的账号密码为cobbler:

	网址:https://IP/cobbler_web

在这里插入图片描述
  点击Kickstart模板,再次点击创建新的Kickstart模板:
在这里插入图片描述
  输入路径和模板,点击保存:
在这里插入图片描述
  上传centos7.5镜像,挂在到/mnt/iso下,并导入到cobbler:

[root@cobbler ~]# mkdir /mnt/iso
[root@cobbler ~]# mount CentOS-7.5-x86_64-DVD-1804.iso /mnt/iso/
mount: /dev/loop0 写保护,将以只读方式挂载
[root@cobbler ~]# cobbler import --arch=x86_64 --path=/mnt/iso --name=CentOS7.5
task started: 2021-01-14_004256_import
task started (id=Media import, time=Thu Jan 14 00:42:56 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/CentOS7.5-x86_64:
creating new distro: CentOS7.5-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS7.5-x86_64 -> /var/www/cobbler/links/CentOS7.5-x86_64
creating new profile: CentOS7.5-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/CentOS7.5-x86_64 for CentOS7.5-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS7.5-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS7.5-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS7.5-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS7.5-x86_64/repodata
*** TASK COMPLETE ***

  点击Profiles,然后点击编辑:
在这里插入图片描述
  然后选择Kickstart,点击保存:
在这里插入图片描述

8.cobbler开机自启动

  上面的相关服务已经做了自启动,我们现在只做自动挂载就可以了:

[root@cobbler ~]# vi /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
mount CentOS-7.5-x86_64-DVD-1804.iso /mnt/iso/
mount /dev/cdrom /centos7.2/

使用cobbler安装系统

  创建一台虚拟机,虚拟网络使用NAT模式,开机:
在这里插入图片描述
  选择一个镜像,进行安装:
在这里插入图片描述
  安装成功:
在这里插入图片描述

参考文献

作者:别来无恙-
出处:https://www.cnblogs.com/yanjieli/p/11016825.html

出处:https://cloud.tencent.com/developer/article/1180830?from=information.detail.Cobbler

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值