Cobbler安装部署CentOS7.4

1.Cobbler简介

  • Cobbler 是一个快速网络安装 Linux 的服务,而且经过调整也可以支持网络安装 Windows。
  • 该工具使用 Python 开发,小巧轻便(才 15 k 行 Python 代码),使用简单的命令即可完成PXE网络安装环境的配置, 同时还可以管理 DHCP、DNS、TFTP、RSYNC 以及 YUM 仓库、构造系统 ISO 镜像。
  • Cobbler 支持命令行管理,Web 界面管理,还提供了 API 接口,可以方便二次开发使用。 Cobbler 客户端 koan 支持虚拟机安装和操作系统重新安装,使重装系统更便捷。

2.Cobbler功能

  • 使用 Cobbler,您无需进行人工干预即可安装机器。Cobbler 设置一个 PXE 引导环境(它还可使用 yaboot 支持 PowerPC),并控制与安装相关的所有方面,比如网络引导服务(DHCP 和 TFTP)与存储库镜像。当希望安装一台新机器时,Cobbler 可以:
1. 使用一个以前定义的模板来配置 DHCP 服务(如果启用了管理 DHCP)
2. 将一个存储库(yum 或 rsync)建立镜像或解压缩一个媒介,以注册一个新操作系统
3. 在 DHCP 配置文件中为需要安装的机器创建一个条目,并使用您指定的参数(IP 和 MAC 地址)
4. 在 TFTP 服务目录下创建适当的 PXE 文件
5. 重新启动 DHCP 服务以反映更改
6. 重新启动机器以开始安装(如果电源管理已启用)
  • Cobbler 支持众多的发行版:Red Hat、Fedora、CentOS、Debian、Ubuntu 和 SuSE。当添加一个操作系统(通常通过使用 ISO 文件)时,Cobbler 知道如何解压缩合适的文件并调整网络服务,以正确引导机器。
  • Cobbler 可使用 kickstart 模板。基于 Red Hat 或 Fedora 的系统使用 kickstart 文件来自动化安装流程。
  • 通过使用模板,您就会拥有基本的 kickstart 模板,然后定义如何针对一种配置文件或机器配置而替换其中的变量。
  • 例如,一个模板可能包含两个变量 $domain 和 $machine_name。在 Cobbler 配置中,一个配置文件指定 domain=mydomain.com,并且每台使用该配置文件的机器在 machine_name 变量中指定其名称。该配置文件中的所有机器都使用相同的 kickstart 安装且针对 domain=mydomain.com
    进行配置,但每台机器拥有其自己的机器名称。您仍然可以使用 kickstart 模板在不同的域中安装其他机器并使用不同的机器名称。
  • 为了协助管理系统,Cobbler 可通过 fence scripts 连接到各种电源管理环境。
  • Cobbler 支持 apc_snmp、bladecenter、bullpap、drac、ether_wake、ilo、integrity、ipmilan、ipmitool、lpar、rsa、virsh 和 wti。
  • 要重新安装一台机器,可运行 reboot system foo 命令,而且 Cobbler 会使用必要的凭据和信息来为您运行恰当的 fence scripts(比如机器插槽数)。
  • 除了这些特性,还可使用一个配置管理系统 (CMS)。您有两种选择:该工具内的一个内部系统,或者集成一个现有的外部 CMS,比如 Chef 或 Puppet。
  • 借助内部系统,您可以指定文件模板,这些模板会依据配置参数进行处理(与 kickstart 模板的处理方式一样),然后复制到您指定的位置。
  • 如果必须自动将配置文件部署到特定机器,那么此功能很有用。
  • 使用 koan 客户端,Cobbler 可从客户端配置虚拟机并重新安装系统。

3.基础环境准备

