本發(fā)明涉及pxe測(cè)試技術(shù)領(lǐng)域,具體地說(shuō)是一種自動(dòng)化搭建pxe測(cè)試環(huán)境的方法。
背景技術(shù):
pxe技術(shù)簡(jiǎn)單說(shuō)就是利用網(wǎng)卡上的pxebootrom(自啟動(dòng)芯片)截取系統(tǒng)引導(dǎo)控制權(quán),通過(guò)dhcp指定的tftp服務(wù)下載系統(tǒng)啟動(dòng)所需的鏡像文件,然后根據(jù)提供的安裝路徑進(jìn)行遠(yuǎn)程系統(tǒng)安裝。在linux平臺(tái)上架設(shè)pxe服務(wù)器通常包括三部分服務(wù)的配置,dhcp自動(dòng)分配ip地址的服務(wù)(dhcpd),啟動(dòng)文件傳輸所需的tftp服務(wù)(xinetd),安裝文件傳輸所需的服務(wù)。其中安裝文件傳輸所用的服務(wù)可選ftp服務(wù)(vsftpd)、nfs服務(wù)(portmap)或http服務(wù)(httpd)三者中的任意一種。
公開(kāi)的相關(guān)專利文件:名稱為“一種pxe測(cè)試環(huán)境實(shí)現(xiàn)os自動(dòng)切換的方法”,該文件公開(kāi)了“該pxe測(cè)試環(huán)境實(shí)現(xiàn)os自動(dòng)切換的方法,首先安裝pxe服務(wù)器,搭建pxe測(cè)試網(wǎng)絡(luò);編寫pxe啟動(dòng)文件,將pxe客戶端首先要進(jìn)入的os設(shè)置為默認(rèn)啟動(dòng)項(xiàng);pxe客戶端從pxe測(cè)試網(wǎng)絡(luò)啟動(dòng),進(jìn)入默認(rèn)的os,開(kāi)始測(cè)試;測(cè)試完成后,以網(wǎng)卡mac地址為原型編寫專屬啟動(dòng)文件,將重啟后要進(jìn)入的os設(shè)置成默認(rèn)啟動(dòng)項(xiàng);pxe客戶端重新啟動(dòng)后,開(kāi)始調(diào)用引導(dǎo)文件,按照優(yōu)先級(jí)關(guān)系調(diào)用對(duì)應(yīng)的專屬引導(dǎo)文件,引導(dǎo)進(jìn)入期望的os。該pxe測(cè)試環(huán)境實(shí)現(xiàn)os自動(dòng)切換的方法,既實(shí)現(xiàn)了pxe測(cè)試過(guò)程中os的自動(dòng)切換,又不改變pxe服務(wù)器啟動(dòng)default文件,不影響其他pxe客戶端測(cè)試,各pxe客戶端os切換時(shí)互不影響,極大地提高了pxe測(cè)試效率”。
上述公開(kāi)文件與本
技術(shù)實(shí)現(xiàn)要素:
要解決的技術(shù)問(wèn)題,采用的技術(shù)手段都不相同。
發(fā)明內(nèi)容
本發(fā)明的技術(shù)任務(wù)是提供一種自動(dòng)化搭建pxe測(cè)試環(huán)境的方法。
本發(fā)明的技術(shù)任務(wù)是按以下方式實(shí)現(xiàn)的,該方法是基于linux下的shell腳本來(lái)運(yùn)行搭建的,在shell環(huán)境下運(yùn)用腳本自動(dòng)化的快速搭建pxe測(cè)試環(huán)境。
該方法的操作步驟如下:
步驟1)服務(wù)器安裝linux操作系統(tǒng),并且所在的網(wǎng)絡(luò)環(huán)境有dhcp服務(wù);
步驟2)將服務(wù)器的linux系統(tǒng)鏡像放到/tmp下,并記錄下鏡像的名字;
步驟3)執(zhí)行shell環(huán)境下的腳本自動(dòng)化的快速搭建pxe測(cè)試環(huán)境。
所述的shell環(huán)境下的腳本如下:
#!/bin/bash
#thisisaautoconfigureforpxeserver!
echo"pleasecopythecdrominto/tmpandtheninputthenameofthefile(rhel6.6forexample)"
readcdrom
mount-oloop/tmp/$cdrom/mnt
#creatmyyumtoinstallnecessaryservice
touch/etc/yum.repos.d/yum.repo
echo"[myyum]">/etc/yum.repos.d/yum.repo
echo"name=redhatmyyum">>/etc/yum.repos.d/yum.repo
echo"url=file:///mnt/">>/etc/yum.repos.d/yum.repo
echo"enabled=1">>/etc/yum.repos.d/yum.repo
echo"gpgcheck=0">>/etc/yum.repos.d/yum.repo
echo"gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-redhat-release">>/etc/yum.repos.d/yum.repo
#setstaticip
servicenetworkmanagerstop
echo"thenetworkinyourlinux:"
ifconfig
echo"pleaseinputthenetworknamefordhcpserver"
readdh
touch/etc/sysconfig/network-scripts/ifcfg-$dh
echo"pleaseinputtheipyouwantorpreassentertoleaveitasdefault(192.168.1.11)"
readip
echo"device=$dh">/etc/sysconfig/network-scripts/ifcfg-$dh
echo"onboot=yes">>/etc/sysconfig/network-scripts/ifcfg-$dh
echo"bootproto=static">>/etc/sysconfig/network-scripts/ifcfg-$dh
if["$ip"=""]
then
ip=192.168.1.11
fi
echo"ipaddr=$ip">>/etc/sysconfig/network-scripts/ifcfg-$dh
echo"netmask=255.255.255.0">>/etc/sysconfig/network-scripts/ifcfg-$dh
servicenetworkrestart
#installtftpdhcpnfsservice
yuminstalltftp*dhcp*nfs*syslinuxsystem-config-kickstart
#configuredhcpservice
touch/etc/dhcp/dhcpd.conf
echo"allowbooting;">/etc/dhcp/dhcpd.conf
echo"allowbootp;">>/etc/dhcp/dhcpd.conf
echo"subnet192.168.1.0netmask255.255.255.0">>/etc/dhcp/dhcpd.conf
echo"{">>/etc/dhcp/dhcpd.conf
echo"range192.168.1.50192.168.1.100;">>/etc/dhcp/dhcpd.conf
echo"optionrouters192.168.1.11;">>/etc/dhcp/dhcpd.conf
echo"optionsubnet-mask255.255.255.0;">>/etc/dhcp/dhcpd.conf
echo"next-server192.168.1.11;">>/etc/dhcp/dhcpd.conf
echo"}">>/etc/dhcp/dhcpd.conf
#configurenfs
mkdir/nfs
touch/etc/exports
echo"/nfs192.168.1.0/24(ro)">/etc/exports
#configuretftpservice
servicexinetdstart
servicedhcpdstart
servicenfsstart
chkconfigtftpon
chkconfigdhcpdon
chkconfignfson
cp-v/usr/share/syslinux/{pxelinux.0,vesamenu.c32}/var/lib/tftpboot
mkdir/var/lib/tftpboot/pxelinux.cfg
mkdir/var/lib/tftpboot/$cdrom
cp/mnt/images/pxeboot/{initrd.img,vmlinuz}/var/lib/tftpboot/$cdrom
cp/root/anaconda-ks.cfg/nfs/$cdrom.cfg
mkdir/nfs/$cdrom
cp-rf/mnt//nfs/$cdrom
touch/var/lib/tftpboot/pxelinux.cfg/default
echo"defaultvesamenu.c32">>/var/lib/tftpboot/pxelinux.cfg/default
echo"timeout100">>/var/lib/tftpboot/pxelinux.cfg/default
echo"labelauto">>/var/lib/tftpboot/pxelinux.cfg/default
echo"menulabelautoinstall$cdrom">>/var/lib/tftpboot/pxelinux.cfg/default
echo"menudefault">>/var/lib/tftpboot/pxelinux.cfg/default
echo"kernel$cdrom/vmlinuz">>/var/lib/tftpboot/pxelinux.cfg/default
echo"appendinitrd=$cdrom/initrd.imgks=nfs:192.168.1.11:/nfs/$cdrom.cfg">>/var/lib/tftpboot/pxelinux.cfg/default。
本發(fā)明的一種自動(dòng)化搭建pxe測(cè)試環(huán)境的方法和現(xiàn)有技術(shù)相比,對(duì)于大批量安裝系統(tǒng)具有深遠(yuǎn)意義,通過(guò)這個(gè)自動(dòng)化的環(huán)境配置腳本,能夠在短時(shí)間內(nèi)快速的配置好pxe環(huán)境,進(jìn)而為接下來(lái)的測(cè)試和生產(chǎn)提供一個(gè)大的環(huán)境基礎(chǔ),縮短了人工配置的時(shí)間和誤差。
具體實(shí)施方式
實(shí)施例1:
該自動(dòng)化搭建pxe測(cè)試環(huán)境的方法是基于linux下的shell腳本來(lái)運(yùn)行搭建的,在shell環(huán)境下運(yùn)用腳本自動(dòng)化的快速搭建pxe測(cè)試環(huán)境。
操作步驟如下:
步驟1)服務(wù)器安裝linux操作系統(tǒng),并且所在的網(wǎng)絡(luò)環(huán)境有dhcp服務(wù);
步驟2)將服務(wù)器的linux系統(tǒng)鏡像放到/tmp下,并記錄下鏡像的名字;
步驟3)執(zhí)行shell環(huán)境下的腳本自動(dòng)化的快速搭建pxe測(cè)試環(huán)境。
所述的shell環(huán)境下的腳本如下:
#!/bin/bash
#thisisaautoconfigureforpxeserver!
echo"pleasecopythecdrominto/tmpandtheninputthenameofthefile(rhel6.6forexample)"
readcdrom
mount-oloop/tmp/$cdrom/mnt
#creatmyyumtoinstallnecessaryservice
touch/etc/yum.repos.d/yum.repo
echo"[myyum]">/etc/yum.repos.d/yum.repo
echo"name=redhatmyyum">>/etc/yum.repos.d/yum.repo
echo"url=file:///mnt/">>/etc/yum.repos.d/yum.repo
echo"enabled=1">>/etc/yum.repos.d/yum.repo
echo"gpgcheck=0">>/etc/yum.repos.d/yum.repo
echo"gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-redhat-release">>/etc/yum.repos.d/yum.repo
#setstaticip
servicenetworkmanagerstop
echo"thenetworkinyourlinux:"
ifconfig
echo"pleaseinputthenetworknamefordhcpserver"
readdh
touch/etc/sysconfig/network-scripts/ifcfg-$dh
echo"pleaseinputtheipyouwantorpreassentertoleaveitasdefault(192.168.1.11)"
readip
echo"device=$dh">/etc/sysconfig/network-scripts/ifcfg-$dh
echo"onboot=yes">>/etc/sysconfig/network-scripts/ifcfg-$dh
echo"bootproto=static">>/etc/sysconfig/network-scripts/ifcfg-$dh
if["$ip"=""]
then
ip=192.168.1.11
fi
echo"ipaddr=$ip">>/etc/sysconfig/network-scripts/ifcfg-$dh
echo"netmask=255.255.255.0">>/etc/sysconfig/network-scripts/ifcfg-$dh
servicenetworkrestart
#installtftpdhcpnfsservice
yuminstalltftp*dhcp*nfs*syslinuxsystem-config-kickstart
#configuredhcpservice
touch/etc/dhcp/dhcpd.conf
echo"allowbooting;">/etc/dhcp/dhcpd.conf
echo"allowbootp;">>/etc/dhcp/dhcpd.conf
echo"subnet192.168.1.0netmask255.255.255.0">>/etc/dhcp/dhcpd.conf
echo"{">>/etc/dhcp/dhcpd.conf
echo"range192.168.1.50192.168.1.100;">>/etc/dhcp/dhcpd.conf
echo"optionrouters192.168.1.11;">>/etc/dhcp/dhcpd.conf
echo"optionsubnet-mask255.255.255.0;">>/etc/dhcp/dhcpd.conf
echo"next-server192.168.1.11;">>/etc/dhcp/dhcpd.conf
echo"}">>/etc/dhcp/dhcpd.conf
#configurenfs
mkdir/nfs
touch/etc/exports
echo"/nfs192.168.1.0/24(ro)">/etc/exports
#configuretftpservice
servicexinetdstart
servicedhcpdstart
servicenfsstart
chkconfigtftpon
chkconfigdhcpdon
chkconfignfson
cp-v/usr/share/syslinux/{pxelinux.0,vesamenu.c32}/var/lib/tftpboot
mkdir/var/lib/tftpboot/pxelinux.cfg
mkdir/var/lib/tftpboot/$cdrom
cp/mnt/images/pxeboot/{initrd.img,vmlinuz}/var/lib/tftpboot/$cdrom
cp/root/anaconda-ks.cfg/nfs/$cdrom.cfg
mkdir/nfs/$cdrom
cp-rf/mnt//nfs/$cdrom
touch/var/lib/tftpboot/pxelinux.cfg/default
echo"defaultvesamenu.c32">>/var/lib/tftpboot/pxelinux.cfg/default
echo"timeout100">>/var/lib/tftpboot/pxelinux.cfg/default
echo"labelauto">>/var/lib/tftpboot/pxelinux.cfg/default
echo"menulabelautoinstall$cdrom">>/var/lib/tftpboot/pxelinux.cfg/default
echo"menudefault">>/var/lib/tftpboot/pxelinux.cfg/default
echo"kernel$cdrom/vmlinuz">>/var/lib/tftpboot/pxelinux.cfg/default
echo"appendinitrd=$cdrom/initrd.imgks=nfs:192.168.1.11:/nfs/$cdrom.cfg">>/var/lib/tftpboot/pxelinux.cfg/default。
通過(guò)上面具體實(shí)施方式,所述技術(shù)領(lǐng)域的技術(shù)人員可容易的實(shí)現(xiàn)本發(fā)明。但是應(yīng)當(dāng)理解,本發(fā)明并不限于上述的幾種具體實(shí)施方式。在公開(kāi)的實(shí)施方式的基礎(chǔ)上,所述技術(shù)領(lǐng)域的技術(shù)人員可任意組合不同的技術(shù)特征,從而實(shí)現(xiàn)不同的技術(shù)方案。