天天看點

cobbler 一鍵自動化安裝系統

本文介紹---collber ,路徑和配置檔案都是完全預設的配置

安裝步驟

1 準備測試環境

虛拟機vmware nat模式

<a href="http://s1.51cto.com/wyfs02/M00/7E/F7/wKioL1cOOo_B-rZpAAEjM5gYCyI566.png" target="_blank"></a>

VMware的NAT模式的dhcp服務也關閉,避免幹擾。 

2 準備系統環境  關閉selinux 關閉iptables,按epel源,可以使用阿裡雲的epel

cat /etc/redhat-release 

getenforce 

/etc/init.d/iptables status

ifconfig eth0 | grep "inet addr" | awk -F '[: ]+' '{print $4}'

yum repolist

<a href="http://s5.51cto.com/wyfs02/M02/7E/FA/wKiom1cOOgzxB--HAABMFPjkh1w835.png" target="_blank"></a>

3 安裝軟體

yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd

dhcp 提供dhcp功能

tftp-server 提供簡單檔案傳輸的功能

httpd 提供web功能

cobbler-web  可以不安裝如果不需要collber的管理界面

<code>rpm -ql cobbler # 檢視安裝的檔案,下面列出部分。</code>

<code>/etc/cobbler # 配置檔案目錄</code>

<code>/etc/cobbler/settings # cobbler主配置檔案,這個檔案是YAML格式,Cobbler是python寫的程式。</code>

<code>/etc/cobbler/dhcp.template # DHCP服務的配置模闆</code>

<code>/etc/cobbler/tftpd.template # tftp服務的配置模闆</code>

<code>/etc/cobbler/rsync.template # rsync服務的配置模闆</code>

<code>/etc/cobbler/iso # iso模闆配置檔案目錄</code>

<code>/etc/cobbler/pxe # pxe模闆檔案目錄</code>

<code>/etc/cobbler/power # 電源的配置檔案目錄</code>

<code>/etc/cobbler/users.conf # Web服務授權配置檔案</code>

<code>/etc/cobbler/users.digest # 用于web通路的使用者名密碼配置檔案</code>

<code>/etc/cobbler/dnsmasq.template # DNS服務的配置模闆</code>

<code>/etc/cobbler/modules.conf # Cobbler子產品配置檔案</code>

<code>/var/lib/cobbler # Cobbler資料目錄</code>

<code>/var/lib/cobbler/config # 配置檔案</code>

<code>/var/lib/cobbler/kickstarts # 預設存放kickstart檔案</code>

<code>/var/lib/cobbler/loaders # 存放的各種引導程式</code>

<code>/var/www/cobbler # 系統安裝鏡像目錄</code>

<code>/var/www/cobbler/ks_mirror # 導入的系統鏡像清單</code>

<code>/var/www/cobbler/images # 導入的系統鏡像啟動檔案</code>

<code>/var/www/cobbler/repo_mirror # yum源存儲目錄</code>

<code>/var/log/cobbler # 日志目錄</code>

<code>/var/log/cobbler/install.log # 用戶端系統安裝日志</code>

<code>/var/log/cobbler/cobbler.log # cobbler日志</code>

<a href="http://s1.51cto.com/wyfs02/M02/7E/FA/wKiom1cOOkfiwxo1AAA3q3YnWSs604.png" target="_blank"></a>

4 配置cobbler

/etc/init.d/httpd start

/etc/init.d/cobblerd start

/etc/init.d/cobblerd restart

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 : 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

9 : 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 指定server ip 結果第一和第二個報錯

# server,Cobbler伺服器的IP。

sed -i 's#server: 127.0.0.1#server: 192.168.100.20#g' /etc/cobbler/settings

# next_server,如果用Cobbler管理DHCP,修改本項,作用不解釋,看kickstart。

sed -i 's/next_server: 127.0.0.1/next_server: 10.0.0.7/' /etc/cobbler/settings

