Cobbler實現PXE自動化無人值守安裝

目錄

前言

1、環境描述

2、準備操作

3、安裝配置Cobbler

3、簡單配置基礎服務

4、啓動cobbler服務

5、檢查Cobbler問題

6、Cobbler首次同步

7、導入發行版

8、驗證操作

10、啓用 Cobbler web

10、定製Profile

 


 

 

  • 前言

基於cobbler從0快速構建起PXE網絡引導安裝環境

 

Why Cobbler?

1. 優秀的Os Provisioning自動化工具,降低PXE環境管理複雜度,尤其是對於多系統PXE環境維護和管理。

2.有CLI和Web管理接口,Cobbler check和cobbler import完成後,就可以通過web界面進行管理,可以不用太過了解底層細節。

3.自動化管理PXE依賴的服務,還有一些高級功能。

 

 

1、環境描述

OS:CentOS 7.4 64bit

硬件:2CPU,2G,2塊網卡

軟件:cobbler-2.8.5,cobbler-web-2.8.5,dhcp-4.2.5,tftp-server-5.2-22,httpd-2.4.6,rsync-3.0.9

 

dhcp手動管理,tftp交由cobbler管理,yum repo由cobbler管理。

不需要通過system定製每個系統網絡屬性,直接手動管理dhcp還比較方便一點

 

2、準備操作

Step1:關閉防火牆

systemctl stop firewalld

 

Step2:關閉selinux

sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

setenforce 0

 

3、安裝配置Cobbler

Step1:安裝Cobbler及其相關依賴包

yum install cobbler cobbler-web dhcp syslinux

作爲cobbler依賴tftp-server、httpd、rsync會被自動安裝

 

step2:修改cobbler配置

/etc/cobbler/settings,YAML格式配置文件,修改其中幾項

default_password_crypted: $1$/FebKFB2$1RYpu1Gt8PV397FU6R6cj0

這個加密密碼可以用openssl passwd -1生成,用於設定/var/lib/cobbler/kickstarts/下的kickstart模版中的root密碼

server: 192.168.1.1

next_server: 192.168.1.1

server和next_server地址不能是127.0.0.1或localhost、0.0.0.0會報錯,要設置爲pxe網卡地址或對應主機名,其中next_server其實dhcp不是由cobbler管理的話無大礙

 

3、簡單配置基礎服務

 

step1:提供DHCP配置

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

vim /etc/dhcp/dhcpd.conf

 

option domain-name "jjf.com"; #你的域名

option domain-name-servers 192.168.1.1 #你的DNS服務器

 

default-lease-time 43200;

max-lease-time 86400;

 

log-facility local7;

 

subnet 192.168.1.0 netmask 255.255.0.0 {

range 192.168.1.100 192.168.1.120;

option routers 192.168.1.1;

next-server 192.168.1.1;

filename="pxelinux.0";

}

 

step2:啓動PXE所依賴服務

#啓動dhcp

systemctl start tftp.socket

systemctl enable tftp.socket

#啓動tftp

systemctl start tftp.socket

systemctl enable tftp.socket

#啓動httpd

systemctl start httpd.service

systemctl enable httpd.service

#啓動rsync

systemctl start rsyncd.service

systemctl enable rsyncd.service

 

4、啓動cobbler服務

systemctl start cobblerd.service

systemctl enable cobblerd.service

systemctl status cobblerd.service

 

5、檢查Cobbler問題

Step1:cobbler環境檢查

cobbler check

執行“cobbler check命令檢查存的問題,而後逐一按提示解決之。常見的問題如下所示:
1 : change 'disable' to 'no' in /etc/xinetd.d/tftp
2 : 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.
3 : debmirror package is not installed, it will be required to manage debian deployments and repositories
4 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

這些就不是什麼太大的問題,基本都可以忽略詳細如下:
1. 我們確保自己是以守護進程的方式正確運行tftp-server即可,只是它這裏檢查風格還是xinetd瞬時守護進程這種方式運行tftp-server。
2. 這一步是說可能會缺乏某些bootloader,如果是引導linux類系統不是efi問題也不大,前面我們安裝了syslinux這個包,等下直接執行cobbler sync它就會把/usr/share/syslinux/下的pxelinux.0,menu.c32,memdisk都複製過去。
3. 不是引導Debian的話這步也大可不必做。
4. 最後這個是做IPMI電源管理的,我們也不需要可以忽略,