[root@cobbler ~]# cat /etc/redhat-release 		# 查看系统版本
CentOS Linux release 7.4.1708 (Core) 
[root@cobbler ~]# uname -r							#  查看内核版本
3.10.0-693.el7.x86_64
[root@cobbler ~]# getenforce 						# 确认SELinux关闭
Disabled
[root@cobbler ~]# systemctl status firewalld	# 确认防火墙关闭
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@cobbler ~]# ip a | grep ens32				# 查看IP地址
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.120.20/24 brd 192.168.120.255 scope global ens32
[root@cobbler ~]# hostname							# 查看主机名
cobbler
[root@cobbler ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo	# 安装 epel 源(因为 Cobbler 软件包在此源中)
--2019-04-03 03:52:37--  http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 61.163.8.210, 61.163.8.209, 61.163.8.211, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|61.163.8.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’

100%[=======================================================================================================================================================================>] 664         --.-K/s   in 0s      

2019-04-03 03:52:37 (43.0 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664]

注意:
1. 虚拟机网卡采用 NAT 模式并关闭,不要使用桥接模式,因为我们会搭建 DHCP 服务器,在同一局域网多个 DHCP 服务会有冲突,并且导致实践失败。
2. VMware 的 NAT 模式的 DHCP 服务也关闭,避免干扰。

在这里插入图片描述

4.Cobbler安装配置

4.1 安装Cobbler及相关软件包

[root@cobbler ~]# yum install dhcp tftp-server xinetd httpd cobbler cobbler-web pykickstart -y
[root@cobbler ~]# rpm -qa | grep -E "dhcp|tftp-server|xinetd|httpd|cobbler|cobbler-web|pykickstart"
httpd-2.4.6-88.el7.centos.x86_64			# Apache httpd服务
dhcp-4.2.5-68.el7.centos.1.x86_64			# dhcp服务
dhcp-common-4.2.5-68.el7.centos.1.x86_64
tftp-server-5.2-22.el7.x86_64				# tftp服务
httpd-tools-2.4.6-88.el7.centos.x86_64
cobbler-2.8.4-4.el7.x86_64					# Cobbler程序包
xinetd-2.3.15-13.el7.x86_64
dhcp-libs-4.2.5-68.el7.centos.1.x86_64
cobbler-web-2.8.4-4.el7.noarch				# Cobbler的web程序包
pykickstart-1.99.66.19-2.el7.noarch			# Cobbler检查kickstart语法错误

[root@cobbler ~]# 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 日志

4.2 配置Cobbler

  • Cobbler 的运行依赖于 DHCP、TFTP、RSYNC 及 DNS 服务,其中 :
  • DHCP 可由 dhcpd(ISC)提供,也可由 dnsmasq 提供;
  • TFTP 可由 tftp-server 程序包提供,也可由 Cobbler 功能提供;
  • rsync 由 rsync 程序包提供;
  • DNS 可由 bind 提供,也可由 dnsmasq 提供。
  • Cobbler可自行管理这些服务中的部分甚至是全部,但需要配置文件 /etc/cobbler/settings 中的“manange_dhcp”、“manager_tftpd”、“manager_rsync”、“manager_dns”分别来进行定义, 另外,由于各种服务都有着不同的实现方式,如若需要进行自定义,需要通过修改/etc/cobbler/modules.conf 配置文件中各服务的模块参数的值来实现。
[root@cobbler ~]# systemctl start httpd				# 启动http服务
[root@cobbler ~]# systemctl enable httpd			# 设置开机启动
[root@cobbler ~]# systemctl is-enabled httpd		# 查看是否设置开机启动
[root@cobbler ~]# systemctl start cobblerd			# 启动cobbler
[root@cobbler ~]# systemctl enable cobblerd			# 设置开机启动
[root@cobbler ~]# systemctl is-enabled cobblerd		# 查看是否开机启动
[root@cobbler ~]# systemctl status httpd cobblerd	# 查看http和cobbler的服务状态

# 检查配置文件,需要在 cobblerd 和 httpd 启动的情况下检查

[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 : 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
8 : 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.

# 如上各问题解决方法如下:
# 第 1、2、7 个问题,顺便修改其他功能
[root@cobbler ~]# cp /etc/cobbler/settings{,.ori}		# 备份

# 修改 /etc/cobbler/settings 文件中的 server 参数的值为提供 cobbler 服务的主机相应的 IP 地址或主机名
[root@cobbler ~]# sed -i "s#server: 127.0.0.1#server: 192.168.120.20#" /etc/cobbler/settings
[root@cobbler ~]# grep "^server: " /etc/cobbler/settings
server: 192.168.120.20

# 修改 /etc/cobbler/settings 文件中的 next_server 参数的值为提供 PXE 服务的主机相应的 IP 地址
[root@cobbler ~]# sed -i "s#next_server: 127.0.0.1#next_server: 192.168.120.20#" /etc/cobbler/settings
[root@cobbler ~]# grep "^next_server: " /etc/cobbler/settings
next_server: 192.168.120.20

# 防止循环装系统,适用于服务器第一启动项是 PXE 启动
[root@cobbler ~]# sed -i "s#pxe_just_once: 0#pxe_just_once: 1#" /etc/cobbler/settings
[root@cobbler ~]# grep "^pxe_just_once: " /etc/cobbler/settings
pxe_just_once: 1

# 设置新装系统的默认 root 密码 cobbler
[root@cobbler ~]# openssl passwd -1 -salt 'cobbler' 'cobbler'
$1$cobbler$M6SE55xZodWc9.vAKLJs6.

# 修改 /etc/cobbler/settings 文件中的 default_password_crypted 参数的值为上面生成的密码串
[root@cobbler ~]# vim /etc/cobbler/settings

# 第 3 个问题,修改 /etc/xinetd.d/tftp 文件中的 disable 参数修改为 disable = no
[root@cobbler ~]# sed -i "/disable/ {s#yes#no#}" /etc/xinetd.d/tftp
[root@cobbler ~]# grep "disable" /etc/xinetd.d/tftp 
	disable			= no

# 第 4 个问题,执行 cobbler get-loaders 命令即可,会自动从官网下载
[root@cobbler ~]# cobbler get-loaders

# 第 5 个问题,配置 rsyncd 开机启动,启动 rsyncd
[root@cobbler ~]# systemctl start rsyncd
[root@cobbler ~]# systemctl status rsyncd
[root@cobbler ~]# systemctl enable rsyncd
[root@cobbler ~]# systemctl is-enabled rsyncd
[root@cobbler ~]# systemctl start xinetd
[root@cobbler ~]# systemctl status xinetd
[root@cobbler ~]# systemctl enable xinetd
[root@cobbler ~]# systemctl is-enabled xinetd

# 第 6 个问题,和 Debian 系统相关,不需要
# 第 8 个问题,fence设备相关,暂不需要

# 上面相关问题配置完后,重启 Cobbler,并再次执行 cobbler check 检查确认(如下算解决了相关问题)
[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
2 : 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.3 配置DHCP

# 配置使用 Cobbler 管理 DHCP
[root@cobbler ~]# sed -i "s#manage_dhcp: 0#manage_dhcp: 1#" /etc/cobbler/settings
[root@cobbler ~]# grep "^manage_dhcp: " /etc/cobbler/settings
manage_dhcp: 1

# 修改 Cobbler 的 DHCP 模版,不要直接修改 DHCP 本身的配置文件,因为 Cobbler 会覆盖
[root@cobbler ~]# cp /etc/cobbler/dhcp.template{,.ori}	# 备份
[root@cobbler ~]# vim /etc/cobbler/dhcp.template		# 列出修改过的相关字段
subnet 192.168.120.0 netmask 255.255.255.0 {
     option routers             192.168.120.2;
     option domain-name-servers 192.168.120.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.120.21 192.168.120.25;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

4.4 同步Cobbler配置

# 同步最新 Cobbler 配置,它会根据配置自动修改 DHCP 等服务
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# cobbler sync
task started: 2019-04-03_090507_sync
task started (id=Sync, time=Wed Apr  3 09:05:07 2019)
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 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 ***

[root@cobbler ~]# head -7 /etc/dhcp/dhcpd.conf 		# 再看一下 DHCP 的配置文件
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Wed Apr  3 01:05:08 2019)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# ******************************************************************

4.5 配置开机启动

[root@cobbler ~]# systemctl enable dhcpd xinetd httpd cobblerd
[root@cobbler ~]# systemctl is-enabled dhcpd xinetd httpd cobblerd
enabled
enabled
enabled
enabled

5.Cobbler命令行管理

5.1 查看命令行帮助

[root@cobbler ~]# cobbler
usage
=====
cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... 
        [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]
[root@cobbler ~]# cobbler import --help			# 导入镜像帮助
Usage: cobbler import [options]

Options:
  -h, --help            show this help message and exit
  --arch=ARCH           OS architecture being imported
  --breed=BREED         the breed being imported
  --os-version=OS_VERSION
                        the version being imported
  --path=PATH           local path or rsync location
  --name=NAME           name, ex 'RHEL-5'
  --available-as=AVAILABLE_AS
                        tree is here, don't mirror
  --kickstart=KICKSTART_FILE
                        assign this kickstart file
  --rsync-flags=RSYNC_FLAGS
                        pass additional flags to rsync

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

5.2 管理distro

  • Cobbler 变得可用的第一步为定义 distro,其可以通过为其指定外部的安装引导内核及 ramdisk 文件的方式实现。
  • 如果已经有完成的安装树(如 OS 的安装镜像)则推荐使用 improt 导入的方式进行。
  • 导入镜像
[root@cobbler ~]# mount /dev/cdrom /mnt		# 挂载 CentOS 7 的系统镜像
mount: /dev/sr0 is write-protected, mounting read-only
[root@cobbler ~]# cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64
# --path 镜像路径
# --name 为安装源定义一个名字
# --arch 指定安装源是 32 位、64 位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据 name 参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7-x86_64,如果重复,系统会提示导入失败
[root@cobbler ~]# cobbler distro list		# 查看镜像列表
   CentOS-7-x86_64
# 镜像存放目录,Cobbler 会将镜像中的所有安装文件拷贝到本地一份,放在 /var/www/cobbler/ks_mirror 下的 CentOS-7-x86_64目录下。
# 因此 /var/www/cobbler 目录必须具有足够容纳安装文件的空间。
[root@cobbler ~]# ll /var/www/cobbler/ks_mirror/
total 0
drwxr-xr-x 8 root root 254 Sep  6  2017 CentOS-7-x86_64
drwxr-xr-x 2 root root  34 Apr  3 09:34 config
[root@cobbler ~]# cobbler profile list		# 导入 distro 会自动生成 profile
   CentOS-7-x86_64

  • 如果有 kickstart 文件,也可以使用–kickstart=/path/to/kickstart_file 进行导入,import 会自动为导入的 distro 生成一个 profile
# 查看安装镜像文件信息
[root@cobbler ~]# cobbler distro report --name=CentOS-7-x86_64
Name                           : CentOS-7-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7-x86_64'}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

5.3 管理profile

  • Cobbler使用 profile 来为特定的需求类别提供所需要安装的配置,即在 distro 的基础上通过提供 kiskstart 文件来生成一个特定的系统安装配置。 distro 的 profile 可以出现在 PXE 的引导菜单中作为安装的选择之一
# 查看所有的 profile 设置
[root@cobbler ~]# cobbler profile report
# 查看指定的 profile 设置
[root@cobbler ~]# cobbler profile report --name=CentOS-7-x86_64
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

# Cobbler 的 ks.cfg 文件存放位置
[root@cobbler ~]# ls /var/lib/cobbler/kickstarts/
default.ks    esxi5-ks.cfg      legacy.ks     sample_autoyast.xml  sample_esx4.ks   sample_esxi5.ks  sample.ks        sample.seed
esxi4-ks.cfg  install_profiles  pxerescue.ks  sample_end.ks        sample_esxi4.ks  sample_esxi6.ks  sample_old.seed
# 在第一次导入系统镜像后,Cobbler 会给镜像指定一个默认的 kickstart 自动安装文件在 /var/lib/cobbler/kickstarts 下的 sample_end.ks

[root@cobbler ~]# cd /var/lib/cobbler/kickstarts/
[root@cobbler kickstarts]# rz		# 上传准备好的 ks 文件

# 编辑 profile,修改关联的 ks 文件
[root@cobbler kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks.cfg

# 修改安装系统的内核参数,在 CentOS 7 系统有一个地方变了,就是网卡名变成 eno16777736 这种形式,但是为了运维标准化,
# 我们需要将它变成我们常用的 eth0,因此使用下面的参数。但要注意是 CentOS 7 才需要下面的步骤,CentOS 6 不需要。
[root@cobbler kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
[root@cobbler kickstarts]# cobbler profile report CentOS-7-x86_64
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/ks.cfg
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@cobbler kickstarts]# cobbler sync

5.4 管理repo

# 新部署机器安装 yum 源,并同步。这里使用内网 yum 源,也可以使用阿里源
# 1. 添加 repo
[root@cobbler kickstarts]# cobbler repo add --name=centos-7.4-base --mirror=http://192.168.120.20/CentOS7/ --arch=x86_64 --breed=yum
# 2. 同步repo
[root@cobbler kickstarts]# cobbler reposync
# 3. 添加 repo 到对应的 profile
[root@cobbler kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --repo="centos-7.4-base"
# 4. 修改 kickstart文件。
url --url="http://192.168.120.20/cobbler/ks_mirror/CentOS-7-x86_64/"
添加 $yum_config_stanza 到 %post %end 中间,如下:
%post
$yum_config_stanza
%end
# 5. 添加定时任务,定期同步 repo
echo "0 3 * * * /usr/bin/cobbler reposync --tries=3 --no-fail" >> /var/spool/cron/root

6.安装系统

6.1 安装新系统

猜你喜欢

转载自blog.csdn.net/Happy_Sunshine_Boy/article/details/88979011