运维自动化之Cobbler系统安装使用详解

运维 系统运维 自动化
Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。使用 Cobbler,您无需进行人工干预即可安装机器。

一、简介

Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP、DNS、以及yum仓库、构造系统ISO镜像。

Cobbler支持命令行管理,web界面管理,还提供了API接口,可以方便二次开发使用。

Cobbler客户端Koan支持虚拟机安装和操作系统重新安装,使重装系统更便捷。

二、cobbler提供的功能

使用 Cobbler,您无需进行人工干预即可安装机器。Cobbler 设置一个 PXE 引导环境(它还可使用 yaboot 支持 PowerPC),并控制与安装相关的所有方面,比如网络引导服务(DHCP 和 TFTP)与存储库镜像。当希望安装一台新机器时,Cobbler 可以:

  • 使用一个以前定义的模板来配置 DHCP 服务(如果启用了管理 DHCP)

  • 将一个存储库(yum 或 rsync)建立镜像或解压缩一个媒介,以注册一个新操作系统

  • 在 DHCP 配置文件中为需要安装的机器创建一个条目,并使用您指定的参数(IP 和 MAC 地址)

  • 在 TFTFP 服务目录下创建适当的 PXE 文件

  • 重新启动 DHCP 服务以反映更改

  • 重新启动机器以开始安装(如果电源管理已启用)

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 可从客户端配置虚拟机并重新安装系统。我不会讨论配置管理和koan 特性,因为它们不属于本文的介绍范畴。但是,它们是值得研究的有用特性。

三、安装配置

1.安装方式

cobbler可以手动编译安装,也可以基于yum源的安装, 如果需要通过yum源安装,则需要配置epel源,epel源可以通过下载官方给的epel源的目录来实现安装https://fedoraproject.org/wiki/EPEL

 

  1. [root@node1 ~]# yum install cobbler cobbler-web pykickstart debmirror -y 

 

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

  1. [root@node1 ~]# cobbler check 
  2. The following are potential configuration items that you may want to fix: 
  3. 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. 
  4. 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. 
  5. 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. 
  6. 4 : change 'disable' to 'no' in /etc/xinetd.d/rsync 
  7. 5 : comment out 'dists' on /etc/debmirror.conf for proper debian support 
  8. 6 : comment out 'arches' on /etc/debmirror.conf for proper debian support 
  9. 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 
  10. 8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them 

 

 

 

如上个问题的解决办法为:

1.修改/etc/cobbler/settings文件的server参数的值为提供cobbler服务的主机对应的ip地址

2.修改/etc/cobbler/settings文件的next_server参数的值为提供PXE服务的主机的对应IP地址  

3.如果当前节点可以访问互联网,执行“cobbler get-loader”命令下载pxelinux.0,menu.c32,elilo.efi, 或yaboot文件,否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/中的pxelinux.0,menu.c32等文件至/var/lib/cobbler/loaders目录中 4.将/etc/xinetd.d/rsync中的disable改为no,或者执行“chkconfig rsync on”

5.注释/etc/dedmirror.conf文件中的“@dists="sid";”一行

6.注释/etc/dedmirror.conf文件中的“@arches="i386";”一行

7.执行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数

8.安装cam和fance-agents来实现电源管理

通过cobbler get-loaders同步文件:

 

  1. [root@node1 ~]# cobbler get-loaders 
  2. task started: 2014-04-23_212251_get_loaders 
  3. task started (id=Download Bootloader Content, time=Wed Apr 23 21:22:51 2014) 
  4. downloading http://www.cobblerd.org/loaders/README to /var/lib/cobbler/loaders/README 
  5. downloading http://www.cobblerd.org/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo 
  6. downloading http://www.cobblerd.org/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot 
  7. downloading http://www.cobblerd.org/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux 
  8. downloading http://www.cobblerd.org/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi 
  9. downloading http://www.cobblerd.org/loaders/yaboot-1.3.14-12 to /var/lib/cobbler/loaders/yaboot 
  10. downloading http://www.cobblerd.org/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0 
  11. downloading http://www.cobblerd.org/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32 
  12. downloading http://www.cobblerd.org/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi 
  13. downloading http://www.cobblerd.org/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi 

四、配置及启动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配置文件中各服务的模块参数的值来实现

