首頁>技術>

一:Cobbler簡介:

1.1:Cobbler{[ˈkɑ:blə(r)]}翻譯為中文是補鞋匠,在linux方面則一個免費的用於系統安裝部署的開源軟體,官方地址 http://cobbler.github.io/,cobbler是對技術的二次基於python的開發,提供了CLI(命令列)和Web的管理方式,另外還提供了API(應用程式程式設計介面)介面,方便二次開發使用,相比PXE,cobbler支援多系統同時引導,而PXE只能一次引導一個系統的安裝,cobbler通常與開源軟體puppet、saltstack配合使用,進行作業系統的批量安裝與部署優化,從而實現大批量linux系統的無人值守安裝與服務部署,大大提升運維的工作效率,cobbler工作於服務端,結合DHCP/TFTP/saltstack等服務提供批量系統安裝部署,cobbler需要結合PXE技術對客戶端進行作業系統的安裝。

1.2:PXE(preboot executeenvironment),預啟動執行環境)是由Intel公司開發的技術,工作於C/S的網路模式,支援客戶端通過網路從伺服器下載映像,並支援客戶端機器通過網路啟動作業系統,在啟動過程中,客戶端需要從伺服器分配IP地址、掩碼、閘道器以及相關的配置檔案路徑,再用TFTP(trivial file transfer protocol)協議從伺服器下載一個啟動軟體包到本機記憶體中執行,由這個啟動軟體包完成客戶端的基本軟體設定,從而引導預先安裝在伺服器中的終端作業系統,PXE可以引導多種作業系統,如:centos、redhat、windows 7等,因此PXE只是一種引導方式,將PC的啟動從網絡卡啟動。

PXE的工作過程:

1. PXE客戶端啟動時選擇或設定為從網絡卡啟動,向本網路中的DHCP伺服器申請IP資訊,包括IP地址、掩碼、閘道器等。2. DHCP 伺服器返回分配給客戶機的IP地址以及PXE檔案的放置位置(該檔案一般是放在一臺TFTP伺服器上)。3. PXE客戶端向本網路中的TFTP伺服器獲取pxelinux.0 檔案。4. PXE Client 取得pxelinux.0 檔案後之執行該檔案到記憶體。5. 根據pxelinux.0 的執行結果,通過TFTP伺服器載入核心vmlinuz和檔案系統init.image 。6. 進入安裝畫面, 此時可以通過選擇HTTP、FTP、NFS 方式之一進行安裝。

二.在服務端安裝部署cobbler:

2.1:安裝epel源,因為預設的yum源沒有Cobbler的rpm安裝包:

