前段时间公司要建设自己的云中心,部署上百台服务器,那么问题来了,我总不能一台一台的安装吧,于是想到了PXE方式安装。

PXE使用动态主机配置协议(DHCP)和简单文件传输协议(TFTP)通过网络引导操作系统
PXE安装过程概览:


DHCP服务器会提供给ESXi主机TFTP服务器IP地址、指向pxelinux.0目录的指针、目标计算机使用 DHCP 服务器来获取 IP 地址。

TFTP服务器用于网络引导系统,简单来说就是传输系统安装文件和pxelinux.0(pxelinux.0二进制文件、配置文件、内核以及其他文件)

HTTP服务器用于存放ks.cfg脚本

Syslinux是一个功能强大的引导加载程序,而且兼容各种介质

PXE配置文件说明:

PXE 引导 ESXi 安装_PXE

下面详细说明下步骤:

准备工作:

操作系统:centos7.0(其他版本也可以 )

安装 DHCP   TFTP-server  syslinux  httpd

 

1、DHCP服务器的安装配置:

Yum install dhcp


# dhcpd.conf

# Sample configuration file for ISC dhcpd

# option definitions common to all supportednetworks..

default-lease-time 600;

max-lease-time 7200;

# Use this to enble / disable dynamic dns updatesglobally.

ddns-update-style none;

allow booting;

allow bootp;

class "pxeclients" {

match if substring(option vendor-class-identifier, 0,9) = "PXEClient";

next-server 192.168.10.145;        //指定TFTP服务器地址,设置服务器从引导文件中安装。

filename = "pxelinux.0";       //开始启动文件的名称,应用于无盘工作站。

}

subnet 192.168.10.0 netmask 255.255.255.0 {

range 192.168.10.100 192.168.10.250;

}

 

2、TFTP服务器的安装配置:

Yum install xinetd

Yum install tftp

Yum install tftp-server

打开/etc/xinetd.d/tftp disable = no  server_args = -s/var/lib/tftpboot/

解压ESXi.iso镜像,复制镜像到tftpboot目录下的esxi目录下
mount -o loop -t iso9660 /tmp/VMware-VMvisor-Installer-5.5.0-1331820.x86_64.iso /mnt/iso/

cd /mnt/iso/

cp *.* /var/lib/tftpboot/esxi/

 

yuminstall syslinux

Syslinux配置:

首先安装syslinux  进入syslinux目录 复制/usr/share/syslinux/pxelinux.0

/usr/share/syslinux/menu.c32 到/var/lib/tftpboot/下

 

创建 PXE 配置文件

mkdir /tftpboot/pxelinux.cfg

将/var/lib/tftpboot/esxi/isolinux.cfg  复制到 pxelinux.cfg目录下,名称可以为default

(     关于PXE 配置文件的文件名说明:

对于PXE 配置文件的文件名,请选择以下选项之一:

1   01-mac_address_of_target_ESXi_host。例如,01-23-45-67-89-0a-bc

2   以十六进制表示的目标ESXi 主机IP 地址。

3   default    )


cp  /var/lib/tftpboot/esxi/isolinux.cfg  /var/lib/tftpboot/pxelinux.cfg/default

内容如下(默认目录为var/lib/tftpboot,我在KERNEL esxi/mboot.c32

  APPEND -cesxi/boot.cfg处写过绝对路径,但是结果提示找不到对应文件,所以修改成了相对路径):

DEFAULT menu.c32

MENU TITLE ESXi-5.5.0-20140302001-standard Boot Menu

NOHALT 1

PROMPT 0

TIMEOUT 80

LABEL install

  KERNEL /esxi/mboot.c32

  APPEND -c /esxi/boot.cfg       //esxi前面的斜杠不能少

  MENU LABELESXi-5.5.0-20140302001-standard ^Installer

LABEL hddboot

  LOCALBOOT 0x80

  MENU LABEL^Boot from local disk

 

修改boot.cfg:

cd /var/lib/tftpboot/esxi/
sed -e "s#/##g" -e "3s#^#prefix=/`basename $PWD`/\n#" -i.bak boot.cfg

这里需要进入boot.cfg看一下,如果prefix=/esxi/修改为prefix=esxi/

修改前:

bootstate=0

title=Loading ESXi installer

kernel=/tboot.b00

kernelopt=runweasel

