RHEL 6.5 PXE 安裝調試 VMWARE ESXi 5.1 安裝

測試環境:win10/vmware workstation 12 prohtml

操做系統:RHEL 6.5(PXE服務器)python

【2016.11.30】linux

 

【遺留問題】shell

一、ks.cfg經過本地文件方式加載不成功,只能經過http://方式成功 ,如下幾種嘗試都是不成功的。apache

   ks=file:esxi5.1/ks.cfg
   ks=ks.cfg
   ks=tftp://192.168.148.1/esxi5.1/ks.cfgvim

 

 

安裝與配置:windows


 。安裝DHCPapi

。安裝XINETD, 並啓用TFTP服務瀏覽器

。安裝syslinux(yum安裝):會自動在tftpboot目錄下放置pxelinux.0及seamenu.c32文件,還有一些其它文件bash

 

配置DHCP: 在地址分配子項中增長filename "pxelinux.0"

配置tftp: enable一下便可,無其它特殊配置,無需-c,整個過程不會向tftp寫文件

配置菜單:在tftpboot目錄下,建立一個文件夾:pxelinux.cfg。而後再創建default文件,即菜單文件

 

配置好以後,就能夠啓動一臺PXE客戶端進行測試了,正常狀況下,就能夠顯示菜單了。說明PXE配置成功了,接下來就能夠根據實際安裝需求,定製default文件、制定ks.cfg文件及佈署安裝包了。

 

 利用PXE方式安裝ESXi 5.1


參考文檔:主要是vmware的官方文檔 

準備:

  • 下載ESXi 5.1的ISO安裝包,並在tftpboot下創建目錄esxi5.1
  • 將iso文件解開後,將文件copy至esxi5.1下(不能只接將ISO mount到esxi5.1目錄,由於要修改文件) 

 配置:

     pxelinux.cfg/default文件: (能夠將esxi5.1中的isolinux.cfg文件COPY過來進行修改,主要修改成正確的目錄路徑)

default menu.c32
menu title PXE BOOT VMWARE ESXI
timeout 100

label ESXi
menu label Boot VMware ESXi
  kernel esxi5.1/mboot.c32
  append -c esxi5.1/boot.cfg     //注意此處boot.cfg要修改
  menu label esxi5.1-xxxxxx

//整個文件相對簡單,只是增長了相對目錄esxi5.1

 

  esxi5.1/boot.cfg文件:因爲原ISO是光盤模式的,故每一個文件都給出了絕對路徑/(根) 

[root@localhost esxi5.1]# cat boot.cfg
bootstate=0
title=Loading ESXi installer
kernel=/tboot.b00
kernelopt=runweasel
modules=/b.b00 --- /useropts.gz --- /k.b00 --- /chardevs.b00 --- /a.b00 --- /user.b00 --- /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 --- /weaselin.t00 --- /esx_dvfi.v00 --- /xlibs.v00 --- /ima_qla4.v00 --- /ipmi_ipm.v00 --- /ipmi_ipm.v01 --- /ipmi_ipm.v02 --- /misc_cni.v00 --- /misc_dri.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_nx_n.v00 --- /net_r816.v00 --- /net_r816.v01 --- /net_s2io.v00 --- /net_sky2.v00 --- /net_tg3.v00 --- /net_vmxn.v00 --- /ohci_usb.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_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 --- /scsi_rst.v00 --- /uhci_usb.v00 --- /tools.t00 --- /xorg.v00 --- /imgdb.tgz --- /imgpayld.tgz
build=
updated=0

  

 但因爲咱們採用PXE方式,文件再也不位於根,而是位於tftp服務器的esxi5.1目錄下,所以,須要將全部/替換成esxi5.1/xxx。操做以下:

首先,將全部/都替換掉,VI命令:%s#/##g

而後在modules這行前面加入一行:prefix=esxi5.1/ (這條命令全局有效,不在意所在位置)

「kernel=......」一行爲 kernel=tboot.b00,此處不加esxi5.1/

 