[root@linux-cobbler ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

2.2:安裝cobbler及相關元件

[root@linux-cobbler ~]# yum install -y httpd dhcp tftp cobbler cobbler-web pykickstart xinetd

#httpd 和cobbler-web 提供cobbler的web管理介面

#dhcp 提供IP地址分配服務

#xinetd 是一個超級守護程序,管理無法開機啟動的服務如tftp開機啟動

其中cobbelr是最核心的安裝包,期安裝後的主要目錄如下:

/etc/cobbler # cobbler的主配置檔案目錄,儲存了與cobbler相關的配置檔案/etc/cobbler/settings # cobble服務的預設主配置檔案/etc/cobbler/dhcp.template # DHCP服務的配置模板,開啟DHCP管理後可以根據此檔案生成dhcpd.conf檔案/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日誌

2.3:啟動cobbler:

[root@linux-cobbler ~]# systemctl start cobblerd && systemctl enable cobblerd #啟動cobbler主服務[root@linux-cobbler ~]# systemctl start httpd && systemctl enable httpd #如果不啟動http服務,下一步監測會報錯

通過cobbler命令進行環境監測,問題如下:

4.9:重啟cobblerd再次檢查: [root@linux-cobbler ~]# systemctl restart cobblerd[root@linux-cobbler ~]# cobbler checkNo configuration problems found. All systems go. #確認檢查沒有遇到任何問題,如果有問題按照提示處理

三:DHCP配置:

3.1:更改cobbler配置檔案,通過cobbler管理dhcp:

[root@linux-cobbler ~]# vim /etc/cobbler/settings #通過cobbler管理dhcp服務,也可以吧通過cobbler管理242 manage_dhcp: 1

3.2:重啟cobbler服務:

[root@linux-cobbler ~]# systemctl restart cobblerd

3.3:編輯cobbler提供的dhcp模板檔案,cobbler會根據更改後的模板檔案生成dhcp配置檔案:

[root@linux-cobbler ~]# vim /etc/cobbler/dhcp.template#以上全部為註釋內容 11 ddns-update-style interim; 12  13 allow booting; 14 allow bootp; 15  16 ignore client-updates; 17 set vendorclass = option vendor-class-identifier; 18  19 option pxe-system-type code 93 = unsigned integer 16; 20   21 subnet 192.168.100.0 netmask 255.255.255.0 { #地址網段與掩碼  22      option routers             192.168.100.2; #閘道器地址  23      option domain-name-servers 192.168.100.2; #DNS地址  24      option subnet-mask         255.255.255.0; #分配的子網範圍  25      range dynamic-bootp        192.168.100.100 192.168.100.254;  #分配的地址範圍  26      default-lease-time         21600; 27      max-lease-time             43200; 28 next-server $next_server; #tftp伺服器地址,呼叫/etc/cobbler/settings的next_server變數值,也可以寫192.168.100.10這樣的tftp伺服器地址 29 class "pxeclients" { 30 match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; 31 if option pxe-system-type = 00:02 { 32 filename "ia64/elilo.efi"; 33 } else if option pxe-system-type = 00:06 { 34 filename "grub/grub-x86.efi"; 35 } else if option pxe-system-type = 00:07 { 36 filename "grub/grub-x86_64.efi"; 37 } else { 38 filename "pxelinux.0"; 39 } 40 } 41 42 }#以下內容未發生更改

3.4:重啟cobbler服務:

[root@linux-cobbler ~]# systemctl restart cobblerd

3.5:執行cobbler sync生成配置檔案:

[root@linux-cobbler ~]# cobbler synctask started: 2017-07-23_194956_synctask started (id=Sync, time=Sun Jul 23 19:49:56 2017)running pre-sync triggerscleaning treesremoving: /var/lib/tftpboot/pxelinux.cfg/defaultremoving: /var/lib/tftpboot/grub/imagesremoving: /var/lib/tftpboot/grub/grub-x86.efiremoving: /var/lib/tftpboot/grub/grub-x86_64.efiremoving: /var/lib/tftpboot/grub/efidefaultremoving: /var/lib/tftpboot/s390x/profile_listcopying bootloaderstrying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efitrying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.eficopying distros to tftpbootcopying imagesgenerating PXE configuration filesgenerating PXE menu structurerendering DHCP filesgenerating /etc/dhcp/dhcpd.conf #生成配置檔案rendering TFTPD filesgenerating /etc/xinetd.d/tftpcleaning link cachesrunning post-sync triggersrunning python triggers from /var/lib/cobbler/triggers/sync/post/*running python trigger cobbler.modules.sync_post_restart_servicesrunning: dhcpd -t -qreceived on stdout: received on stderr: running: service dhcpd restart #重啟dhcp服務received on stdout: received on stderr: Redirecting to /bin/systemctl restart dhcpd.servicerunning 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 ***

四:cobbler使用:

4.1:cobbler是最核心的命令,獲取幫助資訊如下:

[root@linux-cobbler ~]# cobbler --helpusage=====cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... [add|edit|copy|getks*|list|remove|rename|report] [options|--help]cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]

4.2:匯入distro,即匯入一個發行版,發行版指的是作業系統,比如centos 6是一個發行版,centos 7也是一個發行版,本次匯入centos 6.8:

[root@linux-cobbler ~]# mount /dev/cdrom /mnt #掛載映象,也可以掛載ISO 光碟[root@linux-cobbler ~]# cobbler import --path=/mnt --name=Centos_6.8-x86_64 --arch=x86_64#import 申明做匯入#--path=/mnt/ 是映象的掛載目錄#--name=Centos-6-x86_64 匯入以後的名稱#--arch=x86_64 宣告是64位系統#以下是匯入過程的提示資訊: task started: 2017-07-23_195958_importtask started (id=Media import, time=Sun Jul 23 19:59:58 2017)Found a candidate signature: breed=redhat, version=rhel6Found a matching signature: breed=redhat, version=rhel6Adding distros from path /var/www/cobbler/ks_mirror/Centos_6.8-x86_64:creating new distro: Centos_6.8-x86_64trying symlink: /var/www/cobbler/ks_mirror/Centos_6.8-x86_64 -> /var/www/cobbler/links/Centos_6.8-x86_64creating new profile: Centos_6.8-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/Centos_6.8-x86_64 for Centos_6.8-x86_64processing repo at : /var/www/cobbler/ks_mirror/Centos_6.8-x86_64need to process repo/comps: /var/www/cobbler/ks_mirror/Centos_6.8-x86_64looking for /var/www/cobbler/ks_mirror/Centos_6.8-x86_64/repodata/*comps*.xmlKeeping repodata as-is :/var/www/cobbler/ks_mirror/Centos_6.8-x86_64/repodata*** TASK COMPLETE ***

4.3:匯入centos 7.2 :

[root@linux-cobbler ~]# mount /dev/cdrom /mnt/[root@linux-cobbler ~]# cobbler import --path=/mnt --name=Centos_7.2-x86_64 --arch=x86_64 #以下是匯入過程task started: 2017-07-23_200924_importtask started (id=Media import, time=Sun Jul 23 20:09:24 2017)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/Centos_7.2-x86_64:creating new distro: Centos_7.2-x86_64trying symlink: /var/www/cobbler/ks_mirror/Centos_7.2-x86_64 -> /var/www/cobbler/links/Centos_7.2-x86_64creating new profile: Centos_7.2-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/Centos_7.2-x86_64 for Centos_7.2-x86_64processing repo at : /var/www/cobbler/ks_mirror/Centos_7.2-x86_64need to process repo/comps: /var/www/cobbler/ks_mirror/Centos_7.2-x86_64looking for /var/www/cobbler/ks_mirror/Centos_7.2-x86_64/repodata/*comps*.xmlKeeping repodata as-is :/var/www/cobbler/ks_mirror/Centos_7.2-x86_64/repodata*** TASK COMPLETE ***

4.4:指定profile,在匯入發行版的時候可以通過–kickstart=KICKSTART_FILE指定profile檔案,如果沒有指定,可以在後期重新指定,需要將profile檔案提前準備好,最好放在/var/lib/cobbler/kickstarts,因為這是cobbler預設的ks檔案路徑,新增過程如下:

4.5:更改cobbler啟動顯示選單:

[root@linux-cobbler ~]# vim /etc/cobbler/pxe/pxedefault.template 3 MENU TITLE Cobbler | http://www.xxx.cn/ #改為自己的內容

4.6:重啟服務:

[root@linux-cobbler ~]# cobblerd[root@linux-cobbler ~]# systemctl restart httpd[root@linux-cobbler ~]# systemctl restart xinetd

4.7:執行cobbler同步並重啟服務:

[root@linux-cobbler kickstarts]# cobbler sync #更改配置檔案要重新執行同步

五:客戶端測試:

5.1:客戶端從啟動,獲取到IP地址後會出現安裝選擇介面,如下:

5.2:服務端檢視的IP地址申請資訊:

四個過程:

1. DHCPDISCOVER:客戶端廣播申請IP

2. DHCPOFFER:服務給客戶端一個IP

3. DHCPREQUEST:客戶端就申請使用此IP

4. DHCPACK:伺服器給客戶端確認IP有效

5.3:伺服器端檢視的客戶端從TFTP服務下載啟動檔案的日誌:

5.4:客戶端選擇安裝centos 7:

5.5:安裝完成以後的介面:

六:客戶端重灌系統工具:koan

[root@localhost ~]# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm #epel源才可以安裝

[root@localhost ~]# yum install koan –y

[root@localhost ~]# koan –server=192.168.56.11 –list=profiles #檢視可以安裝的profile

– looking for Cobbler athttp://192.168.56.11:80/cobbler_api

CentOS-7-x86_64

Centos-6-x86_64

#執行安裝並重啟

koan –replace-self –server=192.168.56.11–profile=CentOS-6-x86_64

reboot #重啟後會從新的ks檔案安裝新的6版本系統,注意之前的資料全丟失

七:cobbler圖形管理介面介紹:

安裝cobbler-web後,可以提供圖形的管理介面,訪問方式為https://x.x.x.x/cobbler_web,

,登入認證方式儲存在/etc/cobbler/modules.conf,預設為authn_configfile,即通過檔案儲存使用者名稱密碼認證,如下:

1).使用預設認證方式登入

