cobbler自动化部署工具

  • cobbler简介

RHEL7默认提供的cobbler是2.6.9版本的,cobbler译文”补鞋匠“网络安装套件cobbler可以同时管理DHCP;DNS;YUM等,现在随便一家互联网公司机器数量成千上万,这个时候我们就不能那个U盘,或者光盘一台台的装,然后诞生了PXE+TFTP+DHCP+Kickstart(俗称PXE)然而PXE不能同时部署多种版本的系统,然而cobbler可以部署多种系统如centos5,6,7;redhat 5,6,7;cobbler还可以部署windows系统。该工具由python语言开发,支持web界面管理十分灵活。

PXE自动化部署参考:http://mictiger.blog.51cto.com/4854014/1577008

  • 配置yum源

cobbler centos源没有cobbler包组,它是由epel提供,但是其依赖的软件包又是centos所提供,所以我们配置centos,epel 两个yum源

[root@cobbler yum.repos.d]# cat aliyun.repo [epel]name=ailiyunbaseurl=http://mirrors.aliyun.com/epel/7/x86_64/enabled=1gpgcheck=0[centos]name=cobblerbaseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/enabled=1gpgcheck=0
  • 开始安装

[root@cobbler yum.repos.d]# yum install cobbler cobbler-web pykickstart debmirror [root@cobbler ~]# rpm -qi cobblerName        : cobblerVersion     : 2.6.9Release     : 1.el7Architecture: noarchInstall Date: Thu 20 Aug 2015 09:00:46 PM CSTGroup       : Applications/SystemSize        : 2177634License     : GPLv2+Signature   : RSA/SHA256, Wed 24 Jun 2015 04:36:07 AM CST, Key ID 6a2faea2352c64e5Source RPM  : cobbler-2.6.9-1.el7.src.rpmBuild Date  : Tue 23 Jun 2015 02:06:19 AM CSTBuild Host  : buildppc-02.phx2.fedoraproject.orgRelocations : (not relocatable)Packager    : Fedora ProjectVendor      : Fedora ProjectURL         : http://www.cobblerd.org/Summary     : Boot server configuratorDescription :Cobbler is a network install server.  Cobbler supports PXE, ISOvirtualized installs, and re-installing existing Linux machines.The last two modes use a helper tool, 'koan', that integrates withcobbler.  There is also a web interface 'cobbler-web'.  Cobbler'sadvanced features include importing distributions from DVDs and rsyncmirrors, kickstart templating, integrated yum mirroring, and built-inDHCP/DNS Management.  Cobbler has a XMLRPC API for integration withother applications.
  • 启动cobbler,httpd服务

[root@cobbler ~]# systemctl start httpd.service[root@cobbler ~]# systemctl start cobblerd.service

  • 关闭selinux

