Cobbler详解

简介:

一、Cobbler简介

二、Cobbler架构

三、配置Cobbler所依赖的服务

四、配置cobbler

五、Cobbler-Web

六、Cobbler其他内容


一、Cobbler简介

PXE:preboot execute environment, Intel

dhcp: udp 67(server),68(client) //dhcpd,dhcp-relay(中继),dnsmasq

tftp: 69/udp 

pxe: dhcp,tftp,yum repo

cobbler: Python

distro(repository)-->profile(kickstart)--->system(ip/mask)

Cobbler 是一个系统启动服务(boot server),可以通过网络启动(PXE)的方式用来快速安装、重装物理服务器和虚拟机,支持安装不同的 Linux 发行版和 Windows。该工具使用python开发,小巧轻便(才15k行代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP,DNS,以及yum包镜像。

   Cobbler 使用命令行方式管理,也提供了基于 Web 的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。

即多安装树的pxe环境,是pxe的高级封装

Cobbler依赖:dhcp、tftp、rsync及dns

特性:

1、PXE服务支持

2、DHCP服务管理

3、DNS服务管理(可选bind,dnsmasq) //dnsmasq同时提供dns和dhcp,轻量化。

4、电源管理

5、Kickstart服务支持

6、yum仓库管理

7、TFTP (PXE启动时需要)

8、Apache(提供kickstart 的安装源,并提供定制化的kickstart配置)

同时,它和apache做了深度整合。通过 cobbler,可以实现对RedHat/Centos/Fedora系统的快速部署,同时也支持Suse 和Debian(Ubuntu)系统,通过配置也支持windows。

提供web界面


二、Cobbler架构

1.架构图

【CentOS repo】//distro

||

--------------------------------------

【profile】【profile】 【..】

------------

||

【os】 【os】

Cobbler各组件关系图:

2.png

profile是根据distro结合ks制定的预安装环境

每一个distro下可以对应多个不同的profile //

同一个iso-->同一个ks--->对应多个ip安装os

生成distro:本地做一个仓库创建,或者import也可以


Profile是核心:有由以下三个组件组成:

1.repositories(安装源)

mirror:镜像,指向网络中的安装源

import:导入

2.distribution(vmlinuz(内核)+initrd.img(引导映像文件)

3.kickstart file组成的完整的系统发行版

2.Cobbler工作流程

如图一:

1.png

Server端:

第一步,启动Cobbler服务

第二步,进行Cobbler错误检查,执行cobbler check命令

第三步,进行配置同步,执行cobbler sync命令

第四步,复制相关启动文件文件到TFTP目录中

第五步,启动DHCP服务,提供地址分配

第六步,DHCP服务分配IP地址

第七步,TFTP传输启动文件

第八步,Server端接收安装信息

第九步,Server端发送ISO镜像与Kickstart文件

Client端:

第一步,客户端以PXE模式启动

第二步,客户端获取IP地址

第三步,通过TFTP服务器获取启动文件

第四步,进入Cobbler安装选择界面

第五步,客户端确定加载信息

第六步,根据配置信息准备安装系统

第七步,加载Kickstart文件

第八步,传输系统安装的其它文件

第九步,进行安装系统

3.cobbler check问题(Centos7)

[root@node112 html]# cobbler check

1
2
3
4
5
6
7
8
9
10
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.

1
2
3
1 : 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.
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : fencing tools were not found, and are required to use the (optional) power management features.  install  cman or fence-agents to use them

//第二个是debian包管理的。第三个是电源管理的。可以忽略


1
2
3
4
5
6
7
1、修改 /etc/cobbler/settings 文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名,如172.16.100.15;
2、修改 /etc/cobbler/settings 文件中的next_server参数的值为提供PXE服务的主机相应的IP地址,如172.16.100.16;
3、如果当前节点可以访问互联网,执行“cobbler get-loaders”命令即可;否则,需要安装syslinux程序包,而后复制 /usr/share/syslinux/ {pxelinux.0,memu.c32}等文件至 /var/lib/cobbler/loaders/ 目录中;
4、执行“chkconfig  rsync  on”命令即可;
5、注释 /etc/debmirror .conf文件中的“@dists= "sid" ;”一行;
6、注释 /etc/debmirror .conf文件中的“@arches= "i386" ;”一行;
7、执行“openssl  passwd  -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换 /etc/cobbler/settings 文件中default_password_crypted参数的值;

[root@node112 html]# useradd cobbler_user ; echo cobbler_user | passwd --stdin cobbler_user

[root@node112 html]# tail -1 /etc/shadow

$6$bqumiXob$da8/DH.oIE1ggz.jW.gA/fpo2kFkDqcIqNBt5w6M3FrSKAkj9349/rygac6fVst.KRTiAWpEUQJFQKu7zB/bp.  //注意:为分隔符

[root@node112 html]# vim /etc/cobbler/settings

default_password_crypted: "$6$bqumiXob$da8/DH.oIE1ggz.jW.gA/fpo2kFkDqcIqNBt5w6M3FrSKAkj9349/rygac6fVst.KRTiAWpEUQJFQKu7zB/bp."

8、执行“yum install cman fence-agents”命令安装相应的程序包即可;

三、配置Cobbler所依赖的服务

cobbler的运行依赖于dhcp、tftp、rsync、dns、httpd、xinetd服务。

cobbler可自行管理这些服务中的部分甚至是全部,但需要配置/etc/cobbler/settings文件中的“manage_dhcp”、“manage_tftpd”、“manage_rsync”和“manage_dns”分别进行定义。另外,由于每种服务都有着不同的实现方式,如若需要进行自定义,需要通过修改/etc/cobbler/modules.conf配置文件中各服务的模块参数的值来实现。

/etc/cobbler/settings

manage_dhcp:0 //不使用dhcp管理

1.配置dchp

==============================================

1
2
3
4
5
6
7
8
9
default-lease- time  43200;
max-lease- time  86400;
log-facility local7;
subnet 172.16.0.0 netmask 255.255.0.0 {
     range 172.16.100.121 172.16.100200;
     option routers 172.16.100.7;
}
next-server 172.16.100.7;
filename= "pxelinux.0" ;

接着使用“service dhcpd start”启动服务即可。


2.配置tftp

==============================================

# chkconfig tftp on

# service xinetd restart

[root@node112 ~]# cobbler

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@node112 ~]# 


distro:主要用来定义某个发行版特有的或者特用的ramdisk和kernel的,distro本身并不是repository

标记一个发行版,关键的是kernel+initrd 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@node112 ~] # cobbler  distro -h
usage
=====
cobbler distro add
cobbler distro copy
cobbler distro edit
cobbler distro  find
cobbler distro list
cobbler distro remove
cobbler distro rename
cobbler distro report
[root@node112 ~] # cobbler  distro add -h
[root@node112 ~] # cobbler  distro add -h
   --name=NAME           Name (Ex: Fedora-11-i386)
   --kernel=KERNEL       Kernel (Absolute path to kernel on filesystem)
   --initrd=INITRD       Initrd (Absolute path to kernel on filesystem)

