码迷,mamicode.com
首页 > 系统相关 > 详细

linux 自动化运维之Cobbler

时间:2014-05-13 13:10:11      阅读:758      评论:0      收藏:0      [点我收藏+]

标签:cobbler

一、Cobbler 简介

1.Cobbler 概述

       Cobbler由python语言开发,是对PXE和Kickstart以及DHCP的封装。融合很多特性,提供了CLI和Web的管理形式。更加方便的实行网络安装。同时,Cobbler也提供了API接口,使用其它语言也很容易做扩展。它不紧可以安装物理机,同时也支持kvm、xen虚拟化、Guest OS的安装。更多的是它还能结合Puppet等集中化管理软件,实现自动化的管理。


2.新旧对比

    以前自动化安装系统得先设置一个网络环境,可是设置网络环境涉及到许多步骤,才能为开始安装系统做好准备。你必须:

  • 配置服务,比如 DHCP、TFTP、DNS、HTTP、FTP 和NFS;

  • 在 DHCP 和 TFTP 配置文件中填入各个客户端机器的信息;

  • 创建自动部署文件(比如 kickstart 和 autoinst);

  • 将安装媒介解压缩到 HTTP/FTP/NFS 存储库中。

这个过程并不简单,而且手动注册每个必须配置的客户端机器可能很麻烦。对配置一台机器的任何参数更改(比如要使用一个不同的操作系统),都需要对配置进行手动干预,并有可能对自动部署文件进行手动干预。当机器数量增加时,如果不高度重视文件组织的条理性,TFTP 目录等元素就可能变得混乱。


    Cobbler 通过为机器配置的所有方面创建一个中央管理点,从而解决了这些不足。Cobbler 可重新配置服务,创建存储库,解压缩操作系统媒介,代理或集成一个配置管理系统,控制电源管理等。Cobbler 创建了一个抽象层,您可在其中运行 “add new repository” 或 “change client machine operating system” 等命令。Cobbler 负责处理所有事情:创建或更新配置文件,重新启动服务,或者将媒介解压到新创建的目录中。它的目的是隐藏所有与系统相关的问题,以便您可专注于任务本身。


3.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 可从客户端配置虚拟机并重新安装系统。


4.Cobbler的工作模式

bubuko.com,布布扣


二、cobbler环境配置

cobbler主机,IP地址为192.168.10.1,此主机可以连接外网!


  • 配置好yum源

# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm


  • 关闭防火墙与SELinux

# service iptables stop
# chkconfig iptables off
# getenforce     //出现Disabled信息则表示禁用selinux成功


三、Cobbler 安装

1、Cobbler运行所需基础包

[root@mogilefs2 ~]# yum install -y cobbler tftp dhcp httpd cman pykickstart debmirror


2、安装cobbler所需环境支持包

[root@mogilefs2 ~]# yum install -y ed patch perl perl-Compress-Zlib perl-Digest-SHA1 perl-LockFile-Simple perl-libwww-perl


3、启动服务

[root@mogilefs2 ~]# chkconfig httpd on
[root@mogilefs2 ~]#  chkconfig dhcpd on
[root@mogilefs2 ~]#  chkconfig xinetd on
[root@mogilefs2 ~]#  chkconfig cobblerd on
[root@mogilefs2 ~]#  service httpd start
[root@mogilefs2 ~]#  service cobblerd start


4、运行Cobbler检查命令

[root@mogilefs2 ~]#  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 : 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 out ‘dists‘ on /etc/debmirror.conf for proper debian support
6 : comment out ‘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
Restart cobblerd and then run ‘cobbler sync‘ to apply changes.


通过ckeck命令会出现上面7个错误:

(1).错误1,修改/etc/cobbler/settings 里面的 server 为Cobbler Server的IP地址 ;

[root@mogilefs2 ~]#  vim /etc/cobbler/settings
//找到server字段,并修改
server: 192.168.10.1

注:选项 server 在客户端安装期间用于引用 Cobbler 服务器地址!


(2).错误2,修改/etc/cobbler/settings 里面的 next_serverw 为本机的 ip;

[root@mogilefs2 ~]#  vim /etc/cobbler/settings
//找到next_server字段,并修改
next_server: 192.168.10.1

注:选项 next_server 用在 DHCP 配置文件中,向客户端告知提供引导文件的tftp服务器地址。


(3).错误3,这个错误可以忽略,也可以使用下面命令来解决

[root@mogilefs2 ~]# cobbler get-loaders

bubuko.com,布布扣

注:使用此命令,你的主机必须要能够连接外网,如果上不了可以通过(修改默认网关,dns配置(/etc/resolv.conf)等来自行解决)!