# 用Cobbler管理DHCP

<code>sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings</code>

2 開啟守護程序xinetd支援開啟tftp rsync

 sed -i 's#\(disable.*= \)no#\1no#g' /etc/xinetd.d/tftp           

 sed -i 's#\(disable.*= \)yes#\rno#g' /etc/xinetd.d/rsync  

3 解決下載下傳安裝系統是需要的loader檔案

cobbler get-loaders

下載下傳的檔案内容是

COPYING.elilo  COPYING.syslinux  COPYING.yaboot  elilo-ia64.efi  grub-x86_64.efi  grub-x86.efi  menu.c32  pxelinux.0  README  yaboot

4 填充密碼 解決第8個報錯

# 設定新安裝裝系統(不是本機系統)的預設root密碼123456。下面的指令來源于提示6。random-phrase-here為幹擾碼,可以自行設定。

[root@linux-node1 ~]# openssl passwd -1 -salt 'oldboy' '123456'

$1$oldboy$Npg9Pt9k98Mlg0ZeqHAuN1

[root@linux-node1 ~]# vim /etc/cobbler/settings

default_password_crypted: "$1$oldboy$Npg9Pt9k98Mlg0ZeqHAuN1"

一條指令搞定(變量替換)

 sed -i 's#default_password_crypted:.*#default_password_crypted: \"'`openssl passwd -1 -salt 'oldboy' '123456'`'\"#g' /etc/cobbler/settings

5  忽略的報錯

<code>1 : debmirror package is not installed, it will be required to manage debian deployments and repositories # 和debian系統相關,不需要</code>

<code>2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them # fence裝置相關,不需要</code>

<a href="http://s4.51cto.com/wyfs02/M00/7E/F7/wKioL1cOOzzSH3pJAAAvy8Q7GEI913.png" target="_blank"></a>

5 配置dhcp

vi /etc/cobbler/dhcp.template

# 修改cobbler的dhcp模版,不要直接修改dhcp本身的配置檔案,因為cobbler cobbler sync同步會覆寫。

[root@linux-node1 ~]# vim /etc/cobbler/dhcp.template

# 僅列出修改過的字段

……