啓動pxe client測試:

經過上面設置後,啓動PXE CLIENT,基本就能出現安裝界面了,只須要選擇鍵盤、安裝位置,基本沒什麼選項(問題:在何處加載第三方驅動)。

這種方法只是實現了PXE安裝,但沒有實現無人值守的自動安裝。

 

ESXi 5實現全自動安裝(無需人工鏈接鍵盤、顯示器):這裏要用到ks.cfg文件(kickstart)


就增長兩個步驟:1)生成ks.cfg    2)在default文件中傳遞該ks.cfg文件給核心

任何一臺esxi安裝完成後,會自動生成一個etc/vmware/weasel/ks.cfg,可經過修改這個文件定製必要的參數,實驗中採用了以下ks.cfg

#
# Sample scripted installation file
#
# Accept the VMware End User License Agreement
vmaccepteula
# Set the root password for the DCUI and Tech Support Mode
rootpw iampeter319
# The install media is in the CD-ROM drive
install --firstdisk --overwritevmfs
# Set the network to DHCP on the first network adapater
#network --bootproto=dhcp --device=vmnic0
network --bootproto=static --device=vmnic0 --ip=192.168.148.100 --netmask=255.255.252.0 --gateway=192.168.148.1
reboot
# A sample post-install script
%post --interpreter=python --ignorefailure=true
import time
stampFile = open('/finished.stamp', mode='w')
stampFile.write( time.asctime() )

具體參數及語法,可參考vmware官方文檔。這裏只改了network項及安裝完成後自動reboot。

準備好ks.cfg文件後,須要將其位置傳遞給核心,能夠經過protocol:// , cdrom://, file://, usb://等方式。在實驗中,採用file方式沒有成功,緣由不詳。最後採用http://<PXESERVER_IP>/ks.cfg的方式(即將ks.cfg拷貝至apache的/var/www/html目錄下)

按照官方文檔的說明,應該是修改boot.cfg文件,經過kernelopt=ks=http://xxxx/ks.cfg進行傳遞。但感受這樣不方便,未採用,而採用了修改default文件的方法,效果同樣。

修改原boot.cfg文件中的倒數第二行,更改成以下:

 append -c esxi5.1/boot.cfg ks=http://192.168.148.128/ks.cfg

還有一種特殊的作法:ESXi在啓動成功後,會在其虛擬文件系統中產生一個/etc/vmware/weasel/ks.cfg文件。若是咱們傳遞以下格式: 

ks=file://etc/vmware/weasel/ks.cfg

則ESXi也會自動安裝,可是參數是不受控制的,由於是自動生成的。這種方式安裝完成後,密碼空,IP地址爲自動獲取。

【說明】在生成ks.cfg文件後,能夠不修改default文件進行傳遞,而是在ESXi開始安裝時,經過按Shift-O鍵,手工進行傳遞,以後就會自動進行了。

因爲ks的內容較多,如下是兩個例子,比較全面,全自動安裝而且自動設置包括:網絡、SSH、vSwitch等等

# Sample kickstart for ESXi 5.1
# William Lam
# www.virtuallyghetto.com
#########################################
 
