Cobbler安装、配置、部署

toc

Cobbler 是一个 PEX 的管理工具,用于自动化网络安装操作系统。
Cobbler 集成了 DNS DHCP 软件包更新,以及配置管理,方便操作系统安装自动化。
Cobbler 支持命令行管理, web界面管理, 同时提供 API 接口便于二次开发。
Cobbler 客户端 Koan 支持虚拟机安装和操作系统重新安装,使重装系统更便捷。

Cobbler服务安装

基础环境准备

## 查看当前系统版本以及内核信息
[root@cobbler-server ~]# hostnamectl
Static hostname: cobbler-cerver
Icon name: computer-vm
Chassis: vm
Machine ID: 6878674c84644fd381a5e3a82d80cf18
Boot ID: 0ec917dac5804f3fa45587a4390fd4fe
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-693.el7.x86_64
Architecture: x86-64
## 关闭 selinux 防火墙
[root@cobbler-server ~]# setenforce 0
[root@cobbler-server ~]# getenforce
Disabled
## 关闭 firewalld 防火墙
[root@cobbler-server ~]# systemctl stop firewalld
[root@cobbler-server ~]# systemctl disable firewalld
## 安装阿里云YUM源(base源和epel源)
[root@cobbler-server ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@cobbler-server ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

阿里云YUM仓库

安装Cobbler和各个组件

yum install cobbler cobbler-web pykickstart httpd dhcp tftp xinetd -y

Cobbler 配置文件概述

## 配置文件目录 /etc/cobbler
/etc/cobbler/settings ## cobbler 主配置文件
/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 模块配置文件
## Cobbler 数据目录 /var/lib/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 日志

启动服务

[root@cobbler-server ~]# systemctl start httpd
[root@cobbler-server ~]# systemctl enable httpd
[root@cobbler-server ~]# systemctl start cobblerd
[root@cobbler-server ~]# systemctl enable cobblerd

执行 Cobbler check 检测,将错误逐一进行解决

[root@cobbler-server ~]# 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.

Cobbler有通过命令配置的动态配置,也可以直接进Cobbler配置文件里面或者通过sed来更改,这里就只写动态配置了。

## 启用cobbler动态配置
[root@cobbler-server ~]# sed -ri '/allow_dynamic_settings:/c \allow_dynamic_settings: 1' /etc/cobbler/settings
[root@cobbler-server ~]# systemctl restart cobblerd
## 配置CobblerServer地址
[root@cobbler-server ~]# cobbler setting edit --name=server --value=192.168.1.1
## 修改next_server主机IP
[root@cobbler-server ~]# cobbler setting edit --name=next_server --value=192.168.1.1
## 配置tftp
[root@cobbler-server ~]# sed -ri '/disable/c\disable = no' /etc/xinetd.d/tftp
[root@cobbler-server ~]# systemctl enable xinetd
[root@cobbler-server ~]# systemctl restart xinetd
## 启动rsync
[root@cobbler-server ~]# systemctl start rsyncd
[root@cobbler-server ~]# systemctl enable rsyncd
## 下载网络安装需要执行的文件
[root@cobbler-server ~]# cobbler get-loaders
## 安装debmirror, 修改/etc/debmirror.conf
[root@cobbler-server ~]# yum install -y debmirror
[root@cobbler-server ~]# sed -ri '/@dists=/c#@dists="sid";' /etc/debmirror.conf
[root@cobbler-server ~]# sed -ri '/@arches=/c#@arches="i386";' /etc/debmirror.conf
## 配置系统登录密码
[root@cobbler-server ~]# openssl passwd -1 -salt 'cobbler' 'cobbler'
[root@cobbler-server ~]# cobbler setting edit --name=default_password_crypted --value='上一个命令的返回值'
## 电源控制模块安装
[root@cobbler-server ~]# yum install -y cman fence-agents
## 开启dhcp地址分配
[root@cobbler-server ~]# cobbler setting edit --name=manage_dhcp --value=1

重启 Cobbler 再用 cobbler check 检测一下

[root@cobbler-server ~]# systemctl restart cobblerd
[root@cobbler-server ~]# systemctl start dhcpd
[root@cobbler-server ~]# systemctl enable dhcpd
[root@cobbler-server ~]# cobbler check
No configuration problems found. All systems go

配置 Cobbler 的 DHCP 模板

## 根据自己的实际情况配置
[root@cobbler-server ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.254;
option domain-name-servers 223.5.5.5;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.1.2 192.168.1.100;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;

重启并同步Cobbler

[root@cobbler-server ~]# systemctl restart xinetd
[root@cobbler-server ~]# systemctl restart cobblerd
[root@cobbler-server ~]# cobbler sync

Cobbler基础安装

Cobbler 导入系统镜像。

## 挂载系统光盘
[root@cobbler-server ~]# mount /dev/cdrom /media/
## 用 import 导入系统镜像
[root@cobbler-server ~]# [root@cobbler-server ~]# cobbler import --path=/media/ --name=centos7.4 --arch=x86_64
## 查看导入的系统
[root@cobbler-server ~]# cobbler distro list
   centos7.4-x86_64

Cobbler 为每个导入的系统提供默认的 Kickstart 配置文件,但许多情况都无法满足运维需求,需要自定义 Kickstart 配置文件

## 移除默认的 profile 配置
[root@cobbler-server ~]# cobbler profile remove --name="centos7.4-x86_64"
## 添加新的 profile 配置 , 并指定 kickstart 应答文件位置
[root@cobbler-server ~]# cobbler profile add --name=centos7.4-web --distro=centos7.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg
## 验证 kickstart 配置文件有效性
[root@cobbler-server ~]# cobbler validateks
## 如果想修改 kickstart 文件位置
[root@cobbler-server ~]# cobbler profile edit --name=centos7.4-web --kickstart=/var/lib/cobbler/kickstarts/centos7_Web.cfg

常用 Kickstart 配置文件
%Pre部分: 安装前解析的脚本,通常用来生成特殊的 ks 配置,比如由一段程序决定磁盘分区等;
%Package部分: 安装包的选择,可以是 @base 这样的组的形式,也可以是这样 http-* 包的形式;
%Post部分: 安装后执行的脚本,通常用来做系统的初始化设置。比如启动的服务,相关的设定等。

Kickstart模板文件

由于 CentOS7 系统网卡名是 eno... ,为了统一标准, 修改为常用 eth0 管理, CentOS6 不需要。

## 使用默认 Kickstart 配置文件修改
[root@cobbler ~]# cobbler profile edit --name=centos7.4-x86_64 --kopts='net.ifnames
=0 biosdevname=0'
## 在 kickstart 配置文件中添加内核参数
bootloader --location=mbr --append="net.ifnames=0 biosdevname=0"

启动被安装服务器, 系统分配 DHCP 后会进入 Cobbler 安装界面, 进行系统选择后, 安装即可。

Cobbler自定义重装

当现有虚拟机运行出现故障或者虚拟机更换其他版本的系统, 需要进行重装操作, 可通过 koan 进行重装系统

## 安装 koan(需要epel的YUM源)
[root@localhost ~]# yum install -y koan
## 客户端列出Cobbler Server端存在的profile
[root@localhost ~]# koan --server=192.168.1.1 --list=profiles
## 选择对应配置即可
[root@localhost ~]# koan --replace-self --server=192.168.1.1 --profile=centos7.4-x86_64
## 重启客户端, 客户端自动进入重装
[root@localhost ~]# reboot

Cobbler自定义安装

实际生产当中要求 Kickstart 指定某台服务器要使用某个具体的 ks 文件,这对于以前来说比较复杂, 但对于 Cobbler 可以通过物理MAC地址来区分。
Cobbler 主要目的配置网络接口, 通过 system 指定服务器 MAC 地址来固定机器的IP、掩码、网关、DNS、主机名等实现基础环境的标准化

虚拟机 VMware Workstation 查看MAC地址的地方

物理服务器就不多介绍了,有相应的资产录入

比如要 MAC:00:0C:29:2B:01:07 配置:
IP地址:192.168.1.50
掩码:255.255.255.0
网关:192.168.1.254
DNS: 192.168.1.254
主机名:zabbix-master

[root@cobbler ~]# cobbler system add --name=zabbix-master --mac=00:0C:29:2B:01:07 \
--profile=Centos-7-web --ip-address=192.168.1.50 --subnet=255.255.255.0 \
--gateway=192.168.1.254 --interface=eth0 --static=1 --hostname=zabbix-master \
--name-servers=192.168.1.254

同步配置信息

[root@cobbler-server ~]# cobbler sync
## 查看配置信息
[root@cobbler-server ~]# cobbler system list
   zabbix-master

启动相应MAC地址的服务器,就会自动安装系统了

为了方便可以写个简单的脚本

#!/bin/bash
read -p "请输入system名称:" Name
read -p "请输入Mac地址:" Mac
clear
echo "请输入下面其中一个"
echo $(/usr/bin/cobbler distro list)
read -p "请输入Profile:" Profile
clear
read -p "请输入网卡接口:" Inter
read -p "请输入IP地址:" Ip
read -p "请输入掩码:" Net
read -p "请输入网关:" Gate
read -p "请输入DNS:" Dns
read -p "请输入主机名:" HostName
echo /usr/bin/cobbler system add --name=$Name --mac=$Mac --profile=$Profile\
--ip-address=$IP --subnet=$Net --gateway=$Gate --interface=$Inter \
--static=1 --hostname=$HostName --name-servers=$Dns
fi

Cobbler自定YUM义仓库

添加YUM仓库

## 添加阿里云YUM仓库
[root@cobbler-server ~]# cobbler repo add --name=openstack-n-centos7 \
--mirror=https://mirrors.aliyun.com/centos/7.4.1708/cloud/x86_64/openstack-newton/
## 添加本地YUM仓库
[root@cobbler-server ~]# cobbler repo add --name=local-ftp-base --mirror=ftp://192.168.1.1/centos7/base/

同步YUM仓库

[root@cobbler-server ~]# cobbler reposync

添加YUM仓库到对应的 profile

## http 协议
[root@cobbler-server ~]# cobbler profile edit --name=centos7.4-x86_64 --repos=openstack-n-centos7
## 本地 ftp
[root@cobbler-server ~]# cobbler profile edit --name=centos7.4-x86_64 --repos=local-ftp-base

/etc/cobbler/settings里面看看 yum_post_install_mirror 的值是不是为1(默认为1,不是就修改成1)
修改 kickstart 文件 ( $yum_config_stanza 添加到 %post %end 中间)

添加定时任务, 定期同步YUM仓库

echo "00 3 * * * /usr/bin/cobbler reposync --tries=3 --no-fail" >> /var/spool/cron/root

Cobbler自定义界面

有时候需要标识企业信息或个人信息,可以通过如下方式进行修改

## 自定义装机页面
[root@cobbler-server ~]# vim /etc/cobbler/pxe/pxedefault.template +3
MENU TITLE Songguoyou | http://www.songguoyou.com
## 同步配置
[root@cobbler-server ~]# cobbler sync

posted on 2019-11-18 16:41  云襄  阅读(532)  评论(0编辑  收藏  举报

导航