這個4個問題都是可以忽律的問題,要說最要關注的可能也只是第2點,

 

6、Cobbler首次同步

確認上述這些問題無誤後,可以執行同步操作

 

Step1:首次同步

cobbler sync

task started: 2020-03-25_115417_sync

task started (id=Sync, time=Wed Mar 25 11:54:17 2020)

running pre-sync triggers

cleaning trees

removing: /var/lib/tftpboot/grub/images

copying bootloaders

trying hardlink /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0

trying hardlink /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32

trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk

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.manage_genders

running python trigger cobbler.modules.scm_track

running shell triggers from /var/lib/cobbler/triggers/change/*

*** TASK COMPLETE ***

 

 

7、導入發行版

導入CentOS6.4、CentOS7.4 發行版,步驟是相同的不詳細列明,以CenOS7.4導入爲例:

 

Step1:掛載光盤iso

mount -t iso9660 -o loop,ro /dev/sr0 /mnt/

 

Step2:執行導入

cobbler import --name=CentOS7.4 --arch=x86_64 --path=/mnt

task started: 2020-03-25_141505_import
task started (id=Media import, time=Wed Mar 25 14:15:05 2020)
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/CentOS7.4-x86_64:
creating new distro: CentOS7.4-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS7.4-x86_64 -> /var/www/cobbler/links/CentOS7.4-x86_64
creating new profile: CentOS7.4-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/CentOS7.4-x86_64 for CentOS7.4-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS7.4-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS7.4-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS7.4-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS7.4-x86_64/repodata
*** TASK COMPLETE ***
 

注意1:/var/www/cobbler/ks_mirror目錄是複製所有發行版和存儲庫文件的地方,因此每個要導入的發行版需要5-10GB的空閒空間。
注意2:不需要指定-arch選項,因爲它通常是自動檢測的。一般是爲了避免發現指定多個體繫結構(比如,Fedora在完整的DVD上提供了i386包,cobbler在默認情況下將創建x86_64和i386發行版)。

 

8、驗證操作

import導入光盤後,自動生成同名的distro(發行版, kernal+ramdisk),還有同名的默認profile(對應grub菜單的一個選項,可以理解爲kickstart+distro),還有同名的YUM repo。

發行版對應的yum倉庫和的kernal、ramdisk,cobbler會自動幫我們從光盤中抽取出來放到對應位置了。而pxe網絡引導需要用到的文件(pxelinux.0、mune.c32、memdisk)前面cobbler sync的時候也從syslinux的目錄中複製到tftp目錄下。

網絡引導的選項菜單cobbler也幫我們寫好,裏面有兩個條目就是對應我們導入的發行版,而且ks文件也幫我我們準備好了,注意這個ks文件是/var/lib/cobbler/kickstarts/sample_end.ks(後文還會有描述)。

有了這一切pxe安裝一個系統就不成問題了,其實生成這一切文件就是兩步,cobbler sync+cobbler import,簡單這兩部就構建出一個多系統的pxe環境,這就是cobbler的便捷之處。

 

Step1:驗證引導安裝CentOS7

 

Step2:驗證引導安裝CentOS6

 

10、啓用 Cobbler web

cobbler web的配置也並不複雜,直接使用digest認證即可。

htdigest -c /etc/cobbler/users.digest Cobbler cobbler

交互式輸入對應密碼

-C,創建一個數字摘要文件, /etc/cobbler/users.digest

Cobbler,realm,類似提示吧,一定要爲Cobbler

cobbler,你的賬號

注意,新版會要求https

 

10、定製Profile

前面說到默認的profile使用的是/var/lib/cobbler/kickstarts/sample_end.ks這個kickstart,它是一個text模式下安裝的最小化linux只%package包組,雖然說系統裝配我們不需要定製太多profile,一般安裝一個最小化安裝的系統然後使用ansible或puppt一類的工具類配置也完全可以。

 

但有時這個默認的kickstart也未必完全符合我們的需要,比如預定義一些我們要安裝的包組或安裝後執行的腳本,因此我們可以創建一個Profile導入我們自定義的Kickstart,和一些傳遞給內核的的參數

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章