天天看點

利用kickstart實作pxe的自動安裝

利用kickstart實作pxe的自動安裝

你還在一台台的手動安裝系統嗎?

告訴你個偷懶的方法,你會喜歡的!

一、

pxe的概念

PXE(preboot execute environment),工作于C/S(客戶機伺服器)的網絡模式,支援工作站通過網絡從遠端伺服器下載下傳映像,并由此支援來自網絡作業系統的啟動過程。

pxe優點

1、減少安裝時間;

2、沒有cannot find or load required file krnl386.exe問題;

3、沒有tnt系列顯示卡16色問題;

4、沒有添加了檔案和列印共享就出錯的問題;

5、沒有修改工作站時間當機問題;

6、沒有無法正常關機與重新開機的問題;

二、

實驗原理

三、

實驗要求:

實作計算機加電後自動安裝linux作業系統;

計算機加電後能自動獲得IP位址(192.168.10.0/24網段);

計算機加電後,通過FTP上的資源安裝linux作業系統;

實作完全脫機安裝系統;

利用後安裝腳本配置系統主機名(格式:station+ip最後以為.a.com);

利用後安裝腳本使系統獲得的動态IP轉換成靜态IP;

啟動時禁止sendmail服務和cups服務的啟動;

四、

實驗拓撲圖:

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_13439650145W3r.png"></a>

五、

實驗步驟

1、配置yum伺服器

當使用pxe自動安裝系統時,為了避免安裝包的依賴性而影響脫機安裝,是以必須使用yum伺服器。

編輯yum配置檔案

[root@localhost ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_13439650544zT1.png"></a>

2、安裝DHCP伺服器

DHCP伺服器,為使用者提供動态IP位址,是實作pxe安裝的必要條件。

挂載CD光牒:

[root@localhost ~]# mount /dev/cdrom /mnt/cdrom

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@localhost ~]#

安裝dhcp

[root@localhost ~]# yum install dhcp

3、配置DHCP伺服器

[root@localhost ~]# vim /etc/dhcpd.conf

在底行模式中輸入:

:r /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965114I6gc.png"></a>

4、啟動DHCP服務

[root@localhost ~]# service dhcpd restart

Shutting down dhcpd:                                       [  OK  ]

Starting dhcpd:                                            [  OK  ]

5、開啟TFTP

編輯tftp的超級守護程序:

[root@localhost ~]# vim /etc/xinetd.d/tftp

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965140JiVu.png"></a>

重新開機超級守護程序:

[root@localhost ~]# service xinetd restart

Stopping xinetd:                                           [  OK  ]

Starting xinetd:                                           [  OK  ]

6、将驅動和核心拷貝到/tftpboot目錄下

切換到tfpt根目錄下:

[root@localhost ~]# cd /tftpboot

将pxe的驅動考到/tftpboot目錄下:

[root@localhost tftpboot]# cp /usr/lib/syslinux/pxelinux.0 ./

将pxe的核心考到/tftpboot目錄下

[root@localhost tftpboot]# cp /mnt/cdrom/images/pxeboot/vmlinuz ./

将pxe的跟硬體相關考到/tftpboot目錄下

[root@localhost tftpboot]# cp /mnt/cdrom/images/pxeboot/initrd.img ./

[root@localhost tftpboot]#

在/tftpboot目錄下建立一個目錄pexlinux.cfg

[root@localhost tftpboot]# mkdir -pv pxelinux.cfg

mkdir: created directory `pxelinux.cfg'

将CD光牒上的引導檔案拷貝到pexlinux.cfg目錄下

用于脫機配置啟動時一些其他的互動

[root@localhost tftpboot]# cp /mnt/cdrom/isolinux/isolinux.cfg pxelinux.cfg/default

7、配置引導過程中的一些資訊

[root@localhost tftpboot]# cd pxelinux.cfg/

[root@localhost pxelinux.cfg]# vim default

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965153B4QC.png"></a>

8、安裝FTP伺服器

FTP伺服器,為使用者提供的網絡資源,用于為使用者提供linux作業系統的安裝包,實作網絡安裝。

[root@localhost ~]# yum install -y vsftpd

啟動ftp服務

[root@localhost ~]# service vsftpd restart

Shutting down vsftpd:                                      [  OK  ]

Starting vsftpd for vsftpd:                                [  OK  ]

9、将linux系統鏡像拷貝到ftp的pub目錄下

[root@localhost ~]# cp -r /mnt/cdrom/.  /var/ftp/pub

[root@localhost ~]# du -sh /var/ftp/pub

2.9G /var/ftp/pub

拷貝成功

10、安裝kickstart

[root@localhost ~]# yum install -y system-config-kickstart

11、配置kickstart

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965200RlyV.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965230bX3Z.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965267wrG5.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965291GGjE.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965315VEFG.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965330jV3s.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965351om64.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965366cKPm.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965383toyj.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965393tXsI.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_13439654052TV8.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965423W73E.png"></a>

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

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_13439654630fi5.png"></a>

後安裝腳本代碼:

ADDRESS=`ifconfig |grep -i bcast |awk '{print $2}'` 

NUM=${ADDRESS##*.} 

ADD=${ADDRESS##*:} 

sed -i "s/HOSTNAME.*$/HOSTNAME=station$NUM.a.com/" /etc/sysconfig/network 

sed -i "s/BOOTPROTO.*$/BOOTPROTO=none/" /etc/sysconfig/network-scripts/ifcfg-eth0 

echo "IPADDR=$ADD" &amp;gt;&amp;gt; /etc/sysconfig/network-scripts/ifcfg-eth0 

echo "NETMASK=255.255.255.0" &amp;gt;&amp;gt; /etc/sysconfig/network-scripts/ifcfg-eth0 

echo "NETWORK=192.168.10.0" &amp;gt;&amp;gt; /etc/sysconfig/network-scripts/ifcfg-eth0

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965479coCb.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965495UHwr.png"></a>

12、編輯ks.cfg

[root@localhost ~]# vim /root/ks.cfg

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965508GG84.png"></a>

13、将kickstart形成的引導檔案ks.cfg考到ftp的pub目錄中

使得使用者在連接配接到FTP後能夠獲得ks.cfg檔案。

[root@localhost ~]# cp /root/ks.cfg /var/ftp/pub

六、

測試的結果

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965513Rn3I.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965521Kvyn.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_13439655313ii8.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965533EQUd.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965535wTwU.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965542QEkg.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965547gxL2.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_13439655548Ewj.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965561upow.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965571kbmX.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965587kki1.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965599dbBm.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965608xjgB.png"></a>

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

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965627JPnP.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201208/3/5251990_1343965633KzVL.png"></a>

本文轉自 cexpert 51CTO部落格,原文連結:http://blog.51cto.com/cexpert/952570

繼續閱讀