Cobbler自動化部署

運維自動化在生產環境中佔據着舉足輕重的地位,尤其是面對幾百臺,幾千臺甚至幾萬臺的服務器時,僅僅是安裝操作系統,如果不通過自動化來完成,根本是不可想象的。面對生產環境中不同服務器的需求,該如何實現批量部署多版本的操作系統呢?Cobbler便可以滿足這一實際需求,實現多版本操作系統批量部署。

1.1 Cobbler簡介

  Cobbler是一個快速網絡安裝linux的服務,而且在經過調整也可以支持網絡安裝windows。該工具使用python開發,小巧輕便(才15k行python代碼),使用簡單的命令即可完成PXE網絡安裝環境的配置,同時還可以管理DHCP、DNS、TFTP、RSYNC以及yum倉庫、構造系統ISO鏡像。
  Cobbler支持命令行管理,web界面管理,還提供了API接口,可以方便二次開發使用,Cobbler客戶端Koan支持虛擬機安裝和操作系統重新安裝。

      Cobbler原理:

         

Cobbler加載原理圖

Server端:

  1. 第一步,啓動Cobbler服務
  2. 第二步,進行Cobbler錯誤檢查,執行cobbler check命令
  3. 第三步,進行配置同步,執行cobbler sync命令
  4. 第四步,複製相關啓動文件文件到TFTP目錄中
  5. 第五步,啓動DHCP服務,提供地址分配
  6. 第六步,DHCP服務分配IP地址
  7. 第七步,TFTP傳輸啓動文件
  8. 第八步,Server端接收安裝信息
  9. 第九步,Server端發送ISO鏡像與Kickstart文件

Client端:

  1. 第一步,客戶端以PXE模式啓動
  2. 第二步,客戶端獲取IP地址
  3. 第三步,通過TFTP服務器獲取啓動文件
  4. 第四步,進入Cobbler安裝選擇界面
  5. 第五步,客戶端確定加載信息
  6. 第六步,根據配置信息準備安裝系統
  7. 第七步,加載Kickstart文件
  8. 第八步,傳輸系統安裝的其它文件
  9. 第九步,進行安裝系統

  Cobbler各主要組件關係圖:                     

說明:

distro->profile-system(可選)

distro 發行版

面對不同的操作系統

面對同一個操作系統不同的版本

profile

核心特性是通過kickstart來部署

system

主要目的配置網絡接口

1.2 Cobbler功能

使用 Cobbler,您無需進行人工干預即可安裝機器。Cobbler 設置一個 PXE 引導環境(它還可使用yaboot 支持 PowerPC),並控制與安裝相關的所有方面,比如網絡引導服務(DHCP 和 TFTP)與存儲庫鏡像。當希望安裝一臺新機器時,Cobbler 可以:

使用一個以前定義的模板來配置 DHCP 服務(如果啓用了管理 DHCP)

將一個存儲庫(yum 或 rsync)建立鏡像或解壓縮一個媒介,以註冊一個新操作系統

在 DHCP 配置文件中爲需要安裝的機器創建一個條目,並使用您指定的參數(IP 和 MAC 地址)

在 TFTFP 服務目錄下創建適當的 PXE 文件

重新啓動 DHCP 服務以反映更改

重新啓動機器以開始安裝(如果電源管理已啓用)

   Cobbler 支持衆多的發行版:Red Hat、Fedora、CentOS、Debian、Ubuntu 和 SuSE。當添加一個操作系統(通常通過使用 ISO 文件)時,Cobbler 知道如何解壓縮合適的文件並調整網絡服務,以正確引導機器。

   Cobbler 可使用 kickstart 模板。基於 Red Hat 或 Fedora 的系統使用 kickstart 文件來自動化安裝流程。通過使用模板,您就會擁有基本的 kickstart 模板,然後定義如何針對一種配置文件或機器配置而替換其中的變量。例如,一個模板可能包含兩個變量 $domain和 $machine_name。在 Cobbler配置中,一個配置文件指定 domain=mydomain.com,並且每臺使用該配置文件的機器在machine_name 變量中指定其名稱。該配置文件中的所有機器都使用相同的 kickstart 安裝且針對domain=mydomain.com 進行配置,但每臺機器擁有其自己的機器名稱。您仍然可以使用 kickstart 模板在不同的域中安裝其他機器並使用不同的機器名稱。

   爲了協助管理系統,Cobbler 可通過 fence scripts 連接到各種電源管理環境。

