Cobbler

1、Cobbler是一个linux安装服务器,他能实现网络安装环境下的快速安装 基于Python开发的

2、适用于大规模安装linux操作系统,不同版本的操作系统,同一版本又不同的配置 Cobber基于DHCP、PXE、TFTP、HTTP、Kickstart的技术,来提供统一的对外服务,另外还有Cobbler Web界面,不过Cobbler CLI已经满足大部分人需求,本节Cobbler Web不做研究,下节有个简单的Web实际用法。

3、另外Cobbler还可以作为一个本地yum仓库,利用reposync

Cobbler工作机制

  1. client客户端配置了从网络启动后,开机会广播请求DHCP服务器(cobbler server)发送其分配好的一个IP
  2. DHCP服务器接收到请求后发送responese,包括其IP地址
  3. clinet裸机拿到ip后,再向cobbler server 发送请求,OS引导文件的请求
  4. cobbler server 返回给客户端OS引导文件的名字和TFTP服务器的ip和port
  5. 客户端通过cobbler返回的信息,通过地址找到TFTP服务器,下载引导文件
  6. 客户端通过该引导文件,确定加载信息,选择要安装的系统,期间会再向cobbler server请求应答文件
  7. 客户端加载应答文件,通过应答文件的配置来完成相关操作

Cobbler 服务集成

PXE服务支持 rsync服务 DHCP服务管理 DNS服务管理(可选bind,dnsmasq) IPMI电源管理 Kickstart服务支持 YUM仓库管理 TFTP(PXE启动时需要) HTTPD(提供kickstart的安装源,并提供定制化的kickstart配置)

Cobbler 配置目录说明

配置文件目录:/etc/cobbler

/etc/cobbler/settings : cobbler 主配置文件 /etc/cobbler/iso/: iso模板配置文件 /etc/cobbler/pxe: pxe模板文件 /etc/cobbler/power: 电源配置文件 /etc/cobbler/user.conf: web服务授权配置文件 /etc/cobbler/users.digest: web访问的用户名密码配置文件 /etc/cobbler/dhcp.template : dhcp服务器的的配置末班 /etc/cobbler/dnsmasq.template : dns服务器的配置模板 /etc/cobbler/tftpd.template : tftp服务的配置模板 /etc/cobbler/modules.conf : 模块的配置文件

数据目录:

/var/lib/cobbler/config/: 用于存放distros,system,profiles 等信 息配置文件 /var/lib/cobbler/triggers/: 用于存放用户定义的cobbler命令 /var/lib/cobbler/kickstart/: 默认存放kickstart文件 /var/lib/cobbler/loaders/: 存放各种引导程序  镜像目录 /var/www/cobbler/ks_mirror/: 导入的发行版系统的所有数据 /var/www/cobbler/images/ : 导入发行版的kernel和initrd镜像用于 远程网络启动 /var/www/cobbler/repo_mirror/: yum 仓库存储目录

日志目录:

/var/log/cobbler/installing: 客户端安装日志 /var/log/cobbler/cobbler.log : cobbler日志

Cobber 命令

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

实验:Cobbler 自动化部署系统

主机信息

服务器:centos7 网卡: 仅主机,192.168.146.10 桥接: dhcp 安装服务:cobbler dhcp tftp-server pykickstart httpd

准备工作

systemctl disable firewalld       centos7开机不自启防火墙
systemctl stop firewalld          centos7停止防火墙
service iptables stop             centos6关闭iptables
service iptables enable           centos6开机不自启iptables
sed -i "s/SELINUX=SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config  修改selinux配置文件
reboot   					重启生效
关闭虚拟机VM本地dhcp服务,防止和我们安装的dhcp发生冲突
yum install cobbler dhcp tftp-server pykickstart httpd -y 安装本实验需要的软件包

安装Cobbler

yum install cobbler -y
systemctl start cobbler
systemctl enable cobbler

修改配置文件

cobbler check 检查cobbler配置文件 当我们执行这条命令后,通常会报以下8条错误,我们一条条修改即可

会出现如下错误:

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.

384    # of the manpage for how that works 
server  192.168.146.10`` 

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.

272   # if you do not set this correctly, this will be manifested in TFTP open timeouts. 
next_server 192.168.146.10

3 : change 'disable' to 'no' in /etc/xinetd.d/tftp

vim /etc/xinetd.d/tftp
disable		=disable改为no 

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.

如果当前节点可以访问互联网,执行“cobbler get-loaders”命令即可;
cobbler get-loaders    下载bootloader 加载程序
否则,需要安装syslinux程序包,而后复制
/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至
/var/lib/cobbler/loaders/目录中 

5 : enable and start rsyncd.service with systemctl

systemctl enable rsyncd
systemctl start rsyncd

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

--这个配置文件在101行 
-- openssl passwd -1
#and put the output between the "" below.
必须要修改这个文件,cobbler check 会报错
default_password_crypted: "$1$3pHPXQL8$VxaAapUajtxI0X610meBl/"

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.

修改完以上6个配置后,可执行 cobbler sync 命令

配置cobbler-DHCP

修改cobbler配置

vim /etc/cobbler/settings 将dhcp服务由cobbler托管

仅修改以下配置文件

导入安装源文件

首先挂载光盘

mount /dev/sr0 /mnt/centos7/		挂载CentOS7镜像文件
mount /dev/sr1 /mnt/centos6/		挂载CentOS6镜像文件

导入光盘

cobbler import --name=CentOS6.10 --path=/mnt/centos6 --arch=x86_64
cobbler import --name=CentOS7.6  --path=/mnt/centos7 --arch=x86_64
	--name	为安装源定义一个名字
	--path	镜像文件路径
	--arch	安装源的架构

centos7

cneots6

安装源的唯一标识就是name参数定义的,以上面为例。导入后唯一标识就是

生成kickstart文件

制作kickstart

基于epel源,安装system-config-kickstart程序包

	yum install system-config-kickstart  

基于图形化界面来制作kickstart文件

也可以参考当前主机上的应答模板文件 /root/anaconda-ks.cfg 制作完kickstart文件后,建议检查一下语法错误

	cobbler validateks

修改kickstart

将原来的配置修改文 url --url="$tree"

导入kickstart文件

将制作好的kickstart文件导入到/var/lib/cobbler/kickstarts/(默认存放kickstart文件) 目录下

cp /data/ks7_mini.cfg /var/lib/cobbler/kickstart/
cp /data/ks6_mini.cfg /var/lib/cobbler/kickstart/
将ks文件和系统关联,生成启动菜单
cobbler profile edit --name Centos7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_mini.cfg
cobbler profile edit --name Centos6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks6_mini.cfg
我们还可以修改CentOS7的默认网卡名称
cobbler profile edit --name Centos7.6-x86_64 --kopts='net.ifnames=0 biosdevname=0' 

同步cobbler cobbler sync

结尾工作

systemctl restart httpd
systemctl restart dhcpd
systemctl restart tftp
systemctl restart cobblerd
systemctl restart xinetd.service


如有错误或不清晰的地方,请各位指正。