大纲

一、前言

二、Cobbler 工作原理详解

三、Cobbler 常用命令汇总

四、Cobbler 各种目录说明

五、自定义Kickstart文件详解

六、Cobbler 实战案例安装CentOS6.4

注,操作系统 CentOS 6.4 x86_64,软件版本 Cobbler-2.4.0-1。(目前最新版)


一、前言

在上篇博客中我们讲解了cobbler命令的详细使用,并在最后我们详细的讲解了Cobbler安装CentOS5.5全部过程,不清楚的博友可以先参考上一篇博文(http://freeloda.blog.51cto.com/2033581/1323620),在这一篇博客中我们主要和大家总结一下上几篇博客讲解的内容,并详细讲解一下自定义Kickstart文件与Cobbler相关目录的说明,最后以一个实际案例做结尾。好了,废话不多说,下面我们先来回顾一下Cobbler工作原理。


二、Cobbler 工作原理详解

1.概述

在前几篇博客中我们和大家说了,Cobbler集众家之长支持众多有服务,我在这里简单的说一下Cobbler集成了哪些服务,

  • PXE 服务

  • DHCP服务管理

  • DNS服务管理

  • HTTP服务管理

  • TFTP服务管理

  • Kickstart服务

  • yum仓库管理

  • 电源管理

2.工作流程

(1).需要安装系统的客户端主机的网卡支持网络安装,也就是支持以PXE模式启动。如下图,

Linux 运维自动化之Cobbler实战案例

(2).客户端主机需要有一个IP地址来与Cobbler Server进行通信,这时网络中必须要有一个主机能自动分配IP。DHCP就是一个能为客户端主机自动分配IP地址的服务,DHCP就是安装在Cobbler Server主机上。

(3).客户端得到IP地址后,需要提供一个引导程序pxelinux.0(类似于grub) 此文件由syslinux程序提供,所以需要安装syslinux并且能加载内核及内核镜像文件(vmlinuz与initrd.img),客户端可以通过TFTP协议到TFTP Server上下载内核及内核镜像文件(vmlinuz与initrd.img),所以需要一个TFTP 服务,TFTP也是安装在Cobbler Server主机上,客户端只是知道可以用TFTP协议下载文件,但是TFTP Server的IP是那个,这个还得需要DHCP服务器指名告诉客户端那个是TFTP Server(注,所以我们在配置DHCP模板时指定next-server,同时指定了filename,这里的filename就是指定的pxelinux.0引导程序),而TFTP服务需要超级进程进行管理,此进程是xinetd,因此需要在Cobbler Server上安装xinet服务。下面是DHCP模板的部分内容,

[[email protected] ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.18.0 netmask 255.255.255.0 { 
   option routers       192.168.18.254;  
   option domain-name-servers 192.168.18.254;  
   option subnet-mask     255.255.255.0;  
   range dynamic-bootp    192.168.18.221 192.168.18.225;  
   filename          "/pxelinux.0"; #指定的网络引导程序  
   default-lease-time     21600;  
   max-lease-time       43200;  
   next-server        $next_server; #指定的TFTP服务器的地址

(4).客户端完全自动化部署操作系统,则需要一个kickstart文件,默认使用的是/var/lib/cobbler/kickstarts/default.ks文件,我们也可以自己自定义一个kickstart文件,自定义kickstart文件可以自己手动的编写,也可以用system-config-kickstart工具进行生成,如果需要则可以在Cobbler Server上安装system-config-kickstart工具生成一个kickstart文件。

(5).已经有了kickstart文件,需要在kickstart文件中指定一个参数,告诉客户端以什么方式安装(http/ftp/nfs等),这里的参数指的就是到哪里去找安装源(安装源就是指安装系统所需的软件),这样的方式可以是nfs,ftp,http等,选择其一即可,Cobbler Server在此选择以http方式提供安装源。

3.Cobbler 所依赖的软件包

注,上述流程可以得到Cobbler安装软件所需的主要的依赖性包。

dhcp 提供IP地址、指名TFTP Server的地址、指定pxelinux文件 tftp-server 提供引导所需的文件、内核文件、内核镜像文件等 xinetd 管理tftp服务的超级进程 syslinux 提供pxelinux文件 system-config-kickstart 生成kickstart文件 httpd 提供安装源 cman 提供电源管理 其它依赖包

好了,刚才我们重新整理一下Cobbler的工作原理,希望可以帮助大家理解。下面我们来看一下Cobbler的常用命令!


三、Cobbler 常用命令汇总

1.导入镜像文件

命令:cobbler import --path=镜像路径 -- name=安装引导名 --arch=32位或64位

参数:

  • path 是镜像所挂载的目录

  • name 是导入到cobbler里面显示的名字

  • arch 是32位系统还是64位系统

2.导入kickstart文件

命令:cobbler profile add --name=list名 --distro=镜像 --kickstart=路径

参数:

  • name是表示添加的ks 的名字,用cobbler report可以看到这个名字

  • distro 是用哪个镜像,list的distros里面选择一个,需要版本相对应

  • kickstart 是具体的 ks 文件路径

3.同步DHCP、HTTPD

命令:cobbler sync

注,每次修改完dhcp.template之类的配置文件需要执行一次使其生效。

4.查看Cobbler列表

命令:cobbler list

注,列出Cobbler所有的元素。

5.删除相关列表

命令:cobbler distro/profile remove --name=要删除的引导文件名

  • 删除指定 distro , 也就是镜像

  • 删除指定的 profile 文件,也就是 ks


四、Cobbler 各种目录说明(注,这里只介绍重点的文件或目录 )

1.cobbler配置文件目录/etc/cobbler

[[email protected] cobbler]# ls /etc/cobbler/ 
auth.conf    cobblerd.service    dnsmasq.template    mongodb.conf  rsync.exclude    users.conf  
cheetah_macros  cobbler_web.conf    import_rsync_whitelist named.template rsync.template   users.digest  
cobbler_bash   completions       iso           power      secondary.template version  
cobbler.conf   dhcp.template      ldap          pxe       settings      zone.template  
cobblerd_rotate distro_signatures.json modules.conf      reporting    tftpd.template   zone_templates
  • /etc/cobbler/settings cobbler主配置文件

  • /etc/cobbler/iso/ iso模板配置文件

  • /etc/cobbler/pxe pxe模板文件

  • /etc/cobbler/power 电源的配置文件

  • /etc/cobbler/users.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模块配置文件

2.cobbler数据目录/var/lib/cobbler

[[email protected] cobbler]# ls /var/lib/cobbler/ 
config distro_signatures.json kickstarts loaders lock scripts snippets triggers web.ss
[[email protected] config]# ls 
distros.d files.d p_w_picpaths.d mgmtclasses.d packages.d profiles.d repos.d systems.d
[[email protected] loaders]# ls 
COPYING.elilo   COPYING.yaboot grub-x86_64.efi menu.c32  README  
COPYING.syslinux elilo-ia64.efi grub-x86.efi   pxelinux.0 yaboot
  • /var/lib/cobbler/config/ 用于存放distros、systems、profiles等信息配置文件

  • /var/lib/cobbler/triggers 用于存放用户定义的cobbler 命令

  • /var/lib/cobbler/kickstarts/ 默认存放kickstart文件

  • /var/lib/cobbler/loaders 存放的各种引导程序

3.镜像数据目录/var/www/cobbler

[[email protected] cobbler]# ls 
aux p_w_picpaths ks_mirror links localmirror pub rendered repo_mirror svc
  • /var/www/cobbler/ks_mirror/ 导入的发行版系统的所有数据

  • /var/www/cobbler/p_w_picpaths/ 导入发行版的Kernel和initrd镜像用于远程网络启动

  • /var/www/cobbler/repo_mirror/ yum仓库存储目录

4.日志目录 /var/log/cobbler/

[[email protected] cobbler]# ls 
anamon cobbler.log install.log kicklog syslog tasks
[[email protected] cobbler]# cat install.log 
profile  CentOS-5.5-x86_64  192.168.18.222  start  1384219313.49  
profile  CentOS-5.5-x86_64  192.168.18.222  stop  1384219512.05
  • /var/log/cobbler/install.log 客户端的安装系统日志

  • /var/log/cobbler/cobbler.log cobbler日志


五、自定义Kickstart文件详解

1.默认的Kickstart文件

[[email protected] kickstarts]# cd /var/lib/cobbler/kickstarts/ 
[[email protected] kickstarts]# ls  
default.ks  legacy.ks      sample_end.ks  sample_esxi5.ks sample.seed  
esxi4-ks.cfg pxerescue.ks     sample_esx4.ks  sample.ks  
esxi5-ks.cfg sample_autoyast.xml sample_esxi4.ks sample_old.seed

注,一般sample.ks与sample_end.ks用的比较多,下面我们来查看一下。

[[email protected] ~]# cobbler report
#上面部分内容省略
profiles: 
========== 
Name              : CentOS-5.5-x86_64 
TFTP Boot Files        : {} 
Comment            :  
DHCP Tag            : default 
Distribution          : CentOS-5.5-x86_64 
Enable gPXE?          : 0 
Enable PXE Menu?        : 1 
Fetchable Files        : {} 
Kernel Options         : {} 
Kernel Options (Post Install) : {} 
Kickstart           : /var/lib/cobbler/kickstarts/sample.ks

注,大家可以看到我们导入的CentOS5.5的镜像默认使用的kickstarts文件是sample.ks ,下面我们来具体看一下sample.ks的内容。

[[email protected] ~]# cat /var/lib/cobbler/kickstarts/sample.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 --enabled #防火墙默认开启 
# 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 America/New_York #默认时区是美国/纽约 
# Install OS instead of upgrade 
install #定义的是安装系统而不是升级系统 
# Clear the Master Boot Record 
zerombr #默认清空所有的mbr 
# Allow anaconda to partition the system as needed 
autopart #默认自动分区
#下面就是Cobbler自定执行的一些脚本,我就不解释了。 
%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

注,大家可以看到默认的Kickstart文件,有许多地方并不符合我们的安装需求,如:默认时区不符合、分区不符合等。所以,我们得自定义Kickstart文件。

2.自定义Kickstart文件

一般两种方案:

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

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

(1).手动的修改已有的Kickstart文件

注,手动修改已存在的Kickstart文件,其中有两个地方有Kickstart文件。一个在root家目录下的anaconda-ks.cfg文件,另一个就是我们默认的/var/lib/cobbler/kickstarts/sample.ks文件。其中anaconda-ks.cfg文件中有我们需要的时区信息、分区信息等,而sample.ks文件有我们需要的其它信息。我们可以手动修改一下,整理出我们需要的Kickstart文件。好了,下面我们就来手动的修改一下。

注,查看默认的 anaconda-ks.cfg 文件。

[[email protected] ~]# cat anaconda-ks.cfg 
# Kickstart file automatically generated by anaconda.
#version=DEVEL 
install 
cdrom 
lang zh_CN.UTF-8 
keyboard us 
network --onboot no --device eth0 --bootproto dhcp --noipv6 
rootpw --iscrypted $6$rLcXd8hdqBw35VJ4$xMY155kcD1IULRuOW5AllU48obFbIgp11OBg72nPAE575mo8oC9Eqo8tGzJgtM2HkrDSciAGVUtCMXTjiIdaG. 
firewall --service=ssh 
authconfig --enableshadow --passalgo=sha512 
selinux --enforcing 
timezone --utc Asia/Shanghai 
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" 
# The following is the partition information you requested 
# Note that any partitions you deleted are not expressed 
# here so unless you clear all partitions first, this is 
# not guaranteed to work 
#clearpart --none
#part /boot --fstype=ext4 --size=200 
#part / --fstype=ext4 --size=10000 
#part /data --fstype=ext4 --size=5000
#part swap --size=1000
repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100
%packages 
@chinese-support 
@core 
@development 
@server-policy

注,查看默认的/var/lib/cobbler/kickstarts/sample.ks文件。

[[email protected] ~]# cat /var/lib/cobbler/kickstarts/sample.ks 
#platform=x86, AMD64, or Intel EM64T 
# System authorization information 
auth --useshadow --enablemd5 
# System bootloader configuration 
bootloader --location=mbr 
# Partition clearing information 
clearpart --all --initlabel 
# Use text mode install 
text 
# Firewall configuration 
firewall --enabled 
# 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 
# Network information 
$SNIPPET('network_config') 
# Reboot after installation 
reboot
#Root password 
rootpw --iscrypted $default_password_crypted 
# SELinux configuration 
selinux --disabled 
# Do not configure the X Window System 
skipx 
# System timezone 
timezone America/New_York 
# Install OS instead of upgrade 
install 
# Clear the Master Boot Record 
zerombr 
# Allow anaconda to partition the system as needed 
autopart
%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

注,修改后的Kickstart文件。

[[email protected] ~]# cd /var/lib/cobbler/kickstarts/ 
[[email protected] kickstarts]# cp sample.ks centos.ks
[[email protected] kickstarts]# cat centos.ks 
#platform=x86, AMD64, or Intel EM64T 
# System authorization information 
auth --useshadow --enablemd5 
# System bootloader configuration 
bootloader --location=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 
# Network information 
$SNIPPET('network_config') 
# Reboot after installation 
reboot
#Root password 
rootpw --iscrypted $default_password_crypted 
# SELinux configuration 
selinux --disabled 
# 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 
# Allow anaconda to partition the system as needed
#下面定义的是默认分区,这个分区大小可以自己定义,单位为MB。由于我这里是虚拟机只有20的硬盘空间,所以我是这样划分的/boot 200MB、/ 10G 、/data 5G、swap 1G。 
part /boot --fstype=ext4 --size=200 
part / --fstype=ext4 --size=10000 
part /data --fstype=ext4 --size=5000 
part swap --size=1000
%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')
@chinese-support 
@core 
@development
%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

好了,到这里我们的手动修改Kickstart文件就全部讲解完成了,下面我们来说一下怎么用system-config-kickstart工具生成Kickstart文件。

(2).用system-config-kickstart工具生成Kickstart文件

注,首先我们得用yum安装一下system-config-kickstart工具。

[[email protected] ~]# yum install -y system-config-kickstart

注,下面我们就来具体演示一下怎么生成Kickstart文件。

[[email protected] ~]# system-config-kickstart

Linux 运维自动化之Cobbler实战案例

注,修改相关选项,设置时区、设置根口令、选择“安装后重新引导系统”。

Linux 运维自动化之Cobbler实战案例

注,选择“执行新安装”、安装方法选择“http”设置相关参数。

Linux 运维自动化之Cobbler实战案例

注,这里选择“清除主引导记录”、“删除所有现在分区”、“不要初始化磁盘标签”、设置分区。

Linux 运维自动化之Cobbler实战案例

注,配置网络信息,增加eth0设置为DHCP获得。

Linux 运维自动化之Cobbler实战案例

注,验证这里全部默认不需要修改。

Linux 运维自动化之Cobbler实战案例

注,设置防火墙与SELinux为禁用状态。

Linux 运维自动化之Cobbler实战案例

注,显示配置我这里安装了图形环境,你可以根据需要设置是否安装。首次引导设置代理“禁用”。

Linux 运维自动化之Cobbler实战案例

注,软件包这边我选择了“开发工具”,其它都没有选择其实就是默认安装。

Linux 运维自动化之Cobbler实战案例

注,语言支持这边我们选择是“中文支持”。

Linux 运维自动化之Cobbler实战案例

注,预安装脚本与安装后脚本可以根据需求自定义配置。

Linux 运维自动化之Cobbler实战案例

Linux 运维自动化之Cobbler实战案例

注,先预览一下我们的配置的Kickstart文件,发现在没有问题我们保存一下就好。

Linux 运维自动化之Cobbler实战案例

注,发现在没有问题了,我们保存一下。

Linux 运维自动化之Cobbler实战案例

[[email protected] ~]# ls 
anaconda-ks.cfg install.log install.log.syslog ks.cfg 
[[email protected] ~]# cat ks.cfg  
#platform=x86, AMD64, 或 Intel EM64T 
#version=DEVEL 
# Firewall configuration 
firewall --disabled 
# Install OS instead of upgrade 
install 
# Use network installation 
url --url="http://192.168.18.202/cobbler/ks_mirror/CentOS-5.5-x86_64/"
# Root password 
rootpw --iscrypted $1$lNz9giZK$b.1VPUVpxYkCYd/Su.E5r1 
# System authorization information 
auth --useshadow --passalgo=sha512 
# Use graphical install 
graphical 
firstboot --disable 
# System keyboard 
keyboard us 
# System language 
lang en_US 
# SELinux configuration 
selinux --disabled 
# Installation logging level 
logging --level=info 
# Reboot after installation 
reboot 
# System timezone 
timezone --isUtc Asia/Shanghai 
# Network information 
network --bootproto=dhcp --device=eth0 --onboot=on 
# Clear the Master Boot Record 
zerombr 
# Partition clearing information 
clearpart --all
# Disk partitioning information 
part /boot --fstype="ext4" --size=256 
part / --fstype="ext4" --size=10000 
part /data --fstype="ext4" --size=5000 
part swap --fstype="swap" --size=1000
%packages 
@chinese-support 
@development 
git 
-ibus-table-cangjie 
-ibus-table-erbi 
-ibus-table-wubi
%end

好了,到这里我们的自定义Kickstart文件就全部讲解完成了,下面我们来说一下怎么将自定义的Kickstart文件与导入的镜像文件相关联。

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

(1).查看一下导入的镜像文件

[[email protected] ~]# cobbler list 
distros: 
  CentOS-5.5-x86_64 
  CentOS-5.5-xen-x86_64
profiles: 
  CentOS-5.5-x86_64 
  CentOS-5.5-xen-x86_64
systems:
repos:
p_w_picpaths:
mgmtclasses:
packages:
files:

注,大家可以看到我们导入的是CentOS5.5镜像,下面我们再来查看一下此镜像对就的Kickstart文件。

[[email protected] ~]# cobbler report
注,上面一些内容省略。
profiles: 
========== 
Name              : CentOS-5.5-x86_64 
TFTP Boot Files        : {} 
Comment            :  
DHCP Tag            : default 
Distribution          : CentOS-5.5-x86_64 
Enable gPXE?          : 0 
Enable PXE Menu?        : 1 
Fetchable Files        : {} 
Kernel Options         : {} 
Kernel Options (Post Install) : {} 
Kickstart           : /var/lib/cobbler/kickstarts/sample.ks  
Kickstart Metadata       : {} 
Management Classes       : [] 
Management Parameters     : <<inherit>> 
Name Servers          : [] 
Name Servers Search Path    : [] 
Owners             : ['admin']
……

注,大家可以看到现在默认的Kickstart文件是sample.ks,现在我就来修改一下设置Kickstart文件文件为我们手动修改的Kickstart文件。

[[email protected] ~]# cobbler profile edit --name=CentOS-5.5-x86_64 --distro=CentOS-5.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos.ks
[[email protected] ~]# cobbler report
注,上面一些内容省略。
profiles: 
========== 
Name              : CentOS-5.5-x86_64 
TFTP Boot Files        : {} 
Comment            :  
DHCP Tag            : default 
Distribution          : CentOS-5.5-x86_64 
Enable gPXE?          : 0 
Enable PXE Menu?        : 1 
Fetchable Files        : {} 
Kernel Options         : {} 
Kernel Options (Post Install) : {} 
Kickstart           : /var/lib/cobbler/kickstarts/centos.ks
……

好了,大家可以看到现在使用的Kickstart文件是我们自定义的Kickstart文件了,客户端再安装系统就会使用的我们定义Kickstart文件去执行。到这里我们的自定义Kickstart文件就全部讲解完成,最后我们来讲解一个案例来结束我们本篇博客。


六、Cobbler 实战案例安装CentOS6.4

1.实验拓扑

Linux 运维自动化之Cobbler实战案例

2.安装yum源

[[email protected] ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.N9dqlP: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY 
Preparing...        ########################################### [100%] 
  1:epel-release      ########################################### [100%]

3.同步系统时间

[[email protected] ~]# yum install -y ntp
[[email protected] ~]# ntpdate 202.120.2.101 
13 Nov 15:14:52 ntpdate[1174]: step time server 202.120.2.101 offset -28799.776629 sec 
[[email protected] ~]# hwclock -w

4.安装Cobbler基础包

[[email protected] ~]# yum install -y cobbler tftp dhcp httpd cman pykickstart debmirror

5.安装Cobbler依赖包

[[email protected] ~]# yum install -y ed patch perl perl-Compress-Zlib perl-Digest-SHA1 perl-LockFile-Simple perl-libwww-perl

6.将所有服务加入开机自启动

[[email protected] ~]# chkconfig httpd on 
[[email protected] ~]# chkconfig dhcpd on 
[[email protected] ~]# chkconfig xinetd on 
[[email protected] ~]# chkconfig cobblerd on

7.修改httpd配置文件并启动httpd

[[email protected] ~]# vim /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1:80
[[email protected] ~]# service httpd start 
正在启动 httpd:                      [确定] 
[[email protected] ~]# netstat -ntulp | grep :80 
tcp    0   0 :::80            :::*            LISTEN   1525/httpd

8.启动Cobbler服务并执行检查命令

[[email protected] ~]# service cobblerd start 
Starting cobbler daemon:                  [确定] 
[[email protected] ~]# 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.

9.解决上述相关配置错误

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

[[email protected] ~]# vim /etc/cobbler/settings
server: 192.168.18.202

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

[[email protected] ~]# vim /etc/cobbler/settings
next_server: 192.168.18.202

(3).错误3,据说这个错误可以忽略,有强迫完美运行症的人士可以运行以下命令来解决;

[[email protected] ~]# cobbler get-loaders
task started: 2013-11-04_143149_get_loaders
task started (id=Download Bootloader Content, time=Mon Nov 4 14:31:49 2013)
downloading http://www.cobblerd.org/loaders/README to /var/lib/cobbler/loaders/README
downloading http://www.cobblerd.org/loaders/COPYING.elilo to/var/lib/cobbler/loaders/COPYING.elilo
downloading http://www.cobblerd.org/loaders/COPYING.yaboot to/var/lib/cobbler/loaders/COPYING.yaboot
downloading http://www.cobblerd.org/loaders/COPYING.syslinux to/var/lib/cobbler/loaders/COPYING.syslinux
downloading http://www.cobblerd.org/loaders/elilo-3.8-ia64.efi to/var/lib/cobbler/loaders/elilo-ia64.efi
downloading http://www.cobblerd.org/loaders/yaboot-1.3.14-12 to/var/lib/cobbler/loaders/yaboot
downloading http://www.cobblerd.org/loaders/pxelinux.0-3.61 to/var/lib/cobbler/loaders/pxelinux.0
downloading http://www.cobblerd.org/loaders/menu.c32-3.61 to /var/lib/cobbler/loaders/menu.c32
downloading http://www.cobblerd.org/loaders/grub-0.97-x86.efi to/var/lib/cobbler/loaders/grub-x86.efi
downloading http://www.cobblerd.org/loaders/grub-0.97-x86_64.efi to/var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***

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

[[email protected] ~]# vim /etc/xinetd.d/tftp
disable     = no
[[email protected] ~]# vim /etc/xinetd.d/rsync
disable = no

注,启动xinetd服务。

[[email protected] ~]# service xinetd start
正在启动 xinetd:           [确定]

(5).错误5与错误6,debmmirror有错误;

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

(6).错误7,设置默认root密码;

注,刚接触Cobbler的博友会问,这个密码是什么密码。有的博友系统安装好了会问,root密码是什么。这里设置的就是客户端安装好系统的root密码。

注,生成你想要的密码的加密字符串,然后复制运行命令之后的加密代码;

[[email protected] ~]# openssl passwd -1 -salt 'hahaha' '123456'
$1$hahaha$hSxFjZSHRoiEn4DYrrGUI.

注,然后替换/etc/cobbler/settings 中选项双引号中的加密代码;

[[email protected] ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$hahaha$hSxFjZSHRoiEn4DYrrGUI."

10.重新启动Cobbler并运行检查命令

[[email protected] ~]# service cobblerd restart
Stopping cobbler daemon:         [确定]
Starting cobbler daemon:         [确定]
[[email protected] ~]# cobbler check 
The following are potential configuration items that you may want to fix:
1 : service dhcpd is not running
Restart cobblerd and then run 'cobbler sync' to apply changes.

11.修改DHCP模板

[[email protected] ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.18.0 netmask 255.255.255.0 { 
   option routers       192.168.18.254; 
   option domain-name-servers 192.168.18.254; 
   option subnet-mask     255.255.255.0; 
   range dynamic-bootp    192.168.18.221 192.168.18.225; 
   filename          "/pxelinux.0"; 
   default-lease-time     21600; 
   max-lease-time       43200; 
   next-server        $next_server;

12.执行一下同步操作并检查配置文件

[[email protected] ~]# cobbler sync 
task started: 2013-11-13_153610_sync 
task started (id=Sync, time=Wed Nov 13 15:36:10 2013) 
running pre-sync triggers 
cleaning trees 
mkdir: /var/lib/tftpboot/pxelinux.cfg 
mkdir: /var/lib/tftpboot/grub 
mkdir: /var/lib/tftpboot/s390x 
mkdir: /var/lib/tftpboot/ppc 
mkdir: /var/lib/tftpboot/etc 
removing: /var/lib/tftpboot/grub/p_w_picpaths 
copying bootloaders 
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32 
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot 
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk 
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi 
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi 
copying distros to tftpboot 
copying p_w_picpaths 
generating PXE configuration files 
generating PXE menu structure 
rendering DHCP files 
generating /etc/dhcp/dhcpd.conf 
rendering TFTPD files 
generating /etc/xinetd.d/tftp 
cleaning link caches 
running post-sync triggers 
running python triggers from /var/lib/cobbler/triggers/sync/post/* 
running python trigger cobbler.modules.sync_post_restart_services 
running: dhcpd -t -q 
received on stdout:  
received on stderr:  
running: service dhcpd restart 
received on stdout: 正在启动 dhcpd:[确定]
received on stderr: 
running shell triggers from /var/lib/cobbler/triggers/sync/post/* 
running python triggers from /var/lib/cobbler/triggers/change/* 
running python trigger cobbler.modules.scm_track 
running shell triggers from /var/lib/cobbler/triggers/change/* 
*** TASK COMPLETE ***
[[email protected] ~]# cobbler check 
No configuration problems found. All systems go.

好了,到这里我们Cobbler安装就全部完成了,最后我们来重新启动一下xinetd并查看一下启动的端口。

[[email protected] ~]# service xinetd restart 
停止 xinetd:                       [确定] 
正在启动 xinetd: 
                              [确定]
[[email protected] ~]# netstat -ntulp 
Active Internet connections (only servers) 
Proto Recv-Q Send-Q Local Address        Foreign Address       State    PID/Program name 
tcp    0   0 0.0.0.0:22         0.0.0.0:*          LISTEN   1010/sshd     
tcp    0   0 127.0.0.1:25        0.0.0.0:*          LISTEN   1087/master    
tcp    0   0 127.0.0.1:6010       0.0.0.0:*          LISTEN   1125/sshd     
tcp    0   0 127.0.0.1:6011       0.0.0.0:*          LISTEN   1478/sshd     
tcp    0   0 127.0.0.1:25151       0.0.0.0:*          LISTEN   1643/python    
tcp    0   0 :::80            :::*            LISTEN   1525/httpd    
tcp    0   0 :::22            :::*            LISTEN   1010/sshd     
tcp    0   0 ::1:25           :::*            LISTEN   1087/master    
tcp    0   0 ::1:6010          :::*            LISTEN   1125/sshd     
tcp    0   0 ::1:6011          :::*            LISTEN   1478/sshd     
tcp    0   0 :::873           :::*            LISTEN   1777/xinetd    
udp    0   0 0.0.0.0:67         0.0.0.0:*                1715/dhcpd    
udp    0   0 0.0.0.0:69         0.0.0.0:*                1777/xinetd    
udp    0   0 0.0.0.0:69         0.0.0.0:*                1618/in.tftpd

13.导入CentOS6.4镜像文件

Linux 运维自动化之Cobbler实战案例

[[email protected] ~]# mount /dev/cdrom /mnt 
mount: block device /dev/sr0 is write-protected, mounting read-only 
[[email protected] ~]# cd /mnt/ 
[[email protected] mnt]# ls 
CentOS_BuildTag GPL    Packages         RPM-GPG-KEY-CentOS-6      RPM-GPG-KEY-CentOS-Testing-6 
EFI       p_w_picpaths  RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Debug-6   TRANS.TBL 
EULA       isolinux repodata         RPM-GPG-KEY-CentOS-Security-6
[[email protected] ~]# cobbler import --path=/mnt/ --name=CentOS-6.4 --arch=x86_64 
task started: 2013-11-13_154155_import 
task started (id=Media import, time=Wed Nov 13 15:41:55 2013) 
Found a candidate signature: breed=redhat, version=rhel6 
Found a matching signature: breed=redhat, version=rhel6 
Adding distros from path /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64: 
creating new distro: CentOS-6.4-x86_64 
trying symlink: /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64 -> /var/www/cobbler/links/CentOS-6.4-x86_64 
creating new profile: CentOS-6.4-x86_64 
associating repos 
checking for rsync repo(s) 
checking for rhn repo(s) 
checking for yum repo(s) 
starting descent into /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64 for CentOS-6.4-x86_64 
processing repo at : /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64 
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64 
looking for /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64/repodata/*comps*.xml 
running: createrepo -c cache -s sha --groupfile /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64/repodata/2727fcb43fbe4c1a3588992af8c19e4d97167aee2f6088959221fc285cab6f72-c6-x86_64-comps.xml /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64 
received on stdout: Spawning worker 0 with 3955 pkgs 
Workers Finished 
Gathering worker results
Saving Primary metadata 
Saving file lists metadata 
Saving other metadata 
Generating sqlite DBs 
Sqlite DBs complete
received on stderr: 
*** TASK COMPLETE ***
[[email protected] ~]# cobbler list 
distros: 
  CentOS-6.4-x86_64
profiles: 
  CentOS-6.4-x86_64
systems:
repos:
p_w_picpaths:
mgmtclasses:
packages:
files:

14.查看一下导入镜像的详细信息

[[email protected] ~]# cobbler report 
distros: 
========== 
Name              : CentOS-6.4-x86_64 
Architecture          : x86_64 
TFTP Boot Files        : {} 
Breed             : redhat 
Comment            :  
Fetchable Files        : {} 
Initrd             : /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64/p_w_picpaths/pxeboot/initrd.img 
Kernel             : /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64/p_w_picpaths/pxeboot/vmlinuz 
Kernel Options         : {} 
Kernel Options (Post Install) : {} 
Kickstart Metadata       : {'tree': 'http://@@[email protected]@/cblr/links/CentOS-6.4-x86_64'}
Management Classes       : [] 
OS Version           : rhel6 
Owners             : ['admin'] 
Red Hat Management Key     : <<inherit>> 
Red Hat Management Server   : <<inherit>> 
Template Files         : {}
profiles: 
========== 
Name              : CentOS-6.4-x86_64 
TFTP Boot Files        : {} 
Comment            :  
DHCP Tag            : default 
Distribution          : CentOS-6.4-x86_64 
Enable gPXE?          : 0 
Enable PXE Menu?        : 1 
Fetchable Files        : {} 
Kernel Options         : {} 
Kernel Options (Post Install) : {} 
Kickstart           : /var/lib/cobbler/kickstarts/sample_end.ks 
Kickstart Metadata       : {} 
Management Classes       : [] 
Management Parameters     : <<inherit>> 
Name Servers          : [] 
Name Servers Search Path    : [] 
Owners             : ['admin'] 
Parent Profile         :  
Proxy             :  
Red Hat Management Key     : <<inherit>> 
Red Hat Management Server   : <<inherit>> 
Repos             : [] 
Server Override        : <<inherit>> 
Template Files         : {} 
Virt Auto Boot         : 1 
Virt Bridge          : xenbr0 
Virt CPUs           : 1 
Virt Disk Driver Type     : raw 
Virt File Size(GB)       : 5 
Virt Path           :  
Virt RAM (MB)         : 512 
Virt Type           : kvm
systems: 
==========
repos: 
==========
p_w_picpaths: 
==========
mgmtclasses: 
==========
packages: 
==========
files: 
==========

15.自定义kickstart文件

[[email protected] ~]# cd /var/lib/cobbler/kickstarts/ 
[[email protected] kickstarts]# cp sample_end.ks centos6.ks 
[[email protected] kickstarts]# vim centos6.ks
# kickstart template for Fedora 8 and later. 
# (includes %end blocks) 
# do not use with earlier distros
#platform=x86, AMD64, or Intel EM64T 
# System authorization information 
auth --useshadow --enablemd5 
# System bootloader configuration 
bootloader --location=mbr 
# Partition clearing information 
clearpart --all --initlabel 
# Use text mode install 
text 
# Firewall configuration 
firewall --service=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 
# Network information 
$SNIPPET('network_config') 
# Reboot after installation 
reboot
#Root password 
rootpw --iscrypted $default_password_crypted 
# SELinux configuration 
selinux --disabled 
# 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 
# Allow anaconda to partition the system as needed 
part /boot --fstype=ext4 --size=200 
part / --fstype=ext4 --size=10000 
part /data --fstype=ext4 --size=5000 
part swap --size=1000
%pre 
$SNIPPET('log_ks_pre') 
$SNIPPET('kickstart_start') 
$SNIPPET('pre_install_network_config') 
# Enable installation monitoring 
$SNIPPET('pre_anamon') 
%end
%packages 
@chinese-support 
@development 
$SNIPPET('func_install_if_enabled') 
%end
%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('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 
%end

16.将自定义的kickstart文件与镜像相关联

[[email protected] ~]# cobbler profile edit --name=CentOS-6.4-x86_64 --distro=CentOS-6.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.ks
[[email protected] ~]# cobbler report 
注,上面部分省略。 
profiles: 
========== 
Name              : CentOS-6.4-x86_64 
TFTP Boot Files        : {} 
Comment            :  
DHCP Tag            : default 
Distribution          : CentOS-6.4-x86_64 
Enable gPXE?          : 0 
Enable PXE Menu?        : 1 
Fetchable Files        : {} 
Kernel Options         : {} 
Kernel Options (Post Install) : {} 
Kickstart           : /var/lib/cobbler/kickstarts/centos6.ks

17.同步一下

[[email protected] ~]# cobbler sync 
task started: 2013-11-13_163907_sync 
task started (id=Sync, time=Wed Nov 13 16:39:07 2013) 
running pre-sync triggers 
cleaning trees 
removing: /var/www/cobbler/p_w_picpaths/CentOS-6.4-x86_64 
removing: /var/lib/tftpboot/pxelinux.cfg/default 
removing: /var/lib/tftpboot/grub/grub-x86_64.efi 
removing: /var/lib/tftpboot/grub/p_w_picpaths 
removing: /var/lib/tftpboot/grub/efidefault 
removing: /var/lib/tftpboot/grub/grub-x86.efi 
removing: /var/lib/tftpboot/p_w_picpaths/CentOS-6.4-x86_64 
removing: /var/lib/tftpboot/s390x/profile_list 
copying bootloaders 
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi 
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi 
copying distros to tftpboot 
copying files for distro: CentOS-6.4-x86_64 
trying hardlink /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64/p_w_picpaths/pxeboot/vmlinuz -> /var/lib/tftpboot/p_w_picpaths/CentOS-6.4-x86_64/vmlinuz 
trying hardlink /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64/p_w_picpaths/pxeboot/initrd.img -> /var/lib/tftpboot/p_w_picpaths/CentOS-6.4-x86_64/initrd.img 
copying p_w_picpaths 
generating PXE configuration files 
generating PXE menu structure 
copying files for distro: CentOS-6.4-x86_64 
trying hardlink /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64/p_w_picpaths/pxeboot/vmlinuz -> /var/www/cobbler/p_w_picpaths/CentOS-6.4-x86_64/vmlinuz 
trying hardlink /var/www/cobbler/ks_mirror/CentOS-6.4-x86_64/p_w_picpaths/pxeboot/initrd.img -> /var/www/cobbler/p_w_picpaths/CentOS-6.4-x86_64/initrd.img 
Writing template files for CentOS-6.4-x86_64 
rendering DHCP files 
generating /etc/dhcp/dhcpd.conf 
rendering TFTPD files 
generating /etc/xinetd.d/tftp 
cleaning link caches 
running post-sync triggers 
running python triggers from /var/lib/cobbler/triggers/sync/post/* 
running python trigger cobbler.modules.sync_post_restart_services 
running: dhcpd -t -q 
received on stdout:  
received on stderr:  
running: service dhcpd restart 
received on stdout: 关闭 dhcpd:[确定] 
正在启动 dhcpd:[确定]
received on stderr: 
running shell triggers from /var/lib/cobbler/triggers/sync/post/* 
running python triggers from /var/lib/cobbler/triggers/change/* 
running python trigger cobbler.modules.scm_track 
running shell triggers from /var/lib/cobbler/triggers/change/* 
*** TASK COMPLETE ***

18.新建客户端虚拟机

Linux 运维自动化之Cobbler实战案例

19.启动客户端并进行系统安装

(1).选择 “CentOS-6.4-x86_64”进行安装。

Linux 运维自动化之Cobbler实战案例

(2).选择后直接回车进行安装。

Linux 运维自动化之Cobbler实战案例

(3).开始安装初始化

Linux 运维自动化之Cobbler实战案例

(4).安装相关软件包

Linux 运维自动化之Cobbler实战案例

(5).软件包安装完成,大概过1分钟后进行重启

Linux 运维自动化之Cobbler实战案例

(6).重新启动虚拟机客户端

Linux 运维自动化之Cobbler实战案例

Linux 运维自动化之Cobbler实战案例Linux 运维自动化之Cobbler实战案例

(8).进入登录界面

Linux 运维自动化之Cobbler实战案例

20.下面我们对客户端安装系统进行登录测试并查看

(1).输入用户名root与密码123456进行登录测试

Linux 运维自动化之Cobbler实战案例

(2).查看自定义的分区与时区

Linux 运维自动化之Cobbler实战案例

好了,到这里我们Linux运维自化工具之Cobbler工具就全部讲解完成了,最后希望大家有所收获吧!^_^……