cobbler import //从镜像中获取

例如,对于已经挂载至/media/cdrom目录的CentOS 6.5 x86_64的安装镜像,则可以使用类似如下命令进行导入。

# cobbler import --name=centos-6.5-x86_64 --path=/media/cdrom //会在/var/www/cobbler下创建一个--name的目录

ks_mirror/ 就是拷贝的所有iso中的文件

会自动创建一个distro。可使用“cobbler distro list”列出所有的distro。

[root@node112 tftpboot]# cp /root/anaconda-ks.cfg /var/lib/cobbler/kickstarts/centos7.cfg

[root@node112 tftpboot]# cobbler profile add --name=CentOS-7-x86_64-100-server --distro=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg

ks文件需要放在:/var/lib/cobbler/cobbler/kickstart/

cobbler sync //同步


四、配置cobbler

1.管理distro

# cobbler import --name=centos-6.5-x86_64 --path=/media/cdrom //会在/var/www/cobbler下创建一个--name的目录

可使用“cobbler distro list”列出所有的distro。

如果有kickstart文件,也可以使用“--kickstart=/path/to/kickstart_file”进行导入,因此import会自动为导入的distro生成一个profile。


2.管理profile

[root@node112 tftpboot]# cobbler profile add --name=CentOS-7-x86_64-100-server --distro=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg


五、Cobbler-Web

cobbler_web的认证功能

cobbler_web支持多种认证方式,如authn_configfile、authn_ldap或authn_pam等,默认为authn_denyall,即拒绝所有用户登录。下面说明两种能认证用户登录cobbler_web的方式。


1.使用authn_pam模块认证cobbler_web用户

首先修改modules中[authentication]段的module参数的值为authn_pam。 //vim /etc/cobbler/modules.conf 