subnet 10.0.0.0 netmask 255.255.255.0 {

option routers 10.0.0.2;

option domain-name-servers 10.0.0.2;

option subnet-mask 255.255.255.0;

range dynamic-bootp 10.0.0.100 10.0.0.200;

6 同步cobbler配置  cobbler sync

做的操作

同步的内容大緻為:

 dhcp配置檔案到 /etc/dhcp/dhcpd.conf

做硬連接配接 /var/lib/cobbler/loaders/pxelinux.0 -&gt; /var/lib/tftpboot/pxelinux.0等系統loaders檔案

pxe的menu檔案生成

<a href="http://s5.51cto.com/wyfs02/M00/7E/FA/wKiom1cOOuHT3xDsAACMRQIoKmA658.png" target="_blank"></a>

7 開啟啟動設定

chkconfig httpd on

chkconfig xinetd on

chkconfig cobblerd on

chkconfig dhcpd on

/etc/init.d/httpd restart

/etc/init.d/xinetd restart

/etc/init.d/cobblerd restart

/etc/init.d/dhcpd restart

8 管理cobbler

常用

cobbler distro report 

cobbler profile report

9 導入鏡像

<a href="http://s3.51cto.com/wyfs02/M00/7E/FA/wKiom1cOO1PjnBRuAAAzzf7yrOM690.png" target="_blank"></a>

<a href="http://s5.51cto.com/wyfs02/M01/7E/FA/wKiom1cOO1WgLrSGAABLVNy9LgM281.png" target="_blank"></a>

如果是真實機器,而不是虛拟機實驗的話,導入鏡像可以從本地。

<code>mkdir</code> <code>-p </code><code>/mnt/iso</code>

<code>mount</code> <code>-o loop </code><code>/data/KerryOS-1</code><code>.0-i386.iso </code><code>/mnt/iso</code>

cobbler import --path=/mnt/ --name=CentOS-6.4-x86_64 --arch=x86_64 (完成之後不需要collber sync)

注意命名的規範和源iso鏡像命名一緻

# --path 鏡像路徑

# --name 為安裝源定義一個名字

# --arch 指定安裝源是32位、64位、ia64, 目前支援的選項有: x86│x86_64│ia64

# 安裝源的唯一标示就是根據name參數來定義,本例導入成功後,安裝源的唯一标示就是:CentOS-6.4-x86_64,如果重複,系統會提示導入失敗。

CentOS-6.4-x86_64

# 鏡像存放目錄,cobbler會将鏡像中的所有安裝檔案拷貝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-6.4-x86_64目錄下。是以/var/www/cobbler目錄必須具有足夠容納安裝檔案的空間。

   CentOS-6.4-x86_64

CentOS-6.4-x86_64  config

<a href="http://s5.51cto.com/wyfs02/M00/7E/F7/wKioL1cOPIKRvHNgAABcY_lJW_I277.png" target="_blank"></a>

10 kickstart檔案

<code># 在第一次導入系統鏡像後,Cobbler會給鏡像指定一個預設的kickstart自動安裝檔案在/var/lib/cobbler/kickstarts下的sample_end.ks。</code>

如:

<a href="http://s5.51cto.com/wyfs02/M02/7E/F7/wKioL1cOPM3jDIF-AAAq5Io5LmA716.png" target="_blank"></a>

11 不做任何修改kickstart檔案進行建立安裝系統

<a href="http://s5.51cto.com/wyfs02/M01/7E/FA/wKiom1cOPDLASSXtAABQgzc1lew043.png" target="_blank"></a>

界面不美觀---需要優化

修改:

vim /etc/cobbler/pxe/pxedefault.template  

修改完成後 記得 cobbler sync  

二修改: 我們不能讓local作預設的啟動選項

實際菜單檔案起作用的是:/var/lib/tftpboot/pxelinux.cfg/default

可以參考一下修改:

或者講local那一個label删除

[root@log_server ~]# cat /var/lib/tftpboot/pxelinux.cfg/default

<code>DEFAULT menu</code>

<code>PROMPT 0</code>

<code>MENU TITLE Cobbler | http://cobbler.github.io</code>

<code>TIMEOUT 200</code>

<code>TOTALTIMEOUT 6000</code>

<code>ONTIMEOUT CentOS-6.4-x86_64</code>

<code>LABEL CentOS-6.4-x86_64</code>

<code>        </code><code>MENU DEFAULT</code>

<code>        </code><code>kernel /images/CentOS-6.4-x86_64/vmlinuz</code>

<code>        </code><code>MENU LABEL CentOS-6.4-x86_64</code>

<code>        </code><code>append initrd=/images/CentOS-6.4-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.100.20/cblr/svc/op/ks/profile/CentOS-6.4-x86_64</code>

<code>        </code><code>ipappend 2</code>

<code>LABEL local</code>

<code>        </code><code>MENU LABEL (local)</code>

<code>        </code><code>LOCALBOOT 2 </code>

<code>MENU end</code>

選擇  Centos-6.4-x86_64 進行安裝

安裝過程的一部分

<a href="http://s3.51cto.com/wyfs02/M02/7E/FA/wKiom1cOPILAXSTgAABgpCZqa7w478.png" target="_blank"></a>

<a href="http://s5.51cto.com/wyfs02/M01/7E/F7/wKioL1cOPVXjKo6zAAA8F5s3ZOA443.png" target="_blank"></a>

總結: 我的經曆

1 一般小公司會使用原生collber進行管理,原因 可以不懂其中的具體操作,且鏡像比較少

2 缺點: collber重複檔案 導入較多,且路徑很複雜 很依賴collber這個工具

3 大公司都是 自己根據原理 安裝每個元件(http tftp dhcp 等自己規劃路徑和鏡像和load等檔案 ) 而不需要collber

如 以下是一家公司的多個鏡像圖:

我此刻再次闡述原理:

<a href="http://s5.51cto.com/wyfs02/M00/7E/F7/wKioL1cOTimgboWjAABam5tEXZ0079.png" target="_blank"></a>

<a href="http://s2.51cto.com/wyfs02/M00/7E/FA/wKiom1cOTVjisFTBAACM3yPlcCc737.png" target="_blank"></a>

<a>Cobbler 的設計方式</a>

Cobbler 的配置結構基于一組注冊的對象。每個對象表示一個與另一個實體相關聯的實體(該對象指向另一個對象,或者另一個對象指向該對象)。當一個對象指向另一個對象時,它就繼承了被指向對象的資料,并可覆寫或添加更多特定資訊。以下對象類型的定義為:

發行版:表示一個作業系統。它承載了核心和 initrd 的資訊,以及核心參數等其他資料。

配置檔案:包含一個發行版、一個 kickstart 檔案以及可能的存儲庫,還包含更多特定的核心參數等其他資料。

系統:表示要配給的機器。它包含一個配置檔案或一個鏡像,還包含 IP 和 MAC 位址、電源管理(位址、憑據、類型)以及更為專業的資料等資訊。

存儲庫:儲存一個 yum 或 rsync 存儲庫的鏡像資訊。

鏡像:可替換一個包含不屬于此類别的檔案的發行版對象(例如,無法分為核心和 initrd 的對象)。

基于注冊的對象以及各個對象之間的關聯,Cobbler 知道如何更改檔案系統以反映具體配置。因為系統配置的内部是抽象的,是以您可以僅關注想要執行的操作。

<a href="http://s2.51cto.com/wyfs02/M01/7E/F7/wKioL1cOTkyCaktRAAAo-0oQdZo043.png" target="_blank"></a>

常見報錯:

1 cobbler sync過程

關鍵錯誤

dhcpd -t failed

解決思路

檢視cat /etc/cobbler/dhcp.template  和 vim /var/log/messages 檢視日志

1 可能dhcp配置錯誤

常見需要解決的問題:

前提:

預設ks檔案

/var/lib/cobbler/kickstarts/sample_end.ks

預設pxe啟動檔案

/var/lib/tftpboot/pxelinux.cfg/default

1 修改ks檔案名字(完成之後不需要collber sync)

<code>cobbler profile edit --name=CentOS-6.7-minimal-x86_64 --kickstart=</code><code>/var/lib/cobbler/kickstarts/Centos_6</code><code>.7_HF_APP.ks</code>

2 em1 變成 eth0網卡名字

應為dell伺服器或者centos7 會将網卡名稱改成em格式。如果要改成eth格式

修改核心參數即可

<code>cobbler profile edit --name=CentOS-6.7-minimal-x86_64 --kopts=</code><code>'net.ifnames=0 biosdevname=0'</code>

注意: 修改了profile之後,/var/lib/tftpboot/pxelinux.cfg/default檔案會被重置。

3 關于磁盤如何分區

# Allow anaconda to partition the system as needed

part /boot --fstype=ext4 --size=210

part / --fstype=ext4 --size=20480

part /home --fstype=ext4 --size=30720

part swap --size=8192

part /data1 --fstype=ext4 --grow --size=1

4 修改cobber服務的http端口。如本機已經跑了nginx 80端口。是以httpd就不能使用80端口了。此時可以考慮使用8080端口。修改方式

vim /etc/cobbler/settings  修改其中的http_port: 8080

cobbler sync 在同步配置即可

有必要再重新開機httpd /etc/init.d/httpd restart

本文轉自殘劍部落格51CTO部落格,原文連結http://blog.51cto.com/cuidehua/1763564如需轉載請自行聯系原作者

cuizhiliang