学习cobbler的话,必须先搞懂kickstart,原理不是,不懂如何排错。
kickstart部署请点击这里

1. Cobbler介绍

Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。

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

Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。

Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
cobbler官网

1.1 Cobbler集成的服务

  • PXE服务支持

  • DHCP服务管理

  • DNS服务管理(可选bind,dnsmasq)

  • 电源管理

  • Kickstart服务支持

  • YUM仓库管理

  • TFTP(PXE启动时需要)

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

1.2 系统环境准备

[root@CentOS6 ~]# cat /etc/redhat-releaseCentOS release 6.8 (Final)
[root@CentOS6 ~]# uname -r2.6.32-642.el6.x86_64[root@CentOS6 ~]# getenforceDisabled[root@CentOS6 ~]# /etc/init.d/iptables statusiptables: Firewall is not running.
[root@CentOS6 ~]# ifconfig eth0|awk -F "[ :]+" 'NR==2 {print $4}'10.0.0.101[root@CentOS6 ~]# hostnameCentOS6[root@CentOS6 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

注意:

  • 虚拟机网卡采用NAT模式,不要使用桥接模式,因为稍后我们会搭建DHCP服务器,在同一局域网多个DHCP服务会有冲突。

  • VMware的NAT模式的dhcp服务也关闭,避免干扰。

2.1 安装Cobbler

需要epel源

[root@CentOS6 ~]# yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd
[root@CentOS6 ~]# rpm -ql cobbler  # 查看安装的文件,下面列出部分。/etc/cobbler                  # 配置文件目录/etc/cobbler/settings         # cobbler主配置文件,这个文件是YAML格式,Cobbler是python写的程序。/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模块配置文件/var/lib/cobbler              # Cobbler数据目录/var/lib/cobbler/config       # 配置文件/var/lib/cobbler/kickstarts   # 默认存放kickstart文件/var/lib/cobbler/loaders      # 存放的各种引导程序/var/www/cobbler              # 系统安装镜像目录/var/www/cobbler/ks_mirror    # 导入的系统镜像列表/var/www/cobbler/p_w_picpaths       # 导入的系统镜像启动文件/var/www/cobbler/repo_mirror  # yum源存储目录/var/log/cobbler              # 日志目录/var/log/cobbler/install.log  # 客户端系统安装日志/var/log/cobbler/cobbler.log  # cobbler日志

2.2 配置Cobbler

cobbler check

[root@CentOS6 ~]# cobbler checkThe 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/tftp4 : 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 : change 'disable' to 'no' in /etc/xinetd.d/rsync6 : file /etc/xinetd.d/rsync does not exist7 : debmirror package is not installed, it will be required to manage debian deployments and repositories8 : 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 one9 : 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.

解释一下9条内容

1.改变server的主机名2.第二是DHCP的next_server改成172.16.1.1013.改xined的tftp disable等于no4.5./etc/xinetd.d/rsync  也改成no6.bug,已经存在7.debin系统的源8.生成密码并设置openssl passwd -1 -salt9.fencing tools 高可用的硬件设备。

修改配置文件
命令直接复制粘贴即可

cp /etc/cobbler/settings{,.ori}                                                                                       #备份sed -i 's/server: 127.0.0.1/server: 172.16.1.101/' /etc/cobbler/settings                                               #服务端IPsed -i 's/next_server: 127.0.0.1/next_server: 172.16.1.101/' /etc/cobbler/settings                                     #服务端IPsed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings                                                         #dhcp只获取一次sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings                                                     #cobbler只执行一遍sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'oldboy' '123456'`\"#" /etc/cobbler/settings  #设置密码为123456sed -i 's#yes#no#' /etc/xinetd.d/rsync                                 #xinet 管理rsyncsed -i 's#yes#no#' /etc/xinetd.d/tftp                                  #xinet 管理tftpcobbler get-loaders                                                    #下载sed -i 's#192.168.1#172.16.1#g;22d;23d' /etc/cobbler/dhcp.template     # 修改dhcp配置文件cobbler sync                                                          #写入磁盘/etc/init.d/xinetd restart                                            #启动三个必须启动的服务。详情请看kickstart/etc/init.d/cobblerd restart/etc/init.d/httpd restartcobbler sync       #    修改配置文件等,没事就来一次。保证没事
CentOS-6.8-x86_64.cfg
# Cobbler for Kickstart Configurator for CentOS 6.8 by yao zhanginstall
url --url=$tree
text
lang en_US.UTF-8keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"$SNIPPET('network_config')
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw  --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype=ext4 --asprimary --size=200part swap --size=1024part / --fstype=ext4 --grow --asprimary --size=200firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot

%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')# Enable installation monitoring$SNIPPET('pre_anamon')
%end

%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
%end

%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%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

图片详解,ks配置文件请看上方

1.登录界面

1010036-20170412212118158-138802708.png

2.导入镜像,记得挂载光盘或者镜像文件

1010036-20170412212131548-1197072345.png

3.自定义KS配置文件。请看上方

1010036-20170412212145876-2116992879.png

4.创建一个全局变量

1010036-20170412212154861-1463108977.png

5.制作yum仓库

1010036-20170412212201361-2033092307.png

6.导入yum仓库并创建全局变量

1010036-20170412212227080-1088558608.png

7.创建system

1010036-20170412212309642-518822049.png
1010036-20170412212207970-1496152080.png

7.1.global

1010036-20170412212221392-808344607.png

7.2.创建网卡

1010036-20170412212233908-1843934427.png

7.3.制作第二张网卡

1010036-20170412212239939-1079512557.png

7.4.拷贝和查看ks配置文件

1010036-20170412213719626-2072280198.png

8.注意事项

1010036-20170412212252017-1367908530.png