运维自动化之cobbler部署


cobbler介绍

Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便,使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP,DNS,以及yum包镜像。

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

  • 优点: 和Kickstart不同的是,使用cobbler不会因为在局域网中启动了dhcp而导致有些机器因为默认从pxe启动在重启服务器后加载tftp内容导致启动终止

cobbler常用架构

69762665-file_1492598575741_15f4e.png

cobbler安装部署配置

环境说明
本次实验环境如下
[root@cobbler ~]# cat /etc/redhat-release   
CentOS Linux release 7.3.1611 (Core)   
[root@cobbler ~]# uname -r  
3.10.0-514.el7.x86_64
关闭防火墙和SElinux
[root@cobbler ~]# sed -i 's@^SELINUX=.*@SELINUX=disabled@g' /etc/selinux/config
[root@cobbler ~]# setenforce 0
[root@cobbler ~]# systemctl stop firewalld
[root@cobbler ~]# iptables -F
[root@cobbler ~]# iptables -Z
[root@cobbler ~]# iptables -X
  • cobbler服务器地址为10.0.0.128

cobbler安装
使用阿里epel源
[root@cobbler ~]# cd /server/tools/
[root@cobbler tools]# rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
[root@cobbler tools]# rpm -qa epel-release
安装cobbler及相关依赖软件
[root@cobbler tools]# yum -y install httpd dhcp tftp bind bind-chroot caching-nameserver python-ctypes cobbler cobbler-web pykickstart xinetd
[root@cobbler ~]# rpm -ql cobbler  #查看安装的文件{部分}
/etc/cobbler                 #配置文件目录
/etc/cobbler/dhcp.template   #dncp服务配置模版
/etc/cobbler/dnsmasq.template   #dns服务配置模版
/etc/cobbler/iso             #iso模版配置文件目录
/etc/cobbler/modules.conf    #cobbler模块配置文件
/etc/cobbler/power           #电源管理配置文件目录
/etc/cobbler/pxe             #pxe模板文件目录
/etc/cobbler/rsync.template  #rsync服务配置模板
/etc/cobbler/settings        #主配置文件
/etc/cobbler/tftpd.template  #ftp服务配置模版
/etc/cobbler/users.conf      #web服务授权配置文件
/etc/cobbler/users.digest    #web访问用户名密码配置文件
/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日志