此方式將登入使用者和密碼儲存在/etc/cobbler/users.digest,因此只要在其中新增使用者密碼即可登入,如下:

#命令格式:htdigest /etc/cobbler/users.digest “使用者組” 使用者名稱

[root@linux-node1 ~]#htdigest /etc/cobbler/users.digest “Cobbler” cobbler

Adding user cobbler in realm Cobbler

New password:

Re-type new password:

2)使用系統使用者認證登入:

更改/etc/cobbler/modules.conf認證方式authn_pam,如下:

module = authn_pam

然後將系統普通使用者新增到/etc/cobbler/users.conf中的admin組中,如下:

admin = “jack”

然重啟cobblerd服務,用瀏覽器訪問https://192.168.56.11/cobbler_web,即可使用系統使用者登入:

八:根據客戶端MAC地址安裝系統並指定yum源:

1) 新增yum源到本機:

[root@linux-node1 ~]# cobbler repo add –name=openstack-mitaka –mirror=http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/ –arch=x86_64 –breed=yum

2) 執行同步repo,同步後的rpm將全部儲存在本地,這樣的好處是伺服器可以設定內網yum,就不需要都設定網路下載rpm包了:

會將yun源的rpm包全部下載到/var/www/cobbler/repo_mirror/$NAME 目錄

