浅谈cobbler自动化部署
cobbler 简介
- Cobbler翻译为中文是补鞋匠,在linux方面则一个免费的用于系统安装部署的开源软件,官方地址
http://cobbler.github.io/
, - cobbler是对技术的二次基于python的开发,提供了CLI(命令行)和Web的管理方式,另外还提供了API(应用程序编程接口)接口,方便二次开发使用,
- 相比PXE,cobbler支持多系统同时引导,而PXE只能一次引导一个系统的安装,
- cobbler通常与开源软件puppet、saltstack配合使用,进行操作系统的批量安装与部署优化,从而实现大批量linux系统的无人值守安装与服务部署,大大提升运维的工作效率,
- cobbler工作于服务端,结合DHCP/TFTP/saltstack等服务提供批量系统安装部署,
- cobbler需要结合PXE技术对客户端进行操作系统的安装。
cobbler工作流程
- client裸机配置了从网络启动后,开机后会广播包请求DHCP服务器(cobbler server)发送其分配好的一个IP
- DHCP服务器(cobbler server)收到请求后发送responese,包括其ip地址
- client裸机拿到ip后再向cobbler server发送请求OS引导文件的请求
- cobbler server告诉裸机OS引导文件的名字和TFTP server的ip和port
- client裸机通过上面告知的TFTP server地址通信,下载引导文件
- client裸机执行执行该引导文件,确定加载信息,选择要安装的os,期间会再向cobbler server请求kickstart文件和os image
- cobbler server发送请求的kickstart和os iamge
- client裸机加载kickstart文件
- client裸机接收os image,安装该os image
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 : 模块的配置文件
cobbler 目录介绍
数据目录
- /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日志
cobbler 命令介绍
- cobbler commands介绍
- cobbler check 核对当前设置是否有问题
- cobbler list 列出所有的cobbler元素
- cobbler report 列出元素的详细信息
- cobbler sync 同步配置到数据目录,更改配置最好都要执行下
- cobbler reposync 同步yum仓库
- cobbler distro 查看导入的发行版系统信息
- cobbler system 查看添加的系统信息
- cobbler profile 查看配置信息
cobbler 重要的参数
/etc/cobbler/settings中重要的参数设置
- default_password_crypted: “ 1 1 1gEc7ilpP$pg5iSOj/mlxTxEslhRvyp/”
- manage_dhcp:1 //自动配置dhcp文件
- manage_tftpd:1
- pxe_just_once:1
- next_server:< tftp服务器的 IP 地址>
- server:<cobbler服务器的 IP 地址>
cobbler 环境检查
执行Cobbler check命令会报如下异常
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 : 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.
4 : change ‘disable’ to ‘no’ in /etc/xinetd.d/rsync
5 : comment ‘dists’ on /etc/debmirror.conf for proper debian support
6 : comment ‘arches’ on /etc/debmirror.conf for proper debian support
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 the
cobbler 报错解决
执行Cobbler check报错解决方式
- 修改
/etc/cobbler/settings
文件中的server
参数的值为提供cobbler服务的主机相应的IP地址或主机名 - 修改
/etc/cobbler/settings
文件中的next_server
参数的值为提供PXE服务的主机相应的IP地址 - 如果当前节点可以访问互联网,执行“
cobbler get-loaders
”命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}
等文件至/var/lib/cobbler/loaders/
目录中 - 修改
/etc/cobbler/settings
文件,manage_dhcp: 1
,并修改下面文件/etc/cobbler/dhcp.template
- 执行“
openssl passwd -1
生成密码,并用其替换/etc/cobbler/settings
文件中default_password_crypted
参数的值
cobbler 相关管理
- 下载启动菜单:
- 联网:
cobbler get-loaders
- 不联网:
cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot
- 联网:
- 管理distro
cobbler import --name=centos-7.5-x86_64 --path=/media/cdrom --arch=x86_64
- 管理profile
cobbler profile add --name=centos-7.5 --distro=centos-7.5-x86_64--kickstart= /var/lib/cobbler/kickstarts/centos7_x86_64.cfg
- 查看profiles
cobbler profile list
- 查看引导文件
cat /var/lib/tftpboot/pxelinux.cfg/default
- 同步cobbler配置
cobbler sync
- 多系统引导方案
cobbler import --name=CentOS-7-x86_64 --path=/media/cdrom
cobbler distro list
cobbler profile list
cobbler sync
cobbler 实现步骤
- 安装包,并设置服务
- 检查配置
- 根据上面提示修改配置
- 下载启动相关文件菜单
- 配置DHCP服务
- 分别导入centos的安装源,并查看
- 准备kickstart文件并导入cobbler
- 测试
cobbler的web管理实现
- cobbler-web
提供cobbler的基于web管理界面,epel源yum install cobbler-web
- 认证方式
- 认证方法配置文件:
/etc/cobbler/modules.conf
- 支持多种认证方法:
authn_configfile
authn_pam
- 认证方法配置文件:
使用authn_configfile
模块认证cobbler_web
用户
vim /etc/cobbler/modules.conf
[authentication]
module=authn_configfile
- 创建其认证文件
/etc/cobbler/users.digest
,并添加所需的用户htdigest -c /etc/cobbler/users.digest Cobbler admin
注意:添加第一个用户时,使用“-c”选项,后续添加其他用户时不要再使用, - cobbler_web的
realm
只能为Cobbler
使用authn_pam模块认证cobbler_web用户
vim /etc/cobbler/modules.conf
[authentication]
module = authn_pam
-
创建cobbler用户:useradd cobbler
vim /etc/cobbler/users.conf
[admins]
admin = "cobbler“
-
Web访问cobbler
-
重启cobblerd服务
-
通过https://cobblerserver/cobbler_web访问
-
用户:useradd cobbler
vim /etc/cobbler/users.conf
[admins]
admin = "cobbler“
-
Web访问cobbler
-
重启cobblerd服务
-
通过https://cobblerserver/cobbler_web访问
完