本处通过独立管理。即不通过cobbler来管理这些服务

1.配置dhcp服务

 定义好所需的“subnet”及其他参数,本处的配置如下: 

  1. [root@node1 ~]# cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf 
  2. 编辑配置文件 
  3. option domain-name "wangfeng7399"; 
  4. option domain-name-servers 192.168.1.201; 
  5. default-lease-time 43200; 
  6. max-lease-time 86400; 
  7. log-facility local7; 
  8. subnet 192.168.1.0 netmask 255.255.255.0 { 
  9.         range 192.168.1.210 192.168.1.230 
  10.         option routers 192.168.1.253 
  11. next-server 192.168.1.210; 
  12. filename="pxelinux.0"

 

 

 

2.配置tftpd服务

 

  1. [root@node1 ~]# chkconfig tftp on 

 

五、配置cobbler

cobbler的各主要组件间的关系如下图所示:

wKiom1Nw3UnBVNxHAAJgNktBY9o030.jpg

  1.管理distro

是cobbler变得可用的***步为定义distro,其可以通过为其指定外部的安装引导内核及ramdisk文件的方式实现。而如果已经有完成的安装树(如os的安装镜像)则推荐使用improt之间导入的方式进行:

  1. [root@node1 ~]# mount /dev/cdrom /media 
  2. mount: block device /dev/sr0 is write-protected, mounting read-only 
  3. [root@node1 ~]# cobbler import --name=centos6.5-x86-64 --path=/media/ 
  4. task started: 2014-04-23_214916_import 
  5. task started (id=Media import, time=Wed Apr 23 21:49:16 2014) 
  6. Found a candidate signature: breed=redhatversion=rhel6 
  7. Found a matching signature: breed=redhatversion=rhel6 
  8. Adding distros from path /var/www/cobbler/ks_mirror/centos6.5-x86-64: 
  9. creating new distro: centos6.5-64-x86_64 
  10. trying symlink: /var/www/cobbler/ks_mirror/centos6.5-x86-64 -> /var/www/cobbler/links/centos6.5-64-x86_64 
  11. creating new profile: centos6.5-64-x86_64 
  12. associating repos 
  13. checking for rsync repo(s) 
  14. checking for rhn repo(s) 
  15. checking for yum repo(s) 
  16. starting descent into /var/www/cobbler/ks_mirror/centos6.5-x86-64 for centos6.5-64-x86_64 
  17. processing repo at : /var/www/cobbler/ks_mirror/centos6.5-x86-64 
  18. need to process repo/comps: /var/www/cobbler/ks_mirror/centos6.5-x86-64 
  19. looking for /var/www/cobbler/ks_mirror/centos6.5-x86-64/repodata/*comps*.xml 
  20. Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos6.5-x86-64/repodata 
  21. *** TASK COMPLETE *** 

 

 

 

列出所有的distro:

  1. [root@node1 ~]# cobbler distro list 
  2. centos6.5-64-x86_64 

 

 

 

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

2.管理profile

 cobbler使用profile来为特定的需求类别提供锁需要安装的配置,即在distro的基础上通过提供kiskstart文件来生成一个特定的系统安装配置。distro的profile可以出现在pxe的引导菜单中作为安装的选择之一,关于kickstark文件的讲解可以移步本人的相关博客http://wangfeng7399.blog.51cto.com/3518031/1369553,不出就不再做详细说明:

 

  1. [root@node1 ~]# cobbler profile add --name=centos6.5-x86_64 --distro=centos6.5-64-x86_64 kickstart=/root/anaconda-ks.cfg 

 

列出当前系统上的profile:

  1. [root@node1 ~]# cobbler profile list 
  2. centos6.5-64-x86_64 
  3. centos6.5-x86_64 

 

 

 

删除一个profile:

 

  1. [root@node1 ~]# cobbler profile remove --name=centos6.5-64-x86_64 

 

3.重启服务及同步数据到响应的目录 

 

  1. [root@node1 ~]# service cobblerd restart  
  2. Stopping cobbler daemon:                                   [  OK  ]  
  3. Starting cobbler daemon:                                   [  OK  ]  
  4. [root@node1 ~]# cobbler sync  
  5. task started: 2014-04-23_220652_sync  
  6. task started (id=Synctime=Wed Apr 23 22:06:52 2014)  
  7. running pre-sync triggers  
  8. cleaning trees  
  9. removing: /var/www/cobbler/images/centos6.5-64-x86_64  
  10. removing: /var/lib/tftpboot/pxelinux.cfg/default  
  11. removing: /var/lib/tftpboot/grub/images  
  12. removing: /var/lib/tftpboot/grub/efidefault  
  13. removing: /var/lib/tftpboot/images/centos6.5-64-x86_64  
  14. removing: /var/lib/tftpboot/s390x/profile_list  
  15. copying bootloaders  
  16. trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0  
  17. trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32  
  18. trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot  
  19. 中间省去N行  
  20. received on stderr:  
  21. running shell triggers from /var/lib/cobbler/triggers/sync/post/*  
  22. running python triggers from /var/lib/cobbler/triggers/change/*  
  23. running python trigger cobbler.modules.scm_track  
  24. running shell triggers from /var/lib/cobbler/triggers/change/*  
  25. *** TASK COMPLETE ***  

 

  4.测试  

 

wKioL1Nw_OLB236xAACzwYdDGI8873.jpg

可以看到我们定制的系统启动页面,开始安装系统

wKiom1Nw_Q2zpiUNAAEV8Xm_Jps672.jpg

系统安装成功,登陆系统

wKiom1Nw_92gOcwhAAEITWN87Q4866.jpg

六、使用cobbler_web

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

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

首先修改modules中的[authentication]段中的module参数的值为authn_pam,接着设定系统用户,并为用户设定密码,而后将设定的系统用户添加至cobbler_web的admin组中,修改/etc/cobbler/users.conf文件,将设定的用户添加为admin参数的值即可。  

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

首先修改modules中的[authentication]段中的module参数的值为authn_configfile,接着创建其认证文件/etc/cobbler/users.digest,并添加所需要的用户即可。需要注意的是,添加***用户时,需要为htdigest命令使用“-c”选项,后续添加其他用户则不能再使用。

本处使用的为authn_pam

  1. [root@node1 ~]# vi /etc/cobbler/modules.conf 
  2. [authentication] 
  3. module = authn_pam 
  4. [root@node1 ~]# useradd wangfeng7399 
  5. [root@node1 ~]# passwd wangfeng7399 
  6. Changing password for user wangfeng7399. 
  7. New password: 
  8. Retype new password: 
  9. passwd: all authentication tokens updated successfully. 
  10. [root@node1 ~]# vi /etc/cobbler/users.conf 
  11. [admins] 
  12. admin = "wangfeng7399" 

 

 

 

wKioL1NxAGDh2J3xAAJOswKBn8c655.jpg

wKiom1NxAIyQhR8MAAGb1odXoqw457.jpg

wKioL1NxAGGzzHAfAAHX4uWbjiE851.jpg

wKiom1NxAIzzqVTaAAJoJMvRY5w390.jpg

完全可以手动添加,这也不为记不住命令而发愁了!

大功告成,后续将推出自动化运维的相关内容,敬请期待!

责任编辑:黄丹 来源: 51TCO博客
相关推荐

2011-09-01 10:22:03

Cobbler运维自动化

2013-04-17 15:48:51

2013-04-11 17:31:28

运维自动化Cobbler

2014-08-04 10:10:35

IT运维自动化运维

2014-09-22 11:24:18

运维

2013-04-16 14:55:21

自动化运维Puppet实战

2012-05-05 21:28:44

2012-10-22 14:54:48

2012-05-05 22:27:46

puppet自动化运维

2012-05-05 21:48:43

puppet自动化运维

2010-08-12 17:39:07

网站运维自动化管理

2016-03-30 11:53:51

Cobbler运维运维自动化

2012-05-05 21:43:27

puppet自动化运维

2017-03-22 18:30:44

Linux运维自动化ansible

2018-06-23 07:31:05

2017-03-22 16:31:30

Linux运维自动化ansible

2012-05-05 21:03:35

puppet自动化运维

2020-04-30 15:00:17

运维Ansible自动化

2015-03-09 11:10:14

运维

2015-09-23 16:46:54

架构监控运维自动化
点赞
收藏

51CTO技术栈公众号