accepteula
install --firstdisk --overwritevmfs
rootpw vmware123
reboot
#下面這句應該往前提,放在reboot以前,估計是做者手誤
%include /tmp/networkconfig %pre --interpreter=busybox # extract network info from bootup VMK_INT="vmk0" VMK_LINE=$(localcli network ip interface ipv4 get | grep "${VMK_INT}") IPADDR=$(echo "${VMK_LINE}" | awk '{print $2}') NETMASK=$(echo "${VMK_LINE}" | awk '{print $3}') GATEWAY=$(localcli network ip route ipv4 list | grep default | awk '{print $3}') DNS="172.30.0.100,172.30.0.200" HOSTNAME=$(nslookup "${IPADDR}" "${DNS}" | grep Address | grep "${IPADDR}" | awk '{print $4}') echo "network --bootproto=static --addvmportgroup=false --device=vmnic0 --ip=${IPADDR} --netmask=${NETMASK} --gateway=${GATEWAY} --nameserver=${DNS} --hostname=${HOSTNAME}" > /tmp/networkconfig %firstboot --interpreter=busybox # enable VHV (Virtual Hardware Virtualization to run nested 64bit Guests + Hyper-V VM) grep -i "vhv.enable" /etc/vmware/config || echo "vhv.enable = \"TRUE\"" >> /etc/vmware/config # enable & start remote ESXi Shell (SSH) vim-cmd hostsvc/enable_ssh vim-cmd hostsvc/start_ssh # enable & start ESXi Shell (TSM) vim-cmd hostsvc/enable_esx_shell vim-cmd hostsvc/start_esx_shell # supress ESXi Shell shell warning - Thanks to Duncan (http://www.yellow-bricks.com/2011/07/21/esxi-5-suppressing-the-localremote-shell-warning/) esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1 # ESXi Shell interactive idle time logout esxcli system settings advanced set -o /UserVars/ESXiShellInteractiveTimeOut -i 3600 # Change the default ESXi Admins group "ESX Admins" to a custom one "Ghetto ESXI Admins" for AD vim-cmd hostsvc/advopt/update Config.HostAgent.plugins.hostsvc.esxAdminsGroup string "Ghetto ESXi Admins" # Users that will have full access to DCUI even if they don't have admin permssions on ESXi host vim-cmd hostsvc/advopt/update DCUI.Access string root,william,tuan # Block VM guest BPDU packets, global configuration esxcli system settings advanced set -o /Net/BlockGuestBPDU -i 1 # copy SSH authorized keys & overwrite existing wget http://air.primp-industries.com/esxi5/id_dsa.pub -O /etc/ssh/keys-root/authorized_keys # disable SSH keys - uncomment the next section # sed -i 's/AuthorizedKeysFile*/#AuthorizedKeysFile/g' /etc/ssh/sshd_config # rename local datastore to something more meaningful vim-cmd hostsvc/datastore/rename datastore1 "$(hostname -s)-local-storage-1" # assign license vim-cmd vimsvc/license --set AAAAA-BBBBB-CCCCC-DDDDD-EEEEE ## SATP CONFIGURATIONS ## esxcli storage nmp satp set --satp VMW_SATP_SYMM --default-psp VMW_PSP_RR esxcli storage nmp satp set --satp VMW_SATP_DEFAULT_AA --default-psp VMW_PSP_RR ########################### ## vSwitch configuration ## ########################### ##################################################### # vSwitch0 : Active->vmnic0,vmnic1 Standby->vmnic2 # failback: yes # faildectection: beacon # load balancing: portid # notify switches: yes # avg bw: 1000000 Kbps # peak bw: 1000000 Kbps # burst size: 819200 KBps # allow forged transmits: yes # allow mac change: no # allow promiscuous no # cdp status: both # attach vmnic1,vmnic2 to vSwitch0 esxcli network vswitch standard uplink add --uplink-name vmnic1 --vswitch-name vSwitch0 esxcli network vswitch standard uplink add --uplink-name vmnic2 --vswitch-name vSwitch0 # configure portgroup esxcli network vswitch standard portgroup add --portgroup-name VMNetwork1 --vswitch-name vSwitch0 esxcli network vswitch standard portgroup set --portgroup-name VMNetwork1 --vlan-id 100 esxcli network vswitch standard portgroup add --portgroup-name VMNetwork2 --vswitch-name vSwitch0 esxcli network vswitch standard portgroup set --portgroup-name VMNetwork2 --vlan-id 200 esxcli network vswitch standard portgroup add --portgroup-name VMNetwork3 --vswitch-name vSwitch0 esxcli network vswitch standard portgroup set --portgroup-name VMNetwork3 --vlan-id 333 # configure cdp esxcli network vswitch standard set --cdp-status both --vswitch-name vSwitch1 ### FAILOVER CONFIGURATIONS ### # configure active and standby uplinks for vSwitch0 esxcli network vswitch standard policy failover set --active-uplinks vmnic0,vmnic1 --standby-uplinks vmnic2 --vswitch-name vSwitch0 # configure failure detection + load balancing (could have appended to previous line) esxcli network vswitch standard policy failover set --failback yes --failure-detection beacon --load-balancing portid --notify-switches yes --vswitch-name vSwitch0 ### SECURITY CONFIGURATION ### esxcli network vswitch standard policy security set --allow-forged-transmits yes --allow-mac-change no --allow-promiscuous no --vswitch-name vSwitch0 ### SHAPING CONFIGURATION ### esxcli network vswitch standard policy shaping set --enabled yes --avg-bandwidth 100000 --peak-bandwidth 100000 --burst-size 819200 --vswitch-name vSwitch0 ##################################################### # vSwitch1 : Active->vmnic3,vmnic4 Standby->vmnic5 # failback: no # faildectection: link # load balancing: mac # notify switches: no # allow forged transmits: no # allow mac change: no # allow promiscuous no # cdp status: listen # mtu: 9000 # add vSwitch1 esxcli network vswitch standard add --ports 256 --vswitch-name vSwitch1 # attach vmnic3,4,5 to vSwitch0 esxcli network vswitch standard uplink add --uplink-name vmnic3 --vswitch-name vSwitch1 esxcli network vswitch standard uplink add --uplink-name vmnic4 --vswitch-name vSwitch1 esxcli network vswitch standard uplink add --uplink-name vmnic5 --vswitch-name vSwitch1 # configure mtu + cdp esxcli network vswitch standard set --mtu 9000 --cdp-status listen --vswitch-name vSwitch1 # configure portgroup esxcli network vswitch standard portgroup add --portgroup-name NFS --vswitch-name vSwitch1 esxcli network vswitch standard portgroup add --portgroup-name FT_VMOTION --vswitch-name vSwitch1 esxcli network vswitch standard portgroup add --portgroup-name VSPHERE_REPLICATION --vswitch-name vSwitch1 ### FAILOVER CONFIGURATIONS ### # configure active and standby uplinks for vSwitch1 esxcli network vswitch standard policy failover set --active-uplinks vmnic3,vmnic4 --standby-uplinks vmnic5 --vswitch-name vSwitch1 # configure failure detection + load balancing (could have appended to previous line) esxcli network vswitch standard policy failover set --failback no --failure-detection link --load-balancing mac --notify-switches no --vswitch-name vSwitch1 ### SECURITY CONFIGURATION ### esxcli network vswitch standard policy security set --allow-forged-transmits no --allow-mac-change no --allow-promiscuous no --vswitch-name vSwitch1 # configure vmkernel interface for NFS traffic, FT_VMOTION and VSPHERE_REPLICATION traffic VMK0_IPADDR=$(esxcli network ip interface ipv4 get | grep vmk0 | awk '{print $2}') VMK1_IPADDR=$(echo ${VMK0_IPADDR} | awk '{print $1".51."$3"."$4}' FS=.) VMK2_IPADDR=10.10.0.2 VMK3_IPADDR=10.20.0.2 esxcli network ip interface add --interface-name vmk1 --mtu 9000 --portgroup-name NFS esxcli network ip interface ipv4 set --interface-name vmk1 --ipv4 ${VMK1_IPADDR} --netmask 255.255.255.0 --type static esxcli network ip interface add --interface-name vmk2 --mtu 9000 --portgroup-name FT_VMOTION esxcli network ip interface ipv4 set --interface-name vmk2 --ipv4 ${VMK2_IPADDR} --netmask 255.255.255.0 --type static esxcli network ip interface add --interface-name vmk3 --mtu 9000 --portgroup-name VSPHERE_REPLICATION esxcli network ip interface ipv4 set --interface-name vmk3 --ipv4 ${VMK3_IPADDR} --netmask 255.255.255.0 --type static # Configure VMkernel traffic type (Management, VMotion, faultToleranceLogging, vSphereReplication) esxcli network ip interface tag add -i vmk2 -t Management esxcli network ip interface tag add -i vmk2 -t VMotion esxcli network ip interface tag add -i vmk2 -t faultToleranceLogging esxcli network ip interface tag add -i vmk3 -t vSphereReplication # Configure VMkernel routes esxcli network ip route ipv4 add -n 10.20.183/24 -g 172.30.0.1 esxcli network ip route ipv4 add -n 10.20.182/24 -g 172.30.0.1 # Disable IPv6 for VMkernel interfaces esxcli system module parameters set -m tcpip3 -p ipv6=0 ### MOUNT NFS DATASTORE ### esxcli storage nfs add --host 172.51.0.200 --share /volumes/Primp/primp-6 --volume-name himalaya-NFS-primp-6 ### ADV CONFIGURATIONS ### esxcli system settings advanced set --option /Net/TcpipHeapSize --int-value 30 esxcli system settings advanced set --option /Net/TcpipHeapMax --int-value 120 esxcli system settings advanced set --option /NFS/HeartbeatMaxFailures --int-value 10 esxcli system settings advanced set --option /NFS/HeartbeatFrequency --int-value 20 esxcli system settings advanced set --option /NFS/HeartbeatTimeout --int-value 10 esxcli system settings advanced set --option /NFS/MaxVolumes --int-value 128 ### SYSLOG CONFIGURATION ### esxcli system syslog config set --default-rotate 20 --loghost vcenter50-3.primp-industries.com:514,udp://vcenter50-3.primp-industries.com:514,ssl://vcenter50-3.primp-industries.com:1514,udp://vcenter50-3.primp-industries.com:514,udp://vcenter50-3.primp-industries.com:514,ssl://vcenter50-3.primp-industries.com:1514,ssl://vcenter50-3.primp-industries.com:1514 # change the individual syslog rotation count esxcli system syslog config logger set --id=hostd --rotate=20 --size=2048 esxcli system syslog config logger set --id=vmkernel --rotate=20 --size=2048 esxcli system syslog config logger set --id=fdm --rotate=20 esxcli system syslog config logger set --id=vpxa --rotate=20 ### NTP CONFIGURATIONS ### cat > /etc/ntp.conf << __NTP_CONFIG__ restrict default kod nomodify notrap noquery nopeer restrict 127.0.0.1 server 0.vmware.pool.ntp.org server 1.vmware.pool.ntp.org __NTP_CONFIG__ /sbin/chkconfig ntpd on ### FIREWALL CONFIGURATION ### # enable firewall esxcli network firewall set --default-action false --enabled yes # services to enable by default FIREWALL_SERVICES="syslog sshClient ntpClient updateManager httpClient netdump" for SERVICE in ${FIREWALL_SERVICES} do esxcli network firewall ruleset set --ruleset-id ${SERVICE} --enabled yes done # backup ESXi configuration to persist changes /sbin/auto-backup.sh # enter maintenance mode esxcli system maintenanceMode set -e true # copy %first boot script logs to persisted datastore cp /var/log/hostd.log "/vmfs/volumes/$(hostname -s)-local-storage-1/firstboot-hostd.log" cp /var/log/esxi_install.log "/vmfs/volumes/$(hostname -s)-local-storage-1/firstboot-esxi_install.log" # Needed for configuration changes that could not be performed in esxcli esxcli system shutdown reboot -d 60 -r "rebooting after host configurations"

  另一個ks.cfg例子,包含如何放棄ipv6, 如何配置ntp