Cobbler 支持apc_snmp、bladecenter、bullpap、drac、ether_wake、ilo、integrity、ipmilan、ipmitool、lpar、rsa、virsh和 wti。要重新安裝一臺機器,可運行 reboot system foo命令,而且 Cobbler 會使用必要的憑據和信息來爲您運行恰當的 fence scripts(比如機器插槽數)。

   除了這些特性,還可使用一個配置管理系統 (CMS)。您有兩種選擇:該工具內的一個內部系統,或者集成一個現有的外部 CMS,比如 Chef 或 Puppet。藉助內部系統,您可以指定文件模板,這些模板會依據配置參數進行處理(與 kickstart 模板的處理方式一樣),然後複製到您指定的位置。如果必須自動將配置文件部署到特定機器,那麼此功能很有用。

   使用 koan 客戶端,Cobbler 可從客戶端配置虛擬機並重新安裝系統。我不會討論配置管理和koan特性,因爲它們不屬於本文的介紹範疇。但是,它們是值得研究的有用特性。

1.3 基礎環境準備

[root@cobbler tools]# cat /etc/redhat-release 
CentOS release 6.6 (Final)

[root@cobbler tools]# uname -r
2.6.32-504.el6.x86_64

#更改主機名稱:
hostname cobbler
sed -i 's#HOSTNAME=template.com#HOSTNAME=cobbler#g' /etc/sysconfig/network

#配置域名解析地址
[root@cobbler tools]# echo "cobbler 192.168.30.130" >/etc/hosts
[root@cobbler tools]# tail -1 /etc/hosts
cobbler 192.168.30.130

#關閉iptable

[root@cobbler pxe]# /etc/init.d/iptables stop
[root@cobbler pxe]# getenforce
Disabled

備註:

提示:

虛擬機網卡採用NAT模式,因爲我們會搭建DHCP服務器,在同一局域網多個DHCP服務會有衝突,並且導致實踐失敗。

注意:生產環境單獨在交換機上面劃分一個專用VLAN,設置不同網段,用來批量安裝系統。禁止混用。

1.4安裝cobbler

yum install httpd dhcp tftp cobbler cobbler-web -y

軟件說明:

複製代碼
cobbler     #cobbler程序包
cobbler-web  #cobbler的web服務包
pykickstart  #cobbler檢查kickstart語法錯誤
httpd       #Apache web服務
 
/etc/cobbler                   # 配置文件目錄
/etc/cobbler/settings         # cobbler主配置文件
/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/images       # 導入的系統鏡像啓動文件
/var/www/cobbler/repo_mirror  # yum源存儲目錄
/var/log/cobbler               # 日誌目錄
/var/log/cobbler/install.log  # 客戶端系統安裝日誌
/var/log/cobbler/cobbler.log  # cobbler日誌
複製代碼

1.5 檢測Cobbler

   cobbler的運行依賴於dhcp、tftp、rsync及dns服務,其中dhcp可由dhcpd(isc)提供,也可由dnsmasq提供;tftp可由tftp-server程序包提供,也可由cobbler功能提供,rsync有rsync程序包提供,dns可由bind提供,也可由dnsmasq提供
   cobbler可自行管理這些服務中的部分甚至是全部,但需要配置/etc/cobbler/settings文件中的“manange_dhcp”、“manager_tftpd”、“manager_rsync”、“manager_dns”分別來進行定義,另外,由於各種服務都有着不同的實現方式,如若需要進行自定義,需要通過修改/etc/cobbler/modules.conf配置文件中各服務的模塊參數的值來實現。

複製代碼
 #別直接start啓動,會報錯
[root@cobbler tools]# /etc/init.d/httpd restart
停止 httpd:[確定]
正在啓動 httpd:httpd: apr_sockaddr_info_get() failed for cobbler
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[確定]