modules=/b.b00 --- /jumpstrt.gz --- /useropts.gz ---/k.b00 --- /chardevs.b00 --- /a.b00 --- /user.b00 --- /sb.v00 --- /s.v00 ---/ata_pata.v00 --- /ata_pata.v01 --- /ata_pata.v02 --- /ata_pata.v03 --- /ata_pata.v04--- /ata_pata.v05 --- /ata_pata.v06 --- /ata_pata.v07 --- /block_cc.v00 ---/ehci_ehc.v00 --- /elxnet.v00 --- /weaselin.t00 --- /esx_dvfi.v00 ---/xlibs.v00 --- /ima_qla4.v00 --- /ipmi_ipm.v00 --- /ipmi_ipm.v01 ---/ipmi_ipm.v02 --- /lpfc.v00 --- /lsi_mr3.v00 --- /lsi_msgp.v00 ---/misc_cni.v00 --- /misc_dri.v00 --- /mtip32xx.v00 --- /net_be2n.v00 ---/net_bnx2.v00 --- /net_bnx2.v01 --- /net_cnic.v00 --- /net_e100.v00 ---/net_e100.v01 --- /net_enic.v00 --- /net_forc.v00 --- /net_igb.v00 --- /net_ixgb.v00--- /net_mlx4.v00 --- /net_mlx4.v01 --- /net_nx_n.v00 --- /net_tg3.v00 ---/net_vmxn.v00 --- /ohci_usb.v00 --- /qlnative.v00 --- /rste.v00 ---/sata_ahc.v00 --- /sata_ata.v00 --- /sata_sat.v00 --- /sata_sat.v01 ---/sata_sat.v02 --- /sata_sat.v03 --- /sata_sat.v04 --- /scsi_aac.v00 ---/scsi_adp.v00 --- /scsi_aic.v00 --- /scsi_bnx.v00 --- /scsi_bnx.v01 ---/scsi_fni.v00 --- /scsi_hps.v00 --- /scsi_ips.v00 --- /scsi_lpf.v00 ---/scsi_meg.v00 --- /scsi_meg.v01 --- /scsi_meg.v02 --- /scsi_mpt.v00 --- /scsi_mpt.v01--- /scsi_mpt.v02 --- /scsi_qla.v00 --- /scsi_qla.v01 --- /uhci_usb.v00 ---/tools.t00 --- /xorg.v00 --- /imgdb.tgz --- /imgpayld.tgz

build=

updated=0

 

修改后:

bootstate=0

title=Loading ESXi installer

prefix=esxi/

kernel=tboot.b00

#kernelopt=runweasel

kernelopt=ks=http://192.168.10.145/KS/ks.cfg

modules=b.b00 --- jumpstrt.gz --- useropts.gz ---k.b00 --- chardevs.b00 --- a.b00 --- user.b00 --- sb.v00 --- s.v00 ---ata_pata.v00 --- ata_pata.v01 --- ata_pata.v02 --- ata_pata.v03 --- ata_pata.v04--- ata_pata.v05 --- ata_pata.v06 --- ata_pata.v07 --- block_cc.v00 ---ehci_ehc.v00 --- elxnet.v00 --- weaselin.t00 --- esx_dvfi.v00 --- xlibs.v00 ---ima_qla4.v00 --- ipmi_ipm.v00 --- ipmi_ipm.v01 --- ipmi_ipm.v02 --- lpfc.v00--- lsi_mr3.v00 --- lsi_msgp.v00 --- misc_cni.v00 --- misc_dri.v00 ---mtip32xx.v00 --- net_be2n.v00 --- net_bnx2.v00 --- net_bnx2.v01 ---net_cnic.v00 --- net_e100.v00 --- net_e100.v01 --- net_enic.v00 ---net_forc.v00 --- net_igb.v00 --- net_ixgb.v00 --- net_mlx4.v00 --- net_mlx4.v01--- net_nx_n.v00 --- net_tg3.v00 --- net_vmxn.v00 --- ohci_usb.v00 ---qlnative.v00 --- rste.v00 --- sata_ahc.v00 --- sata_ata.v00 --- sata_sat.v00--- sata_sat.v01 --- sata_sat.v02 --- sata_sat.v03 --- sata_sat.v04 ---scsi_aac.v00 --- scsi_adp.v00 --- scsi_aic.v00 --- scsi_bnx.v00 ---scsi_bnx.v01 --- scsi_fni.v00 --- scsi_hps.v00 --- scsi_ips.v00 ---scsi_lpf.v00 --- scsi_meg.v00 --- scsi_meg.v01 --- scsi_meg.v02 ---scsi_mpt.v00 --- scsi_mpt.v01 --- scsi_mpt.v02 --- scsi_qla.v00 --- scsi_qla.v01--- uhci_usb.v00 --- tools.t00 --- xorg.v00 --- imgdb.tgz --- imgpayld.tgz

build=

updated=0

 

去掉 /  ,添加prefix=esxi/  指定modules下的文件的前缀。

 

Httpd服务器的配置:

安装:yum install httpd

进入默认目录 /var/www/html/

创建KS目录,创建ks.cfg文件,内容如下:

# Accept the VMware End User License Agreement

vmaccepteula

# Set the root password for the DCUI and Tech SupportMode

rootpw wxk_123

# Set the keyboard type

keyboard 'United Kingdom'

# Install on the first local disk available on machine

install --firstdisk --overwritevmfs

# Configure a static IP Address on the first networkadapter

network --bootproto=dhcp --device=vmnic0

#Reboot after installation complete

reboot


service xinetd start

Service dhcpd start

service httpd restart



启动所有服务,完成,在服务器启动时bios中设置为从网络启动。

以上步骤都是通过实验完成的确认无误。

启动服务器开启网络启动。开始安装。