# Accept the VMware End User License Agreement
 vmaccepteula
 # Set the root password for the DCUI and ESXi Shell 
 rootpw --iscrypted yHYo5Lev6wbMg 
 # Set the keyboard
 keyboard German
 # Install on the first local disk available on machine
 install --firstdisk --overwritevmfs
 # Set the network 
 network --bootproto=static  --device=vmnic0 --addvmportgroup=0 --hostname=ewie1vmesx01.aareal.org --ip=xxx.xxx.xxx.xxx--netmask=255.255.255.0 --gateway=xxx.xxx.xxx.xxx--nameserver="xxx.xxx.xxx.xxx"
 # reboots the host after the scripted installation is completed
 reboot

%firstboot --interpreter=busybox

 #####SWITCH0 - VMANAGE ########

 # Add an extra nic to vSwitch0 and add Name 
 esxcli network vswitch standard uplink add --uplink-name=vmnic1 --vswitch-name=vSwitch0
  
 # configure active and standby uplinks for vSwitch0
 esxcli network vswitch standard policy failover set --active-uplinks=vmnic0,vmnic1 --vswitch-name=vSwitch0

 ####SWITCH1 - VMOTION ########

 # Add new vSwitch for VMotion, assign uplinks, create a portgroup for Switch1                  
 esxcli network vswitch standard add --vswitch-name=vSwitch1 --ports=256
 esxcli network vswitch standard uplink add --uplink-name=vmnic2 --vswitch-name=vSwitch1
 esxcli network vswitch standard uplink add --uplink-name=vmnic3 --vswitch-name=vSwitch1

 #Add vMotion Portgroup to vSwitch1
 esxcli network vswitch standard portgroup add --portgroup-name=vMotion --vswitch-name=vSwitch1
  
 # Enable vMotion on the newly created VMkernel vmk1
 esxcli network ip interface add --interface-name=vmk1 --portgroup-name=vMotion
 esxcli network ip interface ipv4 set --interface-name=vmk1 --ipv4=172.27.196.10 --netmask=255.255.255.0 --type=static

 # Enable vMotion on the newly created VMkernel vmk1
 vim-cmd hostsvc/vmotion/vnic_set vmk1

 # configure active and standby uplinks for vSwitch1
 esxcli network vswitch standard policy failover set --active-uplinks=vmnic2,vmnic3 --vswitch-name=vSwitch1

 ####SWITCH2 - Virtual Machines ######## 

 # Add new vSwitch for VirtualMachines , assign uplinks, create a portgroup                     
  esxcli network vswitch standard add --vswitch-name=vSwitch2 --ports=504
  esxcli network vswitch standard uplink add --uplink-name=vmnic4 --vswitch-name=vSwitch2
  esxcli network vswitch standard uplink add --uplink-name=vmnic5 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup add --portgroup-name=PUB_172_27_193_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PUB_172_27_193_0 --vlan-id=99
  esxcli network vswitch standard portgroup add --portgroup-name=PUB_172_27_194_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PUB_172_27_194_0 --vlan-id=101
  esxcli network vswitch standard portgroup add --portgroup-name=PUB_172_27_195_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PUB_172_27_195_0 --vlan-id=195
  esxcli network vswitch standard portgroup add --portgroup-name=PUB_172_27_197_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PUB_172_27_197_0 --vlan-id=197
  esxcli network vswitch standard portgroup add --portgroup-name=PUB_172_27_198_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PUB_172_27_198_0 --vlan-id=198
  esxcli network vswitch standard portgroup add --portgroup-name=PRIV_172_27_231_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PRIV_172_27_231_0 --vlan-id=231
  esxcli network vswitch standard portgroup add --portgroup-name=PRIV_172_27_232_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PRIV_172_27_232_0 --vlan-id=232
  esxcli network vswitch standard portgroup add --portgroup-name=PRIV_172_27_233_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PRIV_172_27_233_0 --vlan-id=233
  esxcli network vswitch standard portgroup add --portgroup-name=PRIV_172_27_234_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PRIV_172_27_234_0 --vlan-id=234
  esxcli network vswitch standard portgroup add --portgroup-name=PRIV_172_27_235_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PRIV_172_27_235_0 --vlan-id=235
  esxcli network vswitch standard portgroup add --portgroup-name=PRIV_172_27_236_0 --vswitch-name=vSwitch2
  esxcli network vswitch standard portgroup set --portgroup-name=PRIV_172_27_236_0 --vlan-id=236
  
  
 # configure active and standby uplinks for vSwitch2
 esxcli network vswitch standard policy failover set --active-uplinks=vmnic4,vmnic5 --vswitch-name=vSwitch2