#別直接start啓動,會報錯
[root@cobbler tools]# /etc/init.d/cobblerd restart
Stopping cobbler daemon: [確定]
Starting cobbler daemon: [確定]
複製代碼

檢查配置文件,需要在cobblerd和httpd啓動的情況下檢查

[root@cobbler-node1 ~]# cobbler check    #檢查存在的問題,逐一解決

複製代碼
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.
解決辦法:
方式一:
sed -i 's/server: 127.0.0.1/server: 192.168.30.130/' /etc/cobbler/settings (其它配置文件方法相同)

方式二: [root@cobbler tools]# vi /etc/cobbler/settings server: 192.168.30.130 #修改384行,把127.0.0.1 修改爲本地網卡的ip地址。 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. 解決辦法: [root@cobbler tools]# vi /etc/cobbler/settings next_server: 192.168.30.130 #修改271行,把127.0.0.1 修改爲本地網卡的ip地址。 3 : change 'disable' to 'no' in /etc/xinetd.d/tftp 解決辦法: [root@cobbler tools]# vi /etc/xinetd.d/tftp # default: off # description: The tftp server serves files using the trivial file transfer \ # protocol. The tftp protocol is often used to boot diskless \ # workstations, download configuration files to network-aware printers, \ # and to start the installation process for some operating systems. service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot disable = no #這裏需要開啓,把yes改成no per_source = 1 cps = 100 2 flags = IPv4 } "/etc/xinetd.d/tftp" 18L, 517C written 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. 解決辦法: [root@cobbler tools]# cobbler get-loaders 5 : change 'disable' to 'no' in /etc/xinetd.d/rsync 解決辦法: [root@cobbler tools]# cat /etc/xinetd.d/rsync # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no #把yes改成no,意思就是打開rsync flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } 6 : file /etc/xinetd.d/rsync does not exist 解決辦法: [root@cobbler tools]# cat /etc/xinetd.d/rsync # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no #把yes改成no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } 解決辦法: [root@cobbler tools]# /etc/init.d/xinetd restart 停止 xinetd:[失敗] 正在啓動 xinetd:[確定] 7 : debmirror package is not installed, it will be required to manage debian deployments and repositories 提示說debmirror沒安裝。如果不是安裝 debian之類的系統,此提示可以忽略,如果需要安裝, 下載地址爲: http://rpmfind.net/linux/rpm2html/search.php?query=debmirror 8 : ksvalidator was not found, install pykickstart 解決辦法: [root@cobbler tools]# yum install pykickstart -y 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 解決辦法: #先用你的用戶名和密碼,生成一段加密後的密碼: 用戶名:root, 密碼:1qaz@WSX [root@cobbler ~]# openssl passwd -1 -salt 'root' '1qaz@WSX' $1$root$GW872S0CPJMETAxxvDcsk0 [root@cobbler tools]# vi /etc/cobbler/settings #修改101行 default_password_crypted: "$1$root$GW872S0CPJMETAxxvDcsk0" 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. 解決方法: fencing tools,我們直接使用yum install -y fence-agents命令安裝即可。 最後有提示說,相關的東西改了,要重啓cobbler並執行cobbler sync纔會生效的哦。 我們將系統重啓後,安裝了fence-agents後,啓動cobbler並執行cobbler sync.
複製代碼

 解決完錯誤提示:

重啓cobblerd

[root@cobbler tools]# /etc/init.d/cobblerd restart
Stopping cobbler daemon: [確定]
Starting cobbler daemon: [確定]

再檢查錯誤:

複製代碼
[root@cobbler tools]# cobbler check
The following are potential configuration items that you may want to fix:
1 : file /etc/xinetd.d/rsync does not exist

[root@cobbler tools]# /etc/init.d/xinetd restart
  
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   #Centos系統直接忽略這個錯誤
複製代碼

1.6、配置dhcp

複製代碼
[root@cobbler tools]# vi /etc/cobbler/settings
manage_dhcp: 1   #把0改成1    #使用cobbler管理dhcp

