天天看點

PXE實作Linux的自動安裝

PXE實作Linux的自動安裝

安裝過linux的人都知道,在隻對一台機器進行linux的安裝,很容易,我們隻需要把光驅放進去就可以了,一步步的安裝就ok!

但是當我們在一個機房,多台機器同時安裝是就不可能這樣做了,那有沒有簡單的方法呢?

随着現在的技術的發展,基本上所有的網卡都支援pxe,此時我們就可以使用遠端的網絡安裝,這裡使用的是ftp安裝

技術資料:

 在PC上從網絡啟動Red Hat Linux安裝程式的PXE協定,同時需要tftp服務

PXE(Pre-boot Execution Environment)是由Intel設計的協定,它可以使計算機通過網絡啟動。協定分為client和server兩端,PXE client在網卡的ROM中,當計算機引導時,BIOS把PXE client調入記憶體執行,并顯示出指令菜單,經使用者選擇後,PXE client将放置在遠端的作業系統通過網絡下載下傳到本地運作。

PXE協定的成功運作需要解決以下兩個問題:

  既然是通過網絡傳輸,那麼計算機在啟動時,它的IP位址由誰來配置;通過什麼協定下載下傳Linux核心和根檔案系統

  對于第一個問題,可以通過DHCP Server解決,由DHCP server來給PXE client配置設定一個IP位址,DHCP Server是用來給DHCP Client動态配置設定IP位址的協定,不過由于這裡是給PXE Client配置設定IP位址,是以在配置DHCP Server時,需要增加相應的PXE特有配置。

 至于第二個問題,在PXE client所在的ROM中,已經存在了TFTP Client。PXE Client使用TFTP Client,通過TFTP協定到TFTP Server上下載下傳所需的檔案。

TFTP根目錄下有linux的相關核心啟動檔案bootstrap,這樣可以就可以引導系統啟動了

 Red Hat Linux安裝程式提供的網絡安裝功能(即指通過網絡通路安裝媒體),需要nfs服務

ks.cfg檔案中制定了安裝媒體的位置,如果沒有此檔案,需要手工指定。

 Red Hat Linux 安裝程式提供的無人值守安裝功能

/tftpboot/pxelinux.cfg/default檔案中定義了ks.cfg檔案的位置,同時ks.cfg規定了安裝過程中的選擇配置資訊,學習ks的最好方式是找到已已安裝

1.挂載光驅,并安裝dhcp服務和vsftp服務

<a href="http://blog.51cto.com/attachment/201308/230500159.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230502159.png" target="_blank"></a>

2.編輯dhcp的配置檔案

<a href="http://blog.51cto.com/attachment/201308/230504513.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230506532.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230509264.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230511657.png" target="_blank"></a>

3.ftp服務

<a href="http://blog.51cto.com/attachment/201308/230513445.png" target="_blank"></a>

編輯tftp程序檔案

<a href="http://blog.51cto.com/attachment/201308/230516876.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230518338.png" target="_blank"></a>

現在已經配置好了dhcp和ftp服務!

4.把isolinux.cfg 拷貝到ftp目錄pxelinux.cfg目錄下,編輯isolinux.cfg 

<a href="http://blog.51cto.com/attachment/201308/204254742.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230522351.png" target="_blank"></a>

5.追加dhcp.conf檔案,開機時讀取linux的啟動項

<a href="http://blog.51cto.com/attachment/201308/212236579.jpg" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230525900.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230527372.png" target="_blank"></a>

6.把光驅上所有的檔案都拷貝到ftp下,這樣需要的檔案可以自動找到安裝

<a href="http://blog.51cto.com/attachment/201308/230529629.png" target="_blank"></a>

7.對于同時安裝多台機器來講,不可能所有的機器的名字都是相同的,是以為了區分開,我們編寫腳本,把機器的名字用從dhcp擷取得到的ip位址的最後一位分開

<a href="http://blog.51cto.com/attachment/201308/230532336.png" target="_blank"></a>

8.安裝linux,我們會安裝很多的工具包,很多的都哦是依賴的,是以我們使用yum安裝,那麼我們就要配置yum環境了

<a href="http://blog.51cto.com/attachment/201308/231806316.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230534653.png" target="_blank"></a>

[root@localhost ~]yum list all

第一次的時候很慢,以後就會很快。

9.網絡安裝linux ,我們需要配置ks.cfg檔案,它是linux的安裝的引導說明

<a href="http://blog.51cto.com/attachment/201308/230536903.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230539990.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230542491.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230545175.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230548634.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230551942.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230554890.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230557717.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230559554.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230602984.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230606383.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230610380.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230613284.png" target="_blank"></a>

10.進行網絡安裝測試

<a href="http://blog.51cto.com/attachment/201308/230615734.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230618357.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230623561.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230730953.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230733900.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/230735810.png" target="_blank"></a>

實驗完成!

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

繼續閱讀