######启动aoache和cobbler
[root@cobbler ~]# systemctl start httpd
[root@cobbler ~]# systemctl start cobblerd
[root@cobbler ~]# systemctl enable httpd
[root@cobbler ~]# systemctl enable cobblerd
[root@cobbler ~]# yum -y install net-tools    #安装netstat命令
[root@cobbler ~]# netstat -ntlpua|grep httpd
tcp6   0  0 :::80   :::*LISTEN  2329/httpd
tcp6   0  0 :::443  :::*LISTEN  2329/httpd
[root@cobbler ~]#  ps -ef|grep cobbler
apache 2330   2329  0 11:05 ?00:00:00 (wsgi:cobbler_w -DFOREGROUND
root   2359  1  0 11:06 ?00:00:00 /usr/bin/python2 -s /usr/bin/cobblerd -F
root   2481   2064  0 11:10 pts/000:00:00 grep --color=auto cobbler
配置cobbler

运行cobbler check,根据显示提示,进行下一步操作

[root@cobbler ~]# 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 otherthan 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctlyin your SELinux environment:
https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' todownload 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 : enable and start rsyncd.service with systemctl
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : ksvalidator was not found, install pykickstart
9 : 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 : 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. cobbler配置文件settings

  2. tftp配置文件

  3. cobbler get-loaders

  4. start rsyncd.service

  5. 设置系统的默认root密码

修改过程如下

每次对cobbler相关配置文件的修改,都需要cobbler sync,才能使设置的参数生效

修改cobbler配置文件
[root@cobbler ~]# cp /etc/cobbler/settings{,.ori}
[root@cobbler ~]# sed -i 's#next_server: 127.0.0.1#next_server: 10.10.10.128#g' /etc/cobbler/settings
[root@cobbler ~]# sed -i 's#server: 127.0.0.1#server: 10.10.10.128#g' /etc/cobbler/settings
修改tftp文件,设置开启使用
[root@cobbler tools]# sed -i 's@disable.*=.*@disable = no@g' /etc/xinetd.d/tftp
[root@cobbler ~]# grep disable /etc/xinetd.d/tftp
    disable = no
[root@cobbler ~]# systemctl start xinetd
[root@cobbler ~]# lsof -i udp:69
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
xinetd  11384 root5u  IPv4  31162  0t0  UDP *:tftp
设置cobbler密码
[root@cobbler ~]# openssl passwd -1 -salt 'cobbler' 'cobbler'
$1$cobbler$M6SE55xZodWc9.vAKLJs6.
[root@cobbler ~]# vim /etc/cobbler/settings
101 default_password_crypted: "$1$cobbler$M6SE55xZodWc9.vAKLJs6."
让cobbler管理dhcp
 [root@cobbler ~]# vim /etc/cobbler/settings 
 242 manage_dhcp: 1
防止循环安装系统,适用于服务器第一启动项是PXE启动
sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
启动rsync
[root@cobbler ~]# systemctl start rsyncd
[root@cobbler ~]# lsof -i :873
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rsync   11481 root4u  IPv4  31490  0t0  TCP *:rsync (LISTEN)
rsync   11481 root5u  IPv6  31491  0t0  TCP *:rsync (LISTEN)
修改cobbler的dhcp模版
[root@cobbler tools]# vim /etc/cobbler/dhcp.template
注意:
1、所分配的地址必须和服务器在同一个网段内
2、不要直接修改dhcp本身的配置文件,因为cobbler会覆盖
subnet 10.10.10.0 netmask 255.255.255.0 {
 option routers 10.10.10.1;
 option domain-name-servers 233.5.5.5;
 option subnet-mask 255.255.255.0;
 range dynamic-bootp 10.10.10.100 10.10.10.120;
运行cobbler get-loaders

如果显示Could not resolve host,需检查dns

[root@cobbler ~]# cobbler get-loaders
task started: 2017-04-19_202510_get_loaders
task started (id=Download Bootloader Content, time=Wed Apr 19 20:25:10 2017)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
重启cobbler服务并执行cobbler sync 让所有修改生效
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# cobbler sync
task started: 2017-04-19_224801_sync
task started (id=Sync, time=Wed Apr 19 22:48:01 2017)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/p_w_picpaths
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
copying: /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying: /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
copying: /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.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:
received on stderr: Redirecting to /bin/systemctl restart  dhcpd.service

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 ***


[root@cobbler ~]# netstat -ntlupa|egrep "httpd|dhcpd|rsync|xinetd"
tcp0  0 0.0.0.0:873 0.0.0.0:*   LISTEN  11481/rsync
tcp6   0  0 :::80   :::*LISTEN  11280/httpd
tcp6   0  0 :::443  :::*LISTEN  11280/httpd
tcp6   0  0 :::873  :::*LISTEN  11481/rsync
udp0  0 0.0.0.0:55026   0.0.0.0:*   11644/dhcpd
udp0  0 0.0.0.0:67  0.0.0.0:*   11644/dhcpd
udp0  0 0.0.0.0:69  0.0.0.0:*   11384/xinetd
udp6   0  0 :::19187:::*11644/dhcpd
[root@cobbler ~]#
设置开机启动
systemctl enable httpd.service
systemctl enable xinetd.service
systemctl enable cobblerd.service
systemctl enable dhcpd.service
systemctl enable rsyncd.service

导入系统镜像{重点}

导入centos7的镜像

插入centos7的光盘或镜像 插入的系统光盘要是bin即DVD的4G镜像

[root@localhost ~]# cobbler import --path=/mnt/ --name=CentOS7.3_x86_64 --arch=x86_64
task started: 2017-04-19_230926_import
task started (id=Media import, time=Wed Apr 19 23:09:26 2017)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/CentOS-7-x86_64:
creating new distro: CentOS-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-7-x86_64 -> /var/www/cobbler/links/CentOS-7-x86_64
creating new profile: CentOS-7-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-7-x86_64 for CentOS-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata
*** TASK COMPLETE ***

说明:

#<== --path 镜像路径
#<== --name 为安装源定义一个名字
#<== --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
#<== 安装源的唯一标识就是根据name参数来定义,本例导入成功后,安装源的唯一标识就是:CentOS-7.1-x86_64,如果重复,系统会提示导入失败。
*** TASK COMPLETE ***               #<==导入完成的标志
导入centos6的镜像

插入centos6的光盘或镜像, 插入的系统光盘要是bin即DVD的4G镜像

[root@localhost ~]# umount /mnt/
[root@localhost ~]# mount /dev/cdrom /mnt/
[root@localhost ~]# cobbler import --path=/mnt/ --name=CentOS6.8_x86_64 --arch=x86_64
task started: 2017-04-19_231649_import
task started (id=Media import, time=Wed Apr 19 23:16:49 2017)
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/CentOS6.8_x86_64-x86_64:
creating new distro: CentOS6.8-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS6.8_x86_64-x86_64 -> /var/www/cobbler/links/CentOS6.8-x86_64
creating new profile: CentOS6.8-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/CentOS6.8_x86_64-x86_64 for CentOS6.8-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS6.8_x86_64-x86_64
directory /var/www/cobbler/ks_mirror/CentOS6.8_x86_64-x86_64 is missing xml comps file, skipping
*** TASK COMPLETE ***
查看导入的系统文件
[root@localhost ~]#  ls /var/www/cobbler/ks_mirror
CentOS6.8_x86_64-x86_64  CentOS-7-x86_64  config
查看cobbler已经导入的内容
[root@localhost ~]# cobbler profile list
   CentOS-7-x86_64
   CentOS6.8-x86_64

镜像存放目录,cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/ksmirror下的CentOS-6.7-x8664目录下。因此/var/www/cobbler目录必须具有足够容纳安装文件的空间

删除已导入的文件(一般不要操作)
[root@cobbler kickstarts]# cobbler profile remove --name CentOS-7-x86_64
[root@cobbler kickstarts]# cobbler profile list
   CentOS6.8-x86_64
   CentOS7.3-x86_64
[root@cobbler kickstarts]#
cobbler常用命令
cobbler check    #<==核对当前设置是否有问题
cobbler list     #<==列出所有的cobbler元素
cobbler report   #<==列出元素的详细信息
cobbler sync     #<==同步配置到数据目录,更改配置最好都要执行下
cobbler reposync #<==同步yum仓库
cobbler distro   #<==查看导入的发行版系统信息
cobbler system   #<==查看添加的系统信息
cobbler profile  #<==查看配置信息
[root@cobbler-node1 ~]# cobbler profile
usage
=====
cobbler profile add
cobbler profile copy
cobbler profile dumpvars
cobbler profile edit
cobbler profile find
cobbler profile getks
cobbler profile list   #查看已导入的内容
cobbler profile remove  #删除已导入的内容
cobbler profile rename
cobbler profile report
查看ks文件内容

以下实验均按照次ks文件内容操作

[root@cobbler kickstarts]# pwd
/var/lib/cobbler/kickstarts  #该文件下还有许多模版可以参考
[root@cobbler ~]# vim /var/lib/cobbler/kickstarts/centos6.8-ks.cfg

# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --asprimary --fstype="ext4" --size=200 --ondisk sda
part swap --asprimary --fstype="swap" --size=1024 --ondisk sda
part / --asprimary --fstype="ext4" --grow --size=1 --ondisk sda

%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 --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('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
指定一个自定义ks.cfg文件

请参照规范将文件放到/var/lib/cobbler/kickstarts目录下,然后执行如下操作

[root@localhost kickstarts]# cobbler profile edit --name=CentOS6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS6.8_x86_64.cfg
[root@localhost kickstarts]# cobbler sync
说明:上边仅仅是个栗子!!!【ks文件需要自己修改上传】
查看安装镜像文件信息
[root@localhost ~]# cobbler distro report --name=CentOS6.8-x86_64
Name   : CentOS6.8-x86_64
Architecture   : x86_64
TFTP Boot Files: {}
Breed  : redhat
Comment:
Fetchable Files: {}
Initrd : /var/www/cobbler/ks_mirror/CentOS6.8_x86_64-x86_64/p_w_picpaths/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/CentOS6.8_x86_64-x86_64/p_w_picpaths/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS6.8-x86_64'}
Management Classes : []
OS Version : rhel6
Owners : ['admin']
Red Hat Management Key : <<inherit>>
Red Hat Management Server  : <<inherit>>
Template Files : {}
至此就可以其他服务器就可以通过已pxe启动来安装系统了。

841eb02cb19d849e.png

修改图片中的http连接地址
[root@localhost ~]# vim /etc/cobbler/pxe/pxedefault.template
MENU TITLE Cobbler | http://cobbler.yanqi.io/
[root@localhost ~]# cobbler sync

其他重要配置选项

定制化安装

如何指定某台服务器使用指定ks文件? 区分一台服务器的最简单的方法就是物理MAC地址。物理服务器的MAC地址在服务器上的标签上写了。虚拟机的MAC查看如下:

a5fb15081165e995.png

[root@localhost ~]# cobbler system add --name=yanqi --mac=00:0C:29:4C:56:7D --profile=CentOS6.8-x86_64  --ip-address=10.10.10.111 --subnet=255.255.255.0 --gateway=10.10.10.100 --interface=eth0 --static=1 --hostname=yanqi.cobbler.com --name-servers="233.5.5.5 8.8.8.8" --kickstart=/var/lib/cobbler/kickstarts/sample.ks
[root@localhost ~]# cobbler system list
   yanqi
[root@localhost ~]# cobbler sync

[root@localhost ~]# tailf -12 /etc/dhcp/dhcpd.conf
group {
host generic1 {
hardware ethernet 00:0C:29:4C:56:7D;
fixed-address 10.10.10.111;
option host-name "yanqi.cobbler.com";
option subnet-mask 255.255.255.0;
option routers 10.10.10.100;
filename "/pxelinux.0";
next-server 10.10.10.128;
}
}

此时客户机,从pxe网络启动,将会自动的安装指定的系统,不需要任何选择。

cobbler的Web管理界面的安装与配置

https://10.10.10.128/cobbler_web

dcf94b1f3f473e75.png9b771ac792af7afe.png778917d682806416.png77400f966b92873f.png

修改cobbler页面的密码
[root@cobbler ~]# htdigest /etc/cobbler/users.digest "cobbler" cobbler
Adding user cobbler in realm cobbler
New password:
Re-type new password:
[root@cobbler ~]# cobbler sync
自动重装系统

注意此步在客户机上进行操作,客户端如果没能下载请使用阿里的yum源。

查看cobbler能重装的系统

[root@localhost ~]# koan --server=10.10.10.128 --list=profiles
- looking for Cobbler at http://10.10.10.128:80/cobbler_api
CentOS6.8_bin-x86_64
CentOS7.3-x86_64
CentOS6.8-x86_64
[root@localhost ~]# koan --replace-self --server=10.10.10.128 --profile=CentOS6.8_bin-x86_64
[root@localhost ~]# cat /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#  all kernel and initrd paths are relative to /boot/, eg.
#  root (hd0,0)
#  kernel /vmlinuz-version ro root=/dev/sda3
#  initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashp_w_picpath=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title kick1492939789
    root (hd0,0)
    kernel /vmlinuz_koan ro rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=autoKEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet ks=http://10.10.10.128/cblr/svc/op/ks/profile/CentOS6.8_bin-x86_64 ksdevice=link kssendmac lang= text
    initrd /initrd.img_koan
title CentOS 6 (2.6.32-642.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=UUID=eb31b204-ddf5-4339-9603-a76b05141fb2 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
    initrd /initramfs-2.6.32-642.el6.x86_64.img

重启后,就会自动重装系统

自定义yum源
1.添加repo
[root@cobbler ~]# cobbler repo add --name=openstack-mitaka --mirror=http://mirrors.aliyun.com/centos/7.3.1611/cloud/x86_64/openstack-mitaka/ --arch=x86_64 --breed=yum
2.同步repo
[root@cobbler ~]# cobbler reposy

nc    3.添加repo到对应的profile    [root@cobbler pxe]# cobbler profile list    [root@cobbler pxe]# cobbler profile edit --name=CentOS7.3-x86_64  --repos="openstack-mitaka"

4.修改kickstart文件,添加如下。
[root@cobbler ~]# vi /var/lib/cobbler/kickstarts/centos7.3-ks.cfg
%post
添加这个,将将把yum库添加进去
$yum_config_stanza
%end

下次再安装系统后,openstack源地址就会指向该cobbler。

使用API的小例子
#!/usr/bin/env python
import xmlrpclib
server = xmlrpclib.Server("http://10.0.0.201/cobbler_api")
print server.get_distros()
print server.get_profiles()
print server.get_systems()
print server.get_p_w_picpaths()
print server.get_repos()
安装过程中遇到的错误

1、客户端安装koan

[root@localhost ~]# yum -y install koan
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.163.com
Error: xz compression not available

原因:该客户端的系统为centos6.8,大意安装了centos7的epel,解决方法:

[root@localhost ~]# yum remove epel-release  #卸载epel源
[root@localhost ~]# rm -rf /var/cache/yum/x86_64/6/epel/   #清理epel 缓存
[root@localhost ~]# rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm
[root@localhost ~]# yum -y install koan    #可以安装了