# Enable SSH and the ESXi Shell
 vim-cmd hostsvc/enable_ssh
 vim-cmd hostsvc/start_ssh
 vim-cmd hostsvc/enable_esx_shell
 vim-cmd hostsvc/start_esx_shell

  # Set the default PSP for Netapp to Round Robin as that is our preferred load balancing mechanism
 esxcli storage nmp satp set --default-psp VMW_PSP_RR --satp VMW_SATP_ALUA


 # Rename local datastore to something more meaningful 
 vim-cmd hostsvc/datastore/rename datastore1 "$(hostname -s)_datastore1"

 #Disable IPv6 and Reboot
 #esxcli system module parameters set -m=tcpip3 -p ipv6=0
 esxcli network ip set --ipv6-enabled=false
 esxcli system shutdown reboot -d 60 -r "making IPv6 config changes"
  

 ### NTP CONFIGURATIONS ###
 cat >/etc/ntp.conf<<__NTP_CONFIG__
 restrict default kod nomodify notrap noquerynopeer
 restrict 127.0.0.1
 server 0.192.168.1.72
 server 1.192.168.1.73
 __NTP_CONFIG__
/sbin/chkconfig ntpd on

【關於ipv6】上面有兩種方法能夠disable掉IPV6。可是esxcli的重啓語句須要先進入維護模式才能執行。也能夠簡單的在%firstboot的最後加一行reboot,直接重啓。 

 如下這個ks.cfg文件是我在實驗中用到的,已經經過試驗,基本功能都有了。(本身增長了DNS項)