[root@linux-node1 ~]# cobbler reposync

task started: 2016-05-31_142005_reposync

task started (id=Reposync, time=Tue May 3114:20:05 2016)

hello, reposync

run, reposync, run!

creating: /var/www/cobbler/repo_mirror/openstack-mitaka/config.repo

creating:/var/www/cobbler/repo_mirror/openstack-mitaka/.origin/openstack-mitaka.repo

running: /usr/bin/reposync -l -n -d–config=/var/www/cobbler/repo_mirror/openstack-mitaka/.origin/openstack-mitaka.repo–repoid=openstack-mitaka –download_path=/var/www/cobbler/repo_mirror -ax86_64

同步過程:

同步完成後將repo新增到對應的profile:

[root@linux-node1 cobbler]# cobbler profile edit –name=Centos-7-x86_64 –repos=’openstack-mitaka’ #只能寫一個repo地址切要對應新增時候的名稱,多了報錯如下:

客戶端啟動安裝系統,安裝完成以後會將自己同步到本機的yum源作為伺服器設定給客戶端,客戶端的yum源將指向本機同步後的http目錄

九:cobbler的system功能:

1).System模組是一個特殊的功能,可以單獨為指定的客戶端自定義ks檔案,並分配指定的IP、主機名、DNS、閘道器等資訊,如公司新進一臺伺服器,可以根據其MAC地址指定不同的profile檔案,劃分不同的分割槽安裝不同安裝包,從而適應不同的業務需求,如下:

新生成一個MAC地址是00:50:56:36:9D:29的虛擬機器,則配置如下:

[root@linux-node1 cobbler]# cobbler systemadd –name=linux-node3.com–mac=00:50:56:36:9D:29 –profile=CentOS-7-x86_64 –ip-address=192.168.56.13–subnet=255.255.255.0 –gateway=192.168.56.2 –interface=eth0 –static=1–hostname=linux-node3.com –name-servers=”192.168.56.2″–kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg

#add –name #新增一個system配置檔案

#–mac #客戶端的MAC地址

#–profile #profile的名稱

#–ip-address #分配給客戶端的指定IP

#–subnet #子網掩碼範圍

#–gateway #閘道器

#–interface #將IP配置在指定網口

#–static #指定靜態獲取IP

#–hostname #指定主機名

#–name-servers #指定DNS地址

#–kickstart #指定kickstack檔案路徑

將此客戶端重啟,將不會出現系統版本選擇介面直接進入系統安裝步驟。

2).安裝後驗證主機名和IP地址:

3).驗證yum原是否同步給客戶端:

[root@linux-node3 ~]# ll /etc/yum.repos.d/

[root@linux-node3 ~]# vim /etc/yum.repos.d/cobbler-config.repo #已經將自定義的yum源配置到了客戶端。

4).Cobbler官方文件:

http://cobbler.github.io/manuals/

  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 實踐React Router v5:完整指南