[root@cobbler ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:#     enforcing - SELinux security policy is enforced.#     permissive - SELinux prints warnings instead of enforcing.#     disabled - No SELinux policy is loaded.SELINUX=disabled# SELINUXTYPE= can take one of these two values:#     targeted - Targeted processes are protected,#     minimum - Modification of targeted policy. Only selected processes are protected. #     mls - Multi Level Security protection.SELINUXTYPE=targeted [root@cobbler ~]# getenforce Permissive  或者  Disabled[root@cobbler ~]# 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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:    https://github.com/cobbler/cobbler/wiki/Selinux4 : change 'disable' to 'no' in /etc/xinetd.d/tftp5 : 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 : 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 themRestart cobblerd and then run 'cobbler sync' to apply changes.

解决以上报告信息

  • 修改参数

修改 /etc/cobbler/settingsnext_server: 192.168.3.100server: 192.168.3.100[root@cobbler ~]# cobbler get-loaders如果网络不行可以直接去 http://cobbler.github.com/loaders/下载COPYING.elilo  COPYING.syslinux  COPYING.yaboot  elilo-ia64.efi  grub-x86_64.efi  grub-x86.efi  menu.c32  pxelinux.0  README  yaboot这些软件包[root@cobbler ~]# cobbler get-loaders task started: 2015-08-20_215034_get_loaderstask started (id=Download Bootloader Content, time=Thu Aug 20 21:50:34 2015)downloading http://cobbler.github.com/loaders/README to /var/lib/cobbler/loaders/README[root@cobbler ~]# yum install fence-agents cman注释/etc/debmirror.conf 中以下两项#@dists="sid";#@arches="i386";[root@cobbler ~]# openssl passwd -1 -salt `openssl rand -hex 4`Password: $1$a6a60411$ltytuO4WzxCYFOJhNFIlh1[root@cobbler ~]# vim /etc/cobbler/settings default_password_crypted: "$1$a6a60411$ltytuO4WzxCYFOJhNFIlh1"

检查是否配置完成

[root@cobbler ~]# cobbler checkNo configuration problems found.  All systems go.安装配置DHCP[root@cobbler ~]# yum install dhcp[root@cobbler loaders]# vim /etc/dhcp/dhcpd.conf default-lease-time  86400;max-lease-time	7200;log-facility local7;subnet	192.168.3.0 netmask 255.255.255.0 { range	192.168.3.105	192.168.3.120; option	routers 192.168.3.100;}next-server	192.168.3.100;filename="pxelinux.0";
  • 准备安装yum

[root@cobbler media]# mkdir centos6[root@cobbler media]# mkdir centos7[root@cobbler ~]# mount -o loop CentOS-6.6-x86_64-bin-DVD1.iso /media/centos6[root@cobbler ~]# mount -o loop CentOS-7.0-1406-x86_64-DVD.iso /media/centos7

安装system-config-kickstart 用于编写ks.cfg文件基于系统的anaconda-ks.cfg这个文件是本系统安装中的配置

[root@cobbler ~]# yum install  system-config-kickstart [root@cobbler ~]# system-config-kickstart

spacer.gif

  • 导入系统镜像

[root@cobbler ~]# cobbler import --name="centos6" --path=/media/centos6[root@cobbler ~]# cobbler distro list   centos6-x86_64[root@cobbler cobbler]# cobbler profile add --name=centos6.6 --distro=centos6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.cfg[root@cobbler cobbler]# cobbler profile list   centos6-x86_64   centos6.6

配置完成后一定要sync

[root@cobbler ~]# cobbler synctask started: 2015-08-22_011824_synctask started (id=Sync, time=Sat Aug 22 01:18:24 2015)running pre-sync triggerscleaning treesremoving: /var/www/cobbler/p_w_picpaths/centos6-x86_64removing: /var/lib/tftpboot/pxelinux.cfg/defaultremoving: /var/lib/tftpboot/grub/p_w_picpathsremoving: /var/lib/tftpboot/grub/grub-x86_64.efiremoving: /var/lib/tftpboot/grub/grub-x86.efiremoving: /var/lib/tftpboot/grub/efidefaultremoving: /var/lib/tftpboot/p_w_picpaths/centos6-x86_64removing: /var/lib/tftpboot/s390x/profile_listcopying bootloaderstrying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yabootcopying: /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboottrying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efitrying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.eficopying distros to tftpbootcopying files for distro: centos6-x86_64trying hardlink /var/www/cobbler/ks_mirror/centos6/p_w_picpaths/pxeboot/vmlinuz -> /var/lib/tftpboot/p_w_picpaths/centos6-x86_64/vmlinuztrying hardlink /var/www/cobbler/ks_mirror/centos6/p_w_picpaths/pxeboot/initrd.img -> /var/lib/tftpboot/p_w_picpaths/centos6-x86_64/initrd.imgcopying p_w_picpathsgenerating PXE configuration filesgenerating PXE menu structurecopying files for distro: centos6-x86_64trying hardlink /var/www/cobbler/ks_mirror/centos6/p_w_picpaths/pxeboot/vmlinuz -> /var/www/cobbler/p_w_picpaths/centos6-x86_64/vmlinuztrying hardlink /var/www/cobbler/ks_mirror/centos6/p_w_picpaths/pxeboot/initrd.img -> /var/www/cobbler/p_w_picpaths/centos6-x86_64/initrd.imgWriting template files for centos6-x86_64rendering TFTPD filesgenerating /etc/xinetd.d/tftpprocessing boot_files for distro: centos6-x86_64cleaning link cachesrunning post-sync triggersrunning python triggers from /var/lib/cobbler/triggers/sync/post/*running python trigger cobbler.modules.sync_post_restart_servicesrunning shell triggers from /var/lib/cobbler/triggers/sync/post/*running python triggers from /var/lib/cobbler/triggers/change/*running python trigger cobbler.modules.scm_trackrunning shell triggers from /var/lib/cobbler/triggers/change/**** TASK COMPLETE ***

查看是否配置成功

[root@cobbler cobbler]# cat /var/lib/tftpboot/pxelinux.cfg/default DEFAULT menuPROMPT 0MENU TITLE Cobbler | http://cobbler.github.comTIMEOUT 200TOTALTIMEOUT 6000ONTIMEOUT localLABEL local        MENU LABEL (local)        MENU DEFAULT        LOCALBOOT -1LABEL centos6-x86_64        kernel /p_w_picpaths/centos6-x86_64/vmlinuz        MENU LABEL centos6-x86_64        append initrd=/p_w_picpaths/centos6-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.3.100/cblr/svc/op/ks/profile/centos6-x86_64        ipappend 2LABEL centos6.6        kernel /p_w_picpaths/centos6-x86_64/vmlinuz        MENU LABEL centos6.6        append initrd=/p_w_picpaths/centos6-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.3.100/cblr/svc/op/ks/profile/centos6.6        ipappend 2

开始安装

spacer.gif

spacer.gif

spacer.gif

spacer.gif

spacer.gif

  • 配置cobbler安装Centos7

[root@cobbler ~]# cobbler import --name="centos7" --path=/media/centos7task started: 2015-08-22_014024_importtask started (id=Media import, time=Sat Aug 22 01:40:24 2015)Found a candidate signature: breed=redhat, version=rhel6Found a candidate signature: breed=redhat, version=rhel7Found a matching signature: breed=redhat, version=rhel7Adding distros from path /var/www/cobbler/ks_mirror/centos7:creating new distro: centos7-x86_64trying symlink: /var/www/cobbler/ks_mirror/centos7 -> /var/www/cobbler/links/centos7-x86_64creating new profile: centos7-x86_64associating reposchecking for rsync repo(s)checking for rhn repo(s)checking for yum repo(s)starting descent into /var/www/cobbler/ks_mirror/centos7 for centos7-x86_64processing repo at : /var/www/cobbler/ks_mirror/centos7need to process repo/comps: /var/www/cobbler/ks_mirror/centos7looking for /var/www/cobbler/ks_mirror/centos7/repodata/*comps*.xmlKeeping repodata as-is :/var/www/cobbler/ks_mirror/centos7/repodata*** TASK COMPLETE ***[root@cobbler ~]# cobbler distro list   centos6-x86_64   centos7-x86_64

出现以下问题是要将做好的ks移动到 /var/lib/cobbler/kickstarts/  这个路径是专门存放ks文件模板的

[root@cobbler ks]# cobbler profile add --distro="centos7-x86_64" --name=centos7 --kickstart=/root/ks/centos7.cfgexception on server: 'Invalid kickstart template file location /root/ks/centos7.cfg, it is not inside /var/lib/cobbler/kickstarts/'
[root@cobbler ks]# cobbler profile add --distro="centos7-x86_64" --name=centos7 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg[root@cobbler ks]# cobbler synctask started: 2015-08-22_015615_synctask started (id=Sync, time=Sat Aug 22 01:56:15 2015)running pre-sync triggerscleaning treesremoving: /var/www/cobbler/p_w_picpaths/centos6-x86_64removing: /var/www/cobbler/p_w_picpaths/centos7-x86_64removing: /var/lib/tftpboot/pxelinux.cfg/defaultremoving: /var/lib/tftpboot/grub/p_w_picpathsremoving: /var/lib/tftpboot/grub/grub-x86_64.efiremoving: /var/lib/tftpboot/grub/grub-x86.efiremoving: /var/lib/tftpboot/grub/efidefaultremoving: /var/lib/tftpboot/p_w_picpaths/centos6-x86_64removing: /var/lib/tftpboot/p_w_picpaths/centos7-x86_64removing: /var/lib/tftpboot/s390x/profile_listcopying bootloaderstrying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yabootcopying: /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboottrying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efitrying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.eficopying distros to tftpbootcopying files for distro: centos7-x86_64trying hardlink /var/www/cobbler/ks_mirror/centos7/p_w_picpaths/pxeboot/vmlinuz -> /var/lib/tftpboot/p_w_picpaths/centos7-x86_64/vmlinuztrying hardlink /var/www/cobbler/ks_mirror/centos7/p_w_picpaths/pxeboot/initrd.img -> /var/lib/tftpboot/p_w_picpaths/centos7-x86_64/initrd.imgcopying files for distro: centos6-x86_64trying hardlink /var/www/cobbler/ks_mirror/centos6/p_w_picpaths/pxeboot/vmlinuz -> /var/lib/tftpboot/p_w_picpaths/centos6-x86_64/vmlinuztrying hardlink /var/www/cobbler/ks_mirror/centos6/p_w_picpaths/pxeboot/initrd.img -> /var/lib/tftpboot/p_w_picpaths/centos6-x86_64/initrd.imgcopying p_w_picpathsgenerating PXE configuration filesgenerating PXE menu structurecopying files for distro: centos7-x86_64trying hardlink /var/www/cobbler/ks_mirror/centos7/p_w_picpaths/pxeboot/vmlinuz -> /var/www/cobbler/p_w_picpaths/centos7-x86_64/vmlinuztrying hardlink /var/www/cobbler/ks_mirror/centos7/p_w_picpaths/pxeboot/initrd.img -> /var/www/cobbler/p_w_picpaths/centos7-x86_64/initrd.imgWriting template files for centos7-x86_64copying files for distro: centos6-x86_64trying hardlink /var/www/cobbler/ks_mirror/centos6/p_w_picpaths/pxeboot/vmlinuz -> /var/www/cobbler/p_w_picpaths/centos6-x86_64/vmlinuztrying hardlink /var/www/cobbler/ks_mirror/centos6/p_w_picpaths/pxeboot/initrd.img -> /var/www/cobbler/p_w_picpaths/centos6-x86_64/initrd.imgWriting template files for centos6-x86_64rendering TFTPD filesgenerating /etc/xinetd.d/tftpprocessing boot_files for distro: centos7-x86_64processing boot_files for distro: centos6-x86_64cleaning link cachesrunning post-sync triggersrunning python triggers from /var/lib/cobbler/triggers/sync/post/*running python trigger cobbler.modules.sync_post_restart_servicesrunning shell triggers from /var/lib/cobbler/triggers/sync/post/*running python triggers from /var/lib/cobbler/triggers/change/*running python trigger cobbler.modules.scm_trackrunning shell triggers from /var/lib/cobbler/triggers/change/**** TASK COMPLETE ***[root@cobbler ks]# cobbler profile list   centos6-x86_64   centos6.6   centos7   centos7-x86_64

开始安装

spacer.gif

spacer.gif

spacer.gif

spacer.gif

附上我自己的ks文件参考

[root@cobbler ks]# cat centos6.cfg #platform=x86, AMD64, or Intel EM64T#version=DEVEL# Install OS instead of upgradeinstall# Keyboard layoutskeyboard 'us'# Reboot after installationreboot# Root passwordrootpw --iscrypted $1$JrbIN3YW$buJKv8Y7FfZhCEhOg/eD01# System timezonetimezone Asia/Chongqing --isUtc# Use network installationurl --url="http://192.168.3.100/cobbler/ks_mirror/centos6/"# System languagelang en_US# Firewall configurationfirewall --disabled# Network informationnetwork  --bootproto=dhcp --device=eth0# System authorization informationauth  --useshadow  --passalgo=sha512# Use graphical installgraphicalfirstboot --disable# SELinux configurationselinux --disabled# Installation logging levellogging --level=info# System bootloader configurationbootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda"# Clear the Master Boot Recordzerombr# Partition clearing informationclearpart --all --initlabel # Disk partitioning informationpart /boot --fstype="ext4" --size=500part pv.008002 --grow --size=1%packages@base@basic-desktop@core@debugging@desktop Platform Development@desktop-debugging@desktop-platform@development tools@directory-client@fonts@input-methods@internet-browser@java-platform@legacy-x@network-file-system-client@print-client@remote-desktop-clients@server Platform Development@server-platform@server-policy@x11%end

centos7 ks文件

[root@cobbler ks]# cat centos7.cfg #platform=x86, AMD64, or Intel EM64T#version=DEVEL# Install OS instead of upgradeinstall# X Window System configuration informationxconfig  --startxonboot# Keyboard layouts# old format: keyboard us# new format:keyboard --vckeymap=us --xlayouts='us'# Halt after installationreboot# Root passwordrootpw --iscrypted $1$L7lKtlWj$DvBzrvndeOQd7EHfRGOnj/# System timezonetimezone Asia/Chongqing --isUtc --nontp# Use network installationurl --url="http://192.168.3.100/cobbler/ks_mirror/centos7/"# System languagelang en_US --addsupport=zh_CN.UTF-8# Firewall configurationfirewall --disabled# Network informationnetwork  --bootproto=dhcp --device=eno16777736network  --bootproto=dhcp --device=None# System authorization informationauth  --useshadow  --passalgo=sha512# Use graphical installgraphical# Run the Setup Agent on first bootfirstboot --enable# SELinux configurationselinux --disabledignoredisk --only-use=sda# System bootloader configurationbootloader --location=mbr --boot-drive=sda# Clear the Master Boot Recordzerombr# Partition clearing informationclearpart --all --initlabel # Disk partitioning informationpart pv.10 --fstype="lvmpv" --ondisk=sda --size=35339part /boot --fstype="xfs" --ondisk=sda --size=500volgroup centos --pesize=4096 pv.10logvol /  --fstype="xfs" --grow --maxsize=51200 --size=1024 --name=root --vgname=centoslogvol swap  --fstype="swap" --size=2064 --name=swap --vgname=centos%packages@base@core@desktop-debugging@dial-up@directory-client@fonts@guest-agents@guest-desktop-agents@input-methods@internet-browser@java-platform@kde-desktop@multimedia@network-file-system-client@print-client@x11%end

cobbler web界面配置

使用系统用户(pam)或者configfile定义用户登录管理cobbler web

[authentication]#module = authn_configfile (默认值)module = authn_pam
[root@cobbler ~]# vim /etc/cobbler/modules.conf [root@cobbler ~]# useradd cobbler[root@cobbler ~]# echo "cobbler" | passwd --stdin cobbler Changing password for user cobbler.passwd: all authentication tokens updated successfully.[root@cobbler ~]# vim /etc/cobbler/users.conf [admins]admin = "cobbler"

spacer.gif

spacer.gif

[root@cobbler ~]# vim /etc/cobbler/modules.conf [authentication]module = authn_configfile[root@cobbler ~]# htdigest /etc/cobbler/users.digest "Cobbler" adminAdding user admin in realm CobblerNew password: Re-type new password:

未完待续