(4).错误4,修改/etc/xinetd.d/tftp 把‘disable‘ 修改为‘no‘;修改/etc/xinetd.d/rsync 把‘disable‘ 修改为‘no‘;

[root@mogilefs2 ~]#  vim /etc/xinetd.d/tftp
disable         = no
[root@mogilefs2 ~]#  vim /etc/xinetd.d/rsync
disable = no
[root@mogilefs2 ~]# service xinetd start


(5).错误5与错误6,修改/etc/debmirror.conf

[root@mogilefs2 ~]# vim /etc/debmirror.conf
//注释掉@dists="sid"与@arches="i386即可
#@dists="sid";
#@arches="i386";


(6).错误7,设置默认root密码;此密码为客户端的密码

生成你想要的密码的加密字符串,然后复制密码串,替换/etc/cobbler/settings 中选项default_password_crypted双引号中的加密代码!

[root@mogilefs2 ~]# openssl passwd -1 -salt ‘wrwrwr‘ ‘admin‘
$1$wrwrwr$rPLGM0rm/G1BIrBPzf8JP0
[root@mogilefs2 ~]# vim /etc/cobbler/settings
//找到default_password_crypted字段,把密码复制进去
default_password_crypted:$1$wrwrwr$rPLGM0rm/G1BIrBPzf8JP0


5、重启cobblerd服务,并检查

[root@mogilefs2 ~]# service cobblerd restart
[root@mogilefs2 ~]# cobbler check

bubuko.com,布布扣


查看下端口:

bubuko.com,布布扣


6、DHCP的配置

  • 让Cobbler来管理DHCP,tftp服务器

[root@mogilefs2 ~]# vim /etc/cobbler/settings
//找到以下字段,并修改如下:
manage_dhcp:1
manage_tftpd:1
restart_dhcp:1
pxe_just_once:1 //此选项可以预防将机器中的安装循环配置为始终从网络引导。激活此选项时,机器告诉 Cobbler 安装已完成。Cobbler 将系统对象的 netboot 标志更改为 false,这会强制机器从本地磁盘引导!


  • 修改dhcp模板

[root@mogilefs2 ~]# vim /etc/cobbler/dhcp.template
//修改subnet项如下:
subnet 192.168.10.0 netmask 255.255.255.0 {
     option routers             192.168.10.5;
     option domain-name-servers 8.8.8.8;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.10.100 192.168.10.125;
     filename "/pxelinux.0";
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "grub/grub-x86.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "grub/grub-x86_64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }
}

注:

filename    "/pxelinux.0";  表示指定的网络引导程序

next-server    $next_server;  表示指定的TFTP服务器的地址,此地址在前面已经定义过!


  • 启用mod_wsgi.so模块(已启用则跳过)

[root@mogilefs2 ~]# vim /etc/httpd/conf.d/wsgi.conf
LoadModule wsgi_module modules/mod_wsgi.so


  • 重启并检查

[root@mogilefs2 ~]# service cobblerd restart
[root@mogilefs2 ~]# cobbler check
[root@mogilefs2 ~]# cobbler sync

注:cobbler sync 可以同步cobbler配置到数据目录中,更改某些配置后需要执行一下,同步一下配置

bubuko.com,布布扣


四、导入要安装的镜像文件

1、首先使用虚拟机挂载centos6.5的iso文件到虚拟机上

bubuko.com,布布扣

2、挂载光盘镜像至本地

[root@mogilefs2 ~]#  mount /dev/cdrom /mnt


3、导入镜像文件

[root@mogilefs2 ~]# cobbler import --path=/mnt/ --name=CentOS-6.5 --arch=x86_64

参数注解:

--path     指定导入镜像的路径

--name    指定导入镜像的名称,

--arch     指定导入镜像的架构(32位还是64位)。

另外,导入镜像时间有点长,稍安勿躁!


乘此机会,我们来介绍下cobbler的命令:

cobbler check     //检查cobbler配置
cobbler sync      //同步配置到dhcp/pxe和数据目录
cobbler list      //列出所有的cobbler元素
cobbler import    //导入安装的系统镜像
cobbler report    //列出各元素的详细信息
cobbler distro     //查看导入的发行版系统信息
cobbler profile    //查看配置信息
cobbler system  //查看添加的系统信息
cobbler reposync //同步yum仓库到本地


导入镜像成功后,我们来看下cobbler元素的信息:

bubuko.com,布布扣


查看详细信息:

bubuko.com,布布扣

从上图看出,自动使用默认的kickstart文件,我们可以使用此ks文件,也可以自定义ks文件!


