测试环境: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的官方文档
准备:
配置:
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