#
# Sample scripted installation file
#
# Accept the VMware End User License Agreement
vmaccepteula
rootpw iampeter
install --firstdisk --overwritevmfs
%include /tmp/networkconfig

reboot
 
%pre --interpreter=busybox
 
# extract network info from bootup
VMK_INT="vmk0"
VMK_LINE=$(localcli network ip interface ipv4 get | grep "${VMK_INT}")
IPADDR=$(echo "${VMK_LINE}" | awk '{print $2}')
NETMASK=$(echo "${VMK_LINE}" | awk '{print $3}')
GATEWAY=$(localcli network ip route ipv4 list | grep default | awk '{print $3}')

DNS=$(localcli network ip dns server list | grep DNS | awk -F ':' '{ print $2 }') #DNS="172.30.0.100,172.30.0.200" #HOSTNAME=$(nslookup "${IPADDR}" "${DNS}" | grep Address | grep "${IPADDR}" | awk '{print $4}') echo "network --bootproto=static --addvmportgroup=false --device=vmnic0 --ip=${IPADDR} --netmask=${NETMASK} --gateway=${GATEWAY} --nameserver=${DNS} --hostname=esxi55" > /tmp/networkconfig %firstboot --interpreter=busybox # enable VHV (Virtual Hardware Virtualization to run nested 64bit Guests + Hyper-V VM) grep -i "vhv.enable" /etc/vmware/config || echo "vhv.enable = \"TRUE\"" >> /etc/vmware/config # enable & start remote ESXi Shell (SSH) vim-cmd hostsvc/enable_ssh vim-cmd hostsvc/start_ssh # enable & start ESXi Shell (TSM) vim-cmd hostsvc/enable_esx_shell vim-cmd hostsvc/start_esx_shell #disable ipv6 #esxcli network ip set --ipv6-enabled=false #esxcli system module parameters set -m tcpip3 -p ipv6=0 esxcli network ip set --ipv6-enabled=false esxcli system shutdown reboot -d 60 -r "making IPv6 config changes" ### NTP CONFIGURATIONS ### cat >/etc/ntp.conf<<__NTP_CONFIG__ restrict default kod nomodify notrap noquerynopeer restrict 127.0.0.1 server 192.168.200.128 __NTP_CONFIG__ /sbin/chkconfig ntpd on # supress ESXi Shell shell warning - Thanks to Duncan (http://www.yellow-bricks.com/2011/07/21/esxi-5-suppressing-the-localremote-shell-warning/) esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1 reboot # A sample post-install script %post --interpreter=python --ignorefailure=true import time stampFile = open('/finished.stamp', mode='w') stampFile.write( time.asctime() )

  