4、检查下

[root@mogilefs2 ~]# cobbler check
[root@mogilefs2 ~]# cobbler sync

没有问题的话,执行下一步.


5、新建的个无操作系统的虚拟机

具体怎么建虚拟机,就不演示了,设置为网络启动(可以按F2,进去BOOT设置)

然后启动虚拟机,会自动向cobbler服务器发送请求。(网卡要与cobbler服务器一个类型):

bubuko.com,布布扣

至此,cobbler自动化安装系统已经实现!


五、自定义Kickstart文件

  上面的实验是通过默认的sample_end.ks文件来实现自动化安装的,但是这个kickstart文件有许多地方并不符合我们的安装需求,如:默认时区不符合、分区不符合等。所以,我们得自定义Kickstart文件。

一般两种方案:

  • 手动的修改已有的Kickstart文件

  • 用system-config-kickstart工具生成Kickstart文件


我们这里采用手动修改的方式,使用默认的sample.ks文件:

[root@mogilefs2 kickstarts]# cp sample.ks centos-6.5.ks


修改如下:

[root@mogilefs2 kickstarts]# vim centos-6.5.ks
//修改如下:
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5     //用户登录认证
# System bootloader configuration
bootloader --location=mbr          //mbr引导
# Partition clearing information
clearpart --all --initlabel        //默认清除所有分区
# Use text mode install
text                            //默认以文本模式安装
# Firewall configuration
firewall --service=ssh      //开启防火墙但开放ssh服务
# Run the Setup Agent on first boot
firstboot --disable       //禁用启动代理
# System keyboard
keyboard us              //默认英文键盘
# System language
lang en_US              //默认语言英文
# Use network installation
url --url=$tree         //网络安装路径
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza      //默认的yum仓库
# Network information
$SNIPPET(‘network_config‘)
# Reboot after installation
reboot               //安装完成后重启
#Root password
rootpw --iscrypted $default_password_crypted  //密码是/etc/cobbler/settings设置密码
# SELinux configuration
selinux --disabled        //默认关闭selinux
# Do not configure the X Window System
skipx                      //默认没有安装图形界面
# System timezone
timezone --utc Asia/Shanghai     //时区修改为亚洲/上海
# Install OS instead of upgrade
install                    //定义默认是安装系统而不是升级系统
# Clear the Master Boot Record
zerombr                   //默认清空所有的mbr
# Allow anaconda to partition the system as needed
#autopart               //默认自动分区注释掉,不启用
//自定义分区,单位为MB
part /boot --fstype=ext4 --size=200
part / --fstype=ext4 --size=20000
part /data --fstype=ext4 --size=10000
part swap --size=5000
%pre
$SNIPPET(‘log_ks_pre‘)
$SNIPPET(‘kickstart_start‘)
$SNIPPET(‘pre_install_network_config‘)
# Enable installation monitoring
$SNIPPET(‘pre_anamon‘)
%packages
$SNIPPET(‘func_install_if_enabled‘)
$SNIPPET(‘puppet_install_if_enabled‘)
%post
$SNIPPET(‘log_ks_post‘)
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET(‘post_install_kernel_options‘)
$SNIPPET(‘post_install_network_config‘)
$SNIPPET(‘func_register_if_enabled‘)
$SNIPPET(‘puppet_register_if_enabled‘)
$SNIPPET(‘download_config_files‘)
$SNIPPET(‘koan_environment‘)
$SNIPPET(‘redhat_register‘)
$SNIPPET(‘cobbler_register‘)
# Enable post-install boot notification
$SNIPPET(‘post_anamon‘)
# Start final steps
$SNIPPET(‘kickstart_done‘)
# End final steps


也可以通过system-config-kickstart来创建ks文件

[root@mogilefs2 kickstarts]# yum install -y system-config-kickstart

这里就不演示了!


  • 将自定义的Kickstart文件与导入的镜像文件相关联

首先查看下cobbler状态

[root@mogilefs2 kickstarts]# cobbler report

bubuko.com,布布扣


将ks文件与镜像关联

[root@mogilefs2 kickstarts]# cobbler profile edit --name=Centos-6.5-x86_64 --distro=Centos-6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-6.5.ks
[root@mogilefs2 kickstarts]# cobbler report

bubuko.com,布布扣


启动安装:

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣


好了,自动化运维之cobbler已经介绍完毕,不足之处,请多加指点!


linux 自动化运维之Cobbler,布布扣,bubuko.com

linux 自动化运维之Cobbler

标签:cobbler

原文地址:http://584014981.blog.51cto.com/8605371/1410039

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!