Linux基于pxe+dhcp+nfs+tftp+kickstart的系統(tǒng)網(wǎng)絡(luò)安裝方法

原文發(fā)表于:2010-09-05

轉(zhuǎn)載至cu于:2012-07-21

一.原理簡(jiǎn)介

PXE(preboot execute environment)工作于Client/Server的網(wǎng)絡(luò)模式,支持工作站通過網(wǎng)絡(luò)從遠(yuǎn)端服務(wù)器下載鏡像,并由此支持來自網(wǎng)絡(luò)的操作系統(tǒng)的啟動(dòng)。啟動(dòng)過程中,終端由DHCP服務(wù)器分配IP地址,再用TFTPtrivial file transfer protocol)等協(xié)議下載存在于服務(wù)器(NFS,FTP,HTTP)Liunx內(nèi)核和根文件系統(tǒng)等到本機(jī)內(nèi)存中并執(zhí)行,由此完成終端基本軟件設(shè)置,從而引導(dǎo)預(yù)先安裝在服務(wù)器中的終端操作系統(tǒng)。

Kickstart 是一種無人職守安裝方式。它通過記錄典型的安裝過程中所需人工干預(yù)填寫的各種參數(shù),并生成一個(gè)ks.cfg文件;在其后的安裝過程中單出現(xiàn)要求填寫參數(shù)的時(shí)候,安裝程序會(huì)查找kickstart文件,在能找到合適的參數(shù)情況下就不需要人工干預(yù)。

二.環(huán)境說明

os

????CentOS 5.4 i386

soft

? ??dhcp, nfs, tftp, kickstart(gnome 或者x-window)

可以使用yum安裝:?

yum?–y?install?dhcp*  yum?–y?install?nfs*  yum?–y?install?tftp*  yum?–y?install?system-config-kickstart*

ip

? ??eth0: 192.168.1.254

三.安裝配置過程簡(jiǎn)介

1. 配置DHCP

more?/etc/dhcpd.conf    #?DHCP?Server?Configuration?file.  #?see?/usr/share/doc/dhcp*/dhcpd.conf.sample  #  #?Location:?Zhangjiang?IDC  #?Date:?2010-08-01  ?  ddns-update-style?interim;  ignore?client-updates;  allow?booting;  allow?bootp;  ?  subnet?192.168.1.0?netmask?255.255.255.0?{  ????????option?routers?192.168.1.254;  ????????option?subnet-mask?255.255.255.0;  ????????option?domain-name-servers?192.168.1.254;  ????????option?time-offset?-18000;?#?Eastern?Standard?Time  ????????range?dynamic-bootp?192.168.1.10?192.168.1.250;  ????????default-lease-time?21600;  ????????max-lease-time?43200;    #?Group?the?PXE?bootable?hosts  #?PXE-server?configuration?direction  ????????next-server?192.168.1.254;?#指向nfs服務(wù)器  ????????filename?"/pxelinux.0";?#/tftp根目錄下的啟動(dòng)引導(dǎo)文件  ?  ????????#?we?want?the?nameserver?to?appear?at?a?fixed?address  ????????host?ns?{  ????????????????hardware?ethernet?00:1C:25:80:F4:58;?#張江機(jī)房的筆記本網(wǎng)卡mac  ????????????????fixed-address?192.168.1.2;  ????????}  }

重啟dhcp服務(wù):

/etc/init.d/dhcpd?restart

?

2. 配置TFTP

more?/etc/xinetd.d/tftp?    #?default:?off  #?description:?The?tftp?server?serves?files?using?the?trivial?file?transfer?  #???????protocol.??The?tftp?protocol?is?often?used?to?boot?diskless?  #???????workstations,?download?configuration?files?to?network-aware?printers,?  #???????and?to?start?the?installation?process?for?some?operating?systems.  service?tftp  {  ????????socket_type??????????=?dgram  ????????protocol????????????????=?udp  ????????wait??????????????????????=?yes  ????????user??????????????????????=?root  ????????server???????????????????=?/usr/sbin/in.tftpd  ????????server_args??????????=?-u?nobody?-s?/tftpboot??#-s指定tftp根目錄  ????????disable??????????????????=?no????????#默認(rèn)yes,關(guān)閉  ????????per_source????????????=?11  ????????cps????????????????????????=?100?2  ????????flags??????????????????????=?IPv4  }