採用http方式:


 

前面介紹的方法,文件的抓取都是經過tftp方式。在網絡環境不佳的狀況下,tftp 採用的udp方式沒有http的tcp方式穩定。根據vmware官方文檔,可採用http方式代替tftp方式

一、pxelinux.0是tftp方式;gpxelinux.0是http方式,所以,更改dhcp.conf的filename "gpxelinux.0"

二、修改boot.cfg,將prefix=esxi5.1/;改成: http://x.x.x.x/esxi5.1/

三、相應的文件夾作好連接,並用瀏覽器作好測試,就能夠執行http的安裝了。

 

Windows平臺PXE的實現


 windows平臺下要實現pxe,也須要dhcp,tftp,(option)http。tiny pxe server 1.0版能夠實現該功能。它不只內置了tftp,dhcp,http,並且內置了pxelinux.0及gpxelinux,軟件僅有不到5M。

須要注意:全部服務器的根是files目錄,其它的和linux下是同樣的。在進行esxi安裝時,配置文件須要linux格式,特別是ks文件。若是格式不是linux格式(unix,ansi)而是windows文本格式,就會出現許多莫名其妙的問題。

 

工做流程分析(根據抓包結果得出):


1.DHCP: 分配IP地址,並分配pxelinux.0文件名告之PXE client
2. Client經過tftp拿到pxelinux.0,大約19個blocks
3. Client運行pxelinux.0, 準備拿配置文件
4. 連續tftp幾個文件(因爲只配置了default,確定找不到),pxelinux.cfg目錄下