快速操作方法:
sed -i 's#manage_dhcp: 0#manage_dhcp: 1#g' /etc/cobbler/settings

#修改dhcp模板文件: [root@cobbler tools]# vi /etc/cobbler/dhcp.template subnet 192.168.30.0 netmask 255.255.255.0 { option routers 192.168.30.2; option domain-name-servers 192.168.30.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.30.10 192.168.30.54; default-lease-time 21600; max-lease-time 43200; next-server $next_server;
複製代碼

1.7 同步Cobbler

複製代碼
[root@cobbler tools]# cobbler sync
task started: 2017-05-02_010406_sync
task started (id=Sync, time=Tue May  2 01:04:06 2017)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
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 images
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 ***
複製代碼

檢查生成的配置文件

複製代碼
[root@cobbler tools]# cat /etc/dhcp/dhcpd.conf
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Mon May  1 17:04:07 2017)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# ******************************************************************

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;

subnet 192.168.30.0 netmask 255.255.255.0 {
     option routers             192.168.30.2;
     option domain-name-servers 192.168.30.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.30.10 192.168.30.54;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                192.168.30.130;
     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";
          }
     }

}

# group for Cobbler DHCP tag: default
group {
}
複製代碼

1.8管理Cobbler

1.8.1管理distro

cobbler變得可用的第一步爲定義distro,其可以通過爲其指定外部的安裝引導內核及ramdisk文件的方式實現。

如果已經有完成的安裝樹(如os的安裝鏡像)則推薦使用improt之間導入的方式進行。

複製代碼
#插入一個光盤鏡像到光驅中。
[root@cobbler tools]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only

# --path 鏡像路徑
# --name 爲安裝源定義一個名稱
# --arch 指定安裝源是32位、64位、ia64, 目前支持的選項有: x86│x86_64│ia64
# 安裝源的唯一標示就是根據name參數來定義,本例導入成功後,安裝源的唯一標示就是:Centos-6.6-x86_64。
# 鏡像存放目錄,cobbler會將鏡像中的所有安裝文件拷貝到本地一份,放在/var/www/cobbler/links下的Centos-6.6-x86_64目錄下。
因此/var/www/cobbler目錄必須具有足夠容納安裝文件的空間。

[root@cobbler tools]# cobbler import --path=/mnt/ --name Centos-6.6-x86_64 --arch=x86_64