?

重啟tftp服務(wù):

/etc/init.d/xinetd.restart

?

查看tftp服務(wù)是否啟動(dòng):

chkconfig?–list?|?grep?tftp

?

3. 配置NFS

NFS需要向RPC注冊(cè)才能被客戶端調(diào)用,一般做端口映射的portmap是默認(rèn)安裝的,沒有的話可以使用yum安裝:

yum?–y?install?portmap*

?

可以直接使用掛載的鏡像,這里是拷到服務(wù)器上為了建立一個(gè)專門存放常用的鏡像文件建的目錄。

?

mount?/dev/cdrom?/mnt  mkdir?/ios/CentOS_5.4  cp?–a?/mnt/*?/ios/CentOS_5.4

?

#共享tftp的根目錄,192.168.1.0/24網(wǎng)段的用戶有只讀權(quán)限  echo?"/tftpboot?192.168.1.0/24(ro,sync)"?>?/etc/exports    #共享存放鏡像文件的目錄,所有用戶有只讀權(quán)限  echo?"/ios/CentOS_5.4?*(ro,sync)"?>>?/etc/exports

?

#不重啟nfs服務(wù)器情況下配置生效  exportfs?–arv?    #重啟服務(wù)  /etc/init.d/portmap?restart  /etc/init.d/nfs?resart

?

查看共享目錄是否生效:

showmount?–e?localhost

?

4. 配置PXE啟動(dòng)需要的文件

cp?/usr/lib/syslinux/pxelinux.0?/tftpboot

# pxelinux.0依賴于syslinux,沒有安裝使用yumyum –y install syslinux*

# pxelinux.0PXE啟動(dòng)引導(dǎo)文件

?

cp?/ios/CentOS_5.4/ioslinux/vmlinuz?/tftpboot  cp?/ios/CentOS_5.4/ioslinux/initrd.img?/tftpboot

# vmlinuzinitrd.img是不同版本的系統(tǒng)內(nèi)核和系統(tǒng)引導(dǎo)文件,安裝不同版本系統(tǒng)時(shí)請(qǐng)使用各版本的vmlinuzinitrd.img

?

mkdir?/tftpboot/pxelinux.cfg  cp?/ios/CentOS_5.4/ioslinux.cfg?/tftpboot/pxelinux.cfg/default

?

到目前已經(jīng)可以從網(wǎng)絡(luò)安裝系統(tǒng)了。測(cè)試如下:

啟動(dòng)服務(wù)器,一般F12進(jìn)入PXE網(wǎng)絡(luò)啟動(dòng),向DHCP請(qǐng)求IPDHCP響應(yīng)包含IP地址和pxelinux啟動(dòng)程序位置;PXE客戶端收到響應(yīng)后,向服務(wù)器請(qǐng)求傳送文件(pxelinux.0pxelinux.cfg/defaultvmlinuzinitrd.img);客戶端通過pxelinux.cfg/default文件成功的引導(dǎo)Linux安裝內(nèi)核后,安裝程序首先必須確定你通過什么安裝介質(zhì)來安裝linux,如果是通過網(wǎng)絡(luò)安裝(NFS, FTP, HTTP),則會(huì)在這個(gè)時(shí)候初始化網(wǎng)絡(luò),并定位安裝源位置。(由于PXE獲取的是安裝用的內(nèi)核以及安裝程序等,而安裝程序要獲取的是安裝系統(tǒng)所需的二進(jìn)制包以及配置文件,它們需要的內(nèi)容不同造成PXE模塊和安裝程序是相對(duì)獨(dú)立的,PXE的網(wǎng)絡(luò)配置并不能傳遞給安裝程序,從而進(jìn)行兩次獲取IP地址過程)。

?

5. 配置ks.cfg文件

ks.cfg文件可以由以下方法生成:

1. 每次裝好一臺(tái)CentOS(RedHat),安裝程序都會(huì)自動(dòng)創(chuàng)建一個(gè)kickstart文件,文件記錄了真實(shí)的安裝配置,位置在/root/anaconda-ks.cfg,可以根據(jù)此配置來生成自己需要的ks.cfg文件;

2. 使用圖形化的kickstart配置工具,命令:system-config-kickstart;

3. 使用文本編輯器編輯。

?以下是已經(jīng)寫好的ks.cfg文件,僅供參考:?

more?/ios/ks.cfg    #?Kickstart?file?automatically?generated?by?anaconda.    install  nfs?--server=192.168.1.254?--dir=/ios/CentOS_5.4  #指出NFS的路徑和安裝文件的位置    lang?en_US.UTF-8  keyboard?us    network?--device?eth0?--onboot?yes?--bootproto?dhcp?--hostname?test  #network?--device?eth0?--onboot?yes?–bootproto?static?--ip?192.168.1.10?--netmask?255.255.255.0?--gateway?192.168.1.1?--nameserver?8.8.8.8?--hostname?test  #一個(gè)網(wǎng)卡獲得地址的方式  network?--device?eth1?--onboot?no?--bootproto?dhcp?--hostname?test    rootpw?--iscrypted?$1$V26J9f5V$A7k9alSJs1GzG.qNBef6f/  #加密root密碼    firewall?--disabled?#--port=22:tcp  authconfig?--enableshadow?--enablemd5  #使用md5認(rèn)證    selinux?--disabled    timezone?--utc?Asia/Shanghai    bootloader?--location=mbr?--driveorder=sda    #?The?following?is?the?partition?information?you?requested  #?Note?that?any?partitions?you?deleted?are?not?expressed  #?here?so?unless?you?clear?all?partitions?first,?this?is  #?not?guaranteed?to?work    clearpart?--linux  part?/boot?--fstype?ext3?--size=100?--ondisk=sda  part?swap?--size=2048?--ondisk=sda  part?/?--fstype?ext3?--size=100?–grow?--ondisk=sda    #分區(qū)和選包是機(jī)房最頭疼的事,在這里可以修改  #clearpart?--linux?--drives=sda  #part?/boot?--fstype?ext3?--size=200  #part?pv.2?--size=0?--grow?--ondisk=sda  #volgroup?VolGroup00?--pesize=32768?pv.2  #logvol?/?--fstype?ext3?--name=LogVol00?--vgname=VolGroup00?--size=1024?--grow  #logvol?swap?--fstype?swap?--name=LogVol01?--vgname=VolGroup00?--size=1000?--grow?--maxsize=6144  #以上是一個(gè)LVM分區(qū)的示范    reboot?#安裝完畢后重啟?    %packages  @development-libs  @development-tools  @admin-tools  @editors  #選包

?

將配置好的ks.cfg文件放在共享目錄內(nèi),這里放到/ios下

echo?"/ios?192.168.1.0/24(ro,sync)"?>>?/etc/exports  exportfs?–arv

?

?修改/tftpboot/pxelinux.cfg/default配置:?

more?/tftpboot/pxelinux.cfg/default    default?ks????#默認(rèn)從標(biāo)簽ks啟動(dòng)  prompt?1?????#顯示"boot:"提示符  timeout?30??#等待超時(shí)時(shí)間    display?boot.msg?#/tftpboot/boot.msg默認(rèn)顯示boot.msg,可以根據(jù)實(shí)際情況編輯,  F1?boot.msg  F2?options.msg  F3?general.msg  F4?param.msg  F5?rescue.msg?    label?linux?#在boot:提示符后輸入linux(只是一個(gè)標(biāo)簽),從下面指出的內(nèi)核啟動(dòng)    kernel?vmlinuz    append?initrd=initrd.img    label?text?#在boot:提示符后輸入text,這里是文字界面安裝    kernel?vmlinuz    append?initrd=initrd.img?text    label?ks?#default默認(rèn),從ks.cfg讀取安裝信息,無需人工干預(yù)    kernel?vmlinuz    append?ks=nfs:192.168.1.254:/ios/ks.cfg?initrd=initrd.img?ksdevice=link    #ksdevice=link,從連接的網(wǎng)卡讀取安裝文件    label?local    localboot?1    label?mem    kernel?memtest    append?-

?

6. 進(jìn)階

由于機(jī)房目前常安裝的系統(tǒng)是RHEL4.7, RHEL4.7 x86_64, CentOS5.4, CentOS5.4 x86_64。可以將四種鏡像放在專門的目錄內(nèi)。例如:

RHEL4.7/ios/rhel4.7

RHEL4.7 x86_64: /ios/rhel4.7-x86_64

CentOS5.4: /ios/centos5.4

CentOS5.4 x86_64: /ios/centos5.4- x86_64

?

/tftp根目錄(這里是/tftpboot下,各版本的內(nèi)核和引導(dǎo)文件也需要改變位置:

RHEL4.7/ios/rhel4.7/vmlinuz

  ? ? ? ? ? ??/ios/rhel4.7/initrd.img

RHEL4.7 x86_64: /ios/ rhel4.7-x86_64/vmlinuz

? ? ? ? ? ? ? ? ? ? ? ? ? ? /ios/ rhel4.7-x86_64/initrd.img

CentOS5.4: /ios/centos5.4/vmlinuz

? ? ? ? ? ? ? ? ? /ios/centos5.4/initrd.img

CentOS5.4 x86_64: /ios/centos5.4- x86_64/vmlinuz

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /ios/centos5.4- x86_64/ initrd.img

?

PXE引導(dǎo)文件(這里是/tftpboot/pxelinux.cfg/default)修改:

default?3  prompt?1  timeout?300    display?boot.msg  F1?boot.msg  F2?options.msg  F3?general.msg  F4?param.msg  F5?rescue.msg    ?  label?1    kernel?rhel4.7/vmlinuz    append?initrd=rhel4.7/initrd.img    label?2    kernel?rhel4.7-x86_64/vmlinuz    append?initrd=rhel4.7-x86_64/initrd.img    label?3    kernel?centos5.4/vmlinuz    append?initrd=centos5.4/initrd.img    label?4    kernel?centos5.4-x86_64/vmlinuz    append?initrd=centos5.4-x86_64/initrd.img    label?1-ks_**    kernel?rhel4.7/vmlinuz    append?ks=nfs:192.168.1.254:/ios/rhel4.7ks_**.cfg?initrd=rhel4.7/initrd.img?ksdevice=link    label?2-ks_**    kernel?rhel4.7-x86_64/vmlinuz    append?ks=nfs:192.168.1.254:/ios/rhel4.7-x86_64ks_**.cfg?initrd=rhel4.7-x86_64/initrd.img?ksdevice=link    label?3-ks_**    kernel?centos5.4/vmlinuz    append?ks=nfs:192.168.1.254:/ios/centos5.4ks_**.cfg?initrd=centos5.4/initrd.img?ksdevice=link    label?4-ks_**    kernel?centos5.4-x86_64/vmlinuz    append?ks=nfs:192.168.1.254:/ios/centos5.4-x86_64ks_**.cfg?initrd=centos5.4-x86_64/initrd.img?ksdevice=link    label?local    localboot?0    label?mem    kernel?memtest    append?–

?

這里由于選項(xiàng)太多,可以在tftp根目錄下啟用boot.msgoptions.msg文件來說明安裝什么樣的操作系統(tǒng)和怎樣安裝操作系統(tǒng)。如:

boot.msgInstall?RHEL4.7:?1  Install?RHEL4.7?x86_64:?2  Install?CentOS5.4:?3  Install?CentOS5.4?x86_64:?4    Default:?Graph?mode.  If?you?want?to?use?text?mode,?type:?[number]?text    F1:?boot.msg?F2:?options.msg

?

options.msgInstall?RHEL4.7:?1  Install?RHEL4.7?x86_64:?2  Install?CentOS5.4:?3  Install?CentOS5.4?x86_64:?4    Default:?Graph?mode.  If?you?want?to?use?text?mode,?type:?[number]?text    If?you?want?to?use?kickstart,?the?flowing?list?the?different?OS?ks.cfg:  1-ks_**:?RHEL4.7  2-ks_**:?RHEL4.7?x86_64  3-ks_**:?CentOS5.4  4-ks_**:?CentOS5.4?x86_64    F1:?boot.msg?F2:?options.msg

?

7. 小結(jié)

只要注意各操作系統(tǒng)的內(nèi)核和引導(dǎo)文件的對(duì)應(yīng)關(guān)系,就能擴(kuò)展到多套系統(tǒng)。

kickstart文件能在原來的基礎(chǔ)上修改的就在原來的基礎(chǔ)上修改,稍加時(shí)日,就可以形成針對(duì)各業(yè)務(wù)不同的kickstart文件,這樣就方便IDC人員實(shí)現(xiàn)Linux操作系統(tǒng)的自動(dòng)化安裝。

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊15 分享