564d330d-5a45-e2de-eb15-88e321e7dfd2 【未知】
01-00-0c-29-e7-df-d2 【此文件名是01,加上PXE CLIENT主機的MAC地址,可採用這種方式進行個性化定製】
C0A89464 【此爲該主機的IP地址(192 168 148 100)的十六進制表示,下面類同,這樣能夠實現針對不一樣主機或一類主機的定製化配置】
C0A8946
C0A894
C0A89
C0A8
C0A
C0
C

以上文件沒有配置,最後取得default文件。Default文件以下:

default vesamenu.c32
timeout 100

menu background splash.jpg
menu title Welcome to Install System --BY Lvyun
 
label Auto_CentOS
menu label Auto Install CentOS6.2
menu default
kernel CentOS/vmlinuz
append initrd=CentOS/initrd.img ks=nfs:192.168.2.58:/mnt/ks/ks.cfg

label Custom_CentOS
menu label Custom Install CentOS6.2
kernel CentOS/vmlinuz

  

5. 成功後,client再讀取default文件,得知要用vesamenu.c32, 則繼續tftp,取vesamenu.c32,大約117blocks
6. Client取到相應的menu.c32,就在client上運行,client根據以前拿到的default顯示菜單

 

Troubleshooting:


1. pxe client DHCP成功,可是tftp.....報錯

    pxe服務器的iptables沒有關掉(與宿主windows的防火牆無關)

2. DHCP成功,tftp也能拿到pxelinux.0,但就是拿不到default,提示權限問題。在tftp服務器上手工tftp get default文件,也說是權限問題不能拿到。

   緣由:selinux關閉就行了。

  

 

etc/vmware/weasel/ks.cfg

相關文章
相關標籤/搜索