接着添加系统用户,用户名和密码按需设定即可,例如下面的命令所示。

# useradd cblradmin

# echo 'cblrpass' | passwd --stdin cblradmin

而后将cblradmin用户添加至cobbler_web的admin组中。修改/etc/cobbler/users.conf文件,将cblradmin用户名添加为admin参数的值即可,如下所示。

[admins]

admin = "cblradmin"

最后重启cobblerd服务,通过http://YOUR_COBBLERD_IP/cobbler_web访问即可。


2.使用authn_configfile模块认证cobbler_web用户

首先修改modules.conf中[authentication]段的module参数的值为authn_configfile。

接着创建其认证文件/etc/cobbler/users.digest,并添加所需的用户即可。需要注意的是,添加第一个用户时,需要为htdigest命令使用“-c”选项,后续添加其他用户时不能再使用;另外,cobbler_web的realm只能为Cobbler。如下所示。

# htdigest -c /etc/cobbler/users.digest Cobbler cblradmin  

最后重启cobblerd服务,通过http://YOUR_COBBLERD_IP/cobbler_web访问即可。


新版的默认使用https://ip/cobbler_web登录


六、Cobbler其他内容

1.Cobbler子命令介绍

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
cobbler check           #检查cobbler配置           主要用于检查cobbler配置是否有错
cobbler  sync             #同步配置到dhcp pxe和数据目录        更改某些配置后记得执行一下,同步一下配置。
cobbler list               #列出所有的cobbler元素
cobbler  import           #导入安装的系统光盘镜像
cobbler report           #列出各元素的详细信息
cobbler distro           #查看导入的发行版系统信息      不但可以查看导入的发行版系统信息还可以增加与修改等
cobbler profile          #查看配置信息                          不但可以查看Kickstart文件而且还可以编辑与删除此文件
cobbler system          #查看添加的系统信息
cobbler reposync        #同步yum仓库到本地               同步远程的yum源到本地
cobbler signature update
cobbler --help            #获得cobbler的帮助 
cobbler distro --help   #获得cobbler子命令的帮助
Cobbler配置目录
1、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模块配置文件
2、Cobbler数据目录: /var/lib/cobbler
/var/lib/cobbler/config  #配置文件
/var/lib/cobbler/triggers  #Cobbler命令
/var/lib/cobbler/kickstarts  #默认存放kickstart文件
/var/lib/cobbler/loaders  #存放的各种引导程序
3、系统安装镜像目录: /var/www/cobbler
/var/www/cobbler/ks_mirror  #导入的系统镜像列表
/var/www/cobbler/images  #导入的系统镜像启动文件
/var/www/cobbler/repo_mirror  #yum源存储目录
4、日志目录: /var/log/cobbler
/var/log/cobbler/install .log  #客户端系统安装日志
/var/log/cobbler/cobbler .log  #cobbler日志

2、Cobbler 不足

1.问题说明

根据MAC地址来配置主机ip和hostname,根据mac配置ip等相关信息是一些常见需求,有些设备标签上有mac地址,这一类可以手动抄下,然后在配置。但是,由于主机更换主板,或其他原因导致mac不对,你还用标签上的mac地址来配置,这就悲剧了。为了更好的解决这样的问题我们也可以有解决的办法。

2.解决方法

根据dhcp请求信息抓取mac地址,然后进行配置。具体方法可以通过tcpdump或者脚本来分析/var/log/message文件,抓取对目标端口为67访问的数据包,然后进行分析。

[root@node6 ~]# tcpdump -i eth0 dst port 67


参考:http://blog.51cto.com/xiexiaojun/1692475

ks文件详解:http://blog.51cto.com/xiexiaojun/1692058












本文转自MT_IT51CTO博客,原文链接:http://blog.51cto.com/hmtk520/2060670,如需转载请自行联系原作者
相关文章
|
数据安全/隐私保护
Cobbler
环境 rhel 6 安装与配置 配置epel源 yum install httpd dhcp tftp-server cobbler pykickstart syslinux rsync cman force-agent -y 修改xinetd的配置文件, 将tftpd和rsync开启 修改/...
1081 0
|
JavaScript Python 前端开发
|
XML Linux 开发工具
|
网络协议 Linux 数据安全/隐私保护
|
Linux 开发工具 数据安全/隐私保护
|
存储 数据安全/隐私保护 开发工具

热门文章

最新文章