task started: 2017-05-02_011038_import
task started (id=Media import, time=Tue May  2 01:10:38 2017)
task started (id=Media import, time=Tue May  2 01:10:38 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/Centos-6.6-x86_64:
creating new distro: Centos-6.6-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos-6.6-x86_64 -> /var/www/cobbler/links/Centos-6.6-x86_64
creating new profile: Centos-6.6-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.6-x86_64 for Centos-6.6-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos-6.6-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-6.6-x86_64
looking for /var/www/cobbler/ks_mirror/Centos-6.6-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos-6.6-x86_64/repodata
*** TASK COMPLETE ***
複製代碼

1.8.2 查看導入信息

複製代碼
[root@cobbler tools]# cobbler profile report
Name                           : Centos-6.6-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : Centos-6.6-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                 : 
Internal 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


#指定kickstarts文件,這裏我們用自己做好的模板文件,不用系統默認的。
[root@cobbler kickstarts]# cd /var/lib/cobbler/kickstarts
例如:sample_end.ks  ===>系統默認kickstarts模板文件
複製代碼

模板文件:CentOS-6.6-x86_64.cfg

複製代碼
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
#Partition information
part /boot --fstype ext4 --size 1024 --ondisk sda
part swap --size=1500
part / --fstype ext4 --size 1 --grow --ondisk sda
  
# Use text mode install
text
# Firewall configuration
firewall --disable
# 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')
#network --bootproto=dhcp   --device=em1
# 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   Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
  
%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet

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

%end

#定製開始顯示網站
[root@cobbler ~]# cd /etc/cobbler/pxe
[root@cobbler pxe]# cat pxedefault.template 
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

$pxe_menu_items

MENU end
複製代碼

複製粘貼的,上傳到服務器,記得dos2unix處理一下。

 

1.8.3 管理profile

cobbler使用profile來爲特定的需求類別提供鎖需要安裝的配置,即在distro的基礎上通過提供kiskstart文件來生成一個特定的系統安裝配置。distro的profile可以出現在pxe的引導菜單中作爲安裝的選擇之一.

1
[root@cobbler kickstarts]# cobbler profile edit --name=CentOS-6.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.6-x86_64.cfg

查看導入信息

複製代碼
[root@cobbler kickstarts]# cobbler profile report
Name                           : CentOS-6.6-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : Centos-6.6-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/CentOS-6.6-x86_64.cfg
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal 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
複製代碼

再同步一下同步Cobbler

複製代碼
[root@cobbler kickstarts]# cobbler sync
task started: 2017-05-02_020005_sync
task started (id=Sync, time=Tue May  2 02:00:05 2017)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/Centos-6.6-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/images/Centos-6.6-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.6-x86_64
trying hardlink /var/www/cobbler/ks_mirror/Centos-6.6-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/Centos-6.6-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/Centos-6.6-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/Centos-6.6-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: Centos-6.6-x86_64
trying hardlink /var/www/cobbler/ks_mirror/Centos-6.6-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/Centos-6.6-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/Centos-6.6-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/Centos-6.6-x86_64/initrd.img
Writing template files for Centos-6.6-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: Centos-6.6-x86_64
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 ***

致此就安裝完成啦!
複製代碼

1.9 部署操作系統

新建一臺虛擬機,通過網絡啓動即可。(我這裏虛擬機使用的是NAT模式,並且關閉DHCP功能)

選擇CentOS-6.6-x86_64,回車就會自動化安裝系統。

安裝完成系統,登錄賬號如下:

用戶:root

密碼:1qaz@WSX

備註:

更多高級用法,參考官方文檔

地址:http://cobbler.github.io/manuals/2.8.0/

 


 CentOS7.2版本安裝Cobbler

一、系統環境配置

複製代碼
#查看版本號
[root@template ~]# cat /etc/redhat-release 

CentOS Linux release 7.2.1511 (Core) 
[root@template ~]# uname -r
3.10.0-327.el7.x86_64

#關閉防火牆
[root@template ~]# getenforce
Disabled
[root@template ~]# systemctl stop firewalld

#查看本機網卡ip
[root@cobbler-server ~]#  ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $3}'
192.168.30.131

#設置主機名
[root@template ~]# hostname
template.com
[root@template ~]# hostname cobbler-server
[root@template ~]# hostnamectl set-hostname cobbler-server

#添加hosts解析
[root@cobbler-server ~]# echo "cobbler-server 192.168.30.131" >/etc/hosts
[root@cobbler-server ~]# tail -1 /etc/hosts
cobbler-server 192.168.30.131
複製代碼

二、安裝Cobbler

複製代碼
[root@cobbler-node1 ~]# yum install cobbler cobbler-web pykickstart httpd dhcp xinetd -y

#cobblerd和httpd啓動服務
[root@cobbler-server ~]# systemctl start httpd
[root@cobbler-server ~]# systemctl start cobblerd

#檢查存在的問題,逐一解決
[root@cobbler-server ~]# 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 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
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
8 : 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、修改/etc/cobbler/settings文件中的server參數的值爲提供cobbler服務的主機相應的IP地址或主機名
sed -i 's/server: 127.0.0.1/server: 192.168.30.131/' /etc/cobbler/settings

2、修改/etc/cobbler/settings文件中的next_server參數的值爲提供PXE服務的主機相應的IP地址,如
sed -i 's/next_server: 127.0.0.1/next_server: 192.168.30.131/' /etc/cobbler/settings

3、修改/etc/xinetd.d/tftp文件中的disable參數修改爲 disable = no ,
[root@cobbler-server ~]# systemctl restart xinetd.service
[root@cobbler-server ~]# netstat -anltup|grep :69
udp        0      0 0.0.0.0:69              0.0.0.0:*                           13953/xinetd

4、執行 cobbler get-loaders 命令即可;否則,需要安裝syslinux程序包,而後複製/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目錄中;

5、執行 systemctl enable rsyncd命令即可;

6、如果有強迫症可以選擇yum install debmirror -y 然後根據錯誤進行解決,一般錯誤如下。
  註釋vi /etc/debmirror.conf文件中的
@dists=”sid”; @arches=”i386”; 7、生成開機用戶和加密密碼 [root@cobbler-server ~]# openssl passwd -1 -salt 'root' '1qaz@WSX' $1$root$GW872S0CPJMETAxxvDcsk0 #手工修改101行 vi /etc/cobbler/settings default_password_crypted: "$1$root$GW872S0CPJMETAxxvDcsk0" #檢查修改結果: [root@cobbler-server ~]# grep "default_password_crypted" /etc/cobbler/settings default_password_crypted: "$1$root$GW872S0CPJMETAxxvDcsk0" 8、安裝install cman or fence-agents [root@cobbler-server ~]# yum install fence-agents -y 最後重啓Cobbler:systemctl restart cobblerd [root@cobbler-server ~]# systemctl restart httpd [root@cobbler-server ~]# systemctl restart cobblerd
複製代碼

三、配置dhcp

複製代碼
#修改配置文件
[root@cobbler-server ~]# sed -i 's#manage_dhcp: 0#manage_dhcp: 1#g' /etc/cobbler/settings

#修改dhcp模板文件
vi /etc/cobbler/dhcp.template
[root@cobbler-server ~]# cp /etc/cobbler/dhcp.template /etc/cobbler/dhcp.template.backup

[root@cobbler-server ~]# ll /etc/cobbler/dhcp.*
-rw-r--r-- 1 root root 2946 11月 17 03:09 /etc/cobbler/dhcp.template
-rw-r--r-- 1 root root 2946 5月   3 00:11 /etc/cobbler/dhcp.template.backup

#修改dhcp配置文件
[root@cobbler-server ~]#vi /etc/cobbler/dhcp.template

subnet 192.168.30.0 netmask 255.255.255.0 {
     option routers             192.168.30.2;
     option domain-name-servers 192.168.30.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.30.100 192.168.30.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

     
[root@cobbler-server cobbler]# cobbler sync
task started: 2017-05-03_004727_sync
task started (id=Sync, time=Wed May  3 00:47:27 2017)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
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
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
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-server cobbler]# cat /etc/dhcp/dhcpd.conf
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Tue May  2 16:47:28 2017)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# ******************************************************************

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;

