cobbler自動化部署

PXE+Kickstart 工作概述

  1. 網(wǎng)卡上的pxe芯片有521字節(jié),存放了dhcp和tftp的客戶端
  2. 以網(wǎng)卡方式啟動計算機
  3. pxe上的dhcp客戶端回向dhcp服務器,申請IP地址
  4. DHCP服務器分配給它IP地址的同時通過以下字段,告訴pxe,TFTP的地址和它需要下載的文件(next-sterver filename “pxslinux.0”)
  5. pxelinux.0告訴pxe要下載的配置文件pxelinux.cfg目錄下面的default
  6. pxe下載并根據(jù)配置文件的內(nèi)容下載啟動必須的文件,并通過ks.cfg開始安裝系統(tǒng)

Cobbler 功能

  1. 使用一個以前定義的模板來配置DHCP服務(如果棄用了管理DHCP)
  2. 將一個存儲庫(yum或rsync)建立鏡像或解壓縮一個媒介,以注冊一個新的操作系統(tǒng)
  3. 在DHCP配置文件中為需要安裝的機器創(chuàng)建一個條目,并使用您指定的參數(shù)(IP和MAC地址)
  4. 在TFTP服務目錄下創(chuàng)建適當?shù)腜XE文件
  5. 重新啟動DHCP服務以反映更改
  6. 重新啟動機器以開始安裝

安裝Cobbler

[root@localhost ~]# yum install epel-release -y
[root@localhost ~]# yum install cobbler cobbler-web tftp httpd xinetd -y

安裝完成執(zhí)行 cobbler check

[root@localhost ~]# 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 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : 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/rsync
6 : file /etc/xinetd.d/rsync does not exist
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和2按照提示修改/etc/cobbler/settings 中 server 和 next_server 為指定的kickstar服務器(一般為本機的IP地址)
server: 9.110.187.140
next_server: 9.110.187.140
  • 3和5開啟守護進程控制rsync和tftp
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

service rsync
{
        disable = no
        flags           = IPv6
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
}
  • 4 直接執(zhí)行 cobbler get-loaders
[root@localhost ~]# cobbler get-loaders
task started: 2017-06-07_113154_get_loaders
task started (id=Download Bootloader Content, time=Wed Jun  7 11:31:54 2017)
downloading http://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading http://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading http://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading http://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading http://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading http://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading http://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading http://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading http://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading http://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
  • 8和10直接進行yum安裝
[root@localhost ~]# yum install pykickstart cman fence-agents -y
  • 9 修改配置文件中的默認密碼
[root@localhost ~]# openssl passwd -1 -salt 'cobbler' 'cobbler'
$1$cobbler$M6SE55xZodWc9.vAKLJs6.

重啟cobbler,檢查,同步

[root@localhost ~]# /etc/init.d/cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : file /etc/xinetd.d/rsync does not exist
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories

Restart cobblerd and then run 'cobbler sync' to apply changes.

[root@localhost ~]# cobbler sync
task started: 2017-06-07_120058_sync
task started (id=Sync, time=Wed Jun  7 12:00:58 2017)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
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 images
generating PXE configuration files
generating PXE menu structure
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 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 ***

利用 kickstart 圖形界面生成需要的 cfg 文件

具體如何使用請參考上篇文章:
http://www.lxweimin.com/p/1d1d46069a44
本文主要利用 HTTP 的方式進行系統(tǒng)安裝

掛載鏡像文件到 /var/www/html/CentOS-6.9-x86_64目錄下

[root@localhost ~]# mkdir /var/www/html/CentOS-6.9-x86_64
[root@localhost ~]# mount /dev/cdrom /var/www/html/CentOS-6.9-x86_64
mount: block device /dev/sr0 is write-protected, mounting read-only

修改 /etc/cobbler/settings 利用cobbler管理DHCP服務

# set to 1 to enable Cobbler's DHCP management features.
# the choice of DHCP management engine is in /etc/cobbler/modules.conf
manage_dhcp: 1

修改 /etc/cobbler/dhcp.template 配置文件

subnet 9.110.187.0 netmask 255.255.255.0 {
     option routers             9.110.187.2;
     option domain-name-servers 9.110.187.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        9.110.187.100 9.110.187.254;
     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";
          }
     }

重啟 cobbler 服務,同步 cobbler 配置

[root@localhost ~]# /etc/init.d/cobblerd restart
[root@localhost ~]# cobbler sync

導入相關(guān)的系統(tǒng)鏡像文件

[root@localhost ~]# cobbler import --path=/var/www/html/CentOS-6.9-x86_64/ --name=CentOS-6.9-x86_64 --arch=x86_64

查看鏡像時候?qū)氤晒?br> `

[root@localhost ~]# cobbler profile list
   CentOS-6.9-x86_64

導入編輯的 cfg文件

[root@localhost ~]# cd /var/lib/cobbler/kickstarts/
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$TjakpGzz$Kfx8GocFqs9sQgfrnBjxu1
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://9.110.187.140/CentOS-6.9-x86_64"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx

# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="xfs" --size=500
part / --asprimary --fstype="xfs" --grow --size=1
[root@localhost ~]# cobbler profile edit --name=CentOS-6.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.9-x86_64.cfg
[root@localhost ~]# cobbler sync

用網(wǎng)卡方式啟動一臺新的服務器

image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容