subnet 192.168.30.0 netmask 255.255.255.0 {
     option routers             192.168.30.2;
     option domain-name-servers 192.168.30.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.30.100 192.168.30.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                192.168.30.131;  #這裏會自動生成本機ip地址
     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";
          }
     }

}

# group for Cobbler DHCP tag: default
group {
}

     
#管理Cobbler
[root@cobbler-server cobbler]# mount /dev/cdrom /mnt
mount: /dev/sr0 寫保護,將以只讀方式掛載


[root@cobbler-server cobbler]# cobbler import --path=/mnt/ --name Centos-7.2-x86_64 --arch=x86_64
# --path 鏡像路徑
# --name 爲安裝源定義一個名字
# --arch 指定安裝源是32位、64位、ia64, 目前支持的選項有: x86│x86_64│ia64
# 安裝源的唯一標示就是根據name參數來定義,本例導入成功後,安裝源的唯一標示就是:Centos-7.2-x86_64。
# 鏡像存放目錄,cobbler會將鏡像中的所有安裝文件拷貝到本地一份,放在/var/www/cobbler/ks_mirror下的Centos-7.2-x86_64目錄下。因此/var/www/cobbler目錄必須具有足夠容納安裝文件的空間。
task started: 2017-05-03_005108_import
task started (id=Media import, time=Wed May  3 00:51:08 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.2-x86_64:
creating new distro: Centos-7.2-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos-7.2-x86_64 -> /var/www/cobbler/links/Centos-7.2-x86_64
creating new profile: Centos-7.2-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.2-x86_64 for Centos-7.2-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos-7.2-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-7.2-x86_64
looking for /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos-7.2-x86_64/repodata
*** TASK COMPLETE ***


[root@cobbler-server cobbler]# cobbler distro list
   Centos-7.2-x86_64
[root@cobbler-server cobbler]# cobbler profile report
Name                           : Centos-7.2-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : Centos-7.2-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                 : 
Internal 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

#進入存放目錄
[root@cobbler-server cobbler]# cd /var/lib/cobbler/kickstarts/
[root@cobbler-server kickstarts]# ls
default.ks    install_profiles  sample_autoyast.xml  sample_esxi4.ks  sample_old.seed
esxi4-ks.cfg  legacy.ks         sample_end.ks        sample_esxi5.ks  sample.seed
esxi5-ks.cfg  pxerescue.ks      sample_esx4.ks       sample.ks

#上傳CentOS-7.1-x86_64.cfg配置文件
[root@cobbler-server kickstarts]# rz -y
rz waiting to receive.
???a? zmodem ′???£ °′ Ctrl+C ???£
??′?? CentOS-7.1-x86_64.cfg...
  100%       1 KB    1 KB/s 00:00:01       0 ′?

#檢查配置文件
[root@cobbler-server kickstarts]# ll
-rw-r--r-- 1 root root 1450 5月  16 2016 CentOS-7.2-x86_64.cfg


#指定kickstarts路徑(如果上面是通過上傳的配置文件,可以省略這步。)
[root@cobbler-server kickstarts]# cobbler profile add --name=CentOS-7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.2-x86_64.cfg
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

CentOS7系統網卡名變成eno....這種,爲了運維標準化,我們需要修改爲我們常用的eth0,使用下面的參數。但要注意是CentOS7才需要下面的步驟,CentOS6不需要。

#修改centos7內核
cobbler profile edit --name=CentOS-7.2-x86_64 --kopts='net.ifnames=0 biosdevname=0' 


新部署機器安裝yum源,並同步。建議使用內網yum源,在這裏使用阿里雲yum源(如果不配置自己定製的內網yum源,省略這步)
[root@cobbler-node1 ~]# cobbler repo add --name=base --mirror=http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/ --arch=x86_64 --breed=yum#添加yum源
[root@cobbler-node1 ~]# cobbler reposync #同步yum源


#每次修改profile都需要同步
[root@cobbler-server ~]# cobbler sync   
task started: 2017-05-03_011112_sync
task started (id=Sync, time=Wed May  3 01:11:12 2017)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/Centos-7.2-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
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/images/Centos-7.2-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying files for distro: Centos-7.2-x86_64
trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/Centos-7.2-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/Centos-7.2-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: Centos-7.2-x86_64
trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/Centos-7.2-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/Centos-7.2-x86_64/initrd.img
Writing template files for Centos-7.2-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: Centos-7.2-x86_64
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-server ~]# tail -f /var/log/messages 
May  3 01:11:13 template dhcpd: Listening on LPF/eth0/00:0c:29:a5:0c:91/192.168.30.0/24
May  3 01:11:13 template dhcpd: Sending on   LPF/eth0/00:0c:29:a5:0c:91/192.168.30.0/24
May  3 01:11:13 template dhcpd: Sending on   Socket/fallback/fallback-net
May  3 01:11:13 template systemd: Started DHCPv4 Server Daemon.
May  3 01:14:31 template dhcpd: DHCPDISCOVER from 00:0c:29:d0:75:ed via eth0
May  3 01:14:32 template dhcpd: DHCPOFFER on 192.168.30.132 to 00:0c:29:d0:75:ed via eth0
May  3 01:14:33 template dhcpd: DHCPREQUEST for 192.168.30.132 (192.168.30.131) from 00:0c:29:d0:75:ed via eth0
May  3 01:14:33 template dhcpd: DHCPACK on 192.168.30.132 to 00:0c:29:d0:75:ed via eth0
May  3 01:15:01 template systemd: Started Session 37 of user root.

#服務端安裝完畢!
複製代碼

三、新建虛擬機,網絡設置爲NAT

1、開始安裝


2、安裝完成,登錄系統賬號
用戶名:root
密碼:1qaz@WSX
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章