测试环境:win10/vmware workstation 12 pro

操作系统:RHEL 6.5(PXE服务器)

【2016.11.30】

 

【遗留问题】

1、ks.cfg通过本地文件方式加载不成功,只能通过http://方式成功 ,以下几种尝试都是不成功的。

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

 

 

安装与配置:


 。安装DHCP

。安装XINETD, 并启用TFTP服务

。安装syslinux(yum安装):会自动在tftpboot目录下放置pxelinux.0及seamenu.c32文件,还有一些其它文件

 

配置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过来进行修改,主要修改为正确的目录路径)

1
2
3
4
5
6
7
8
9
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<br><br>//整个文件相对简单,只是增加了相对目录esxi5.1

 

  esxi5.1/boot.cfg文件:由于原ISO是光盘模式的,故每个文件都给出了绝对路径/(根) 

1
2
3
4
5
6
7
8
[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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#
# 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文件中的倒数第二行,更改为如下:

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

还有一种特殊的做法:ESXi在启动成功后,会在其虚拟文件系统中产生一个/etc/vmware/weasel/ks.cfg文件。如果我们传递如下格式: 

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

则ESXi也会自动安装,但是参数是不受控制的,因为是自动生成的。这种方式安装完成后,密码空,IP地址为自动获取。

【说明】在生成ks.cfg文件后,可以不修改default文件进行传递,而是在ESXi开始安装时,通过按Shift-O键,手工进行传递,之后就会自动进行了。

由于ks的内容较多,以下是两个例子,比较全面,全自动安装并且自动设置包括:网络、SSH、vSwitch等等

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# Sample kickstart for ESXi 5.1
# William Lam
# www.virtuallyghetto.com
#########################################
  
accepteula
install --firstdisk --overwritevmfs
rootpw vmware123
reboot<br>#下面这句应该往前提,放在reboot之前,估计是作者手误<br>%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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# 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项)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
# 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}')<br><br>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方式

1、pxelinux.0是tftp方式;gpxelinux.0是http方式,因此,更改dhcp.conf的filename "gpxelinux.0"

2、修改boot.cfg,将prefix=esxi5.1/;改为: http://x.x.x.x/esxi5.1/

3、相应的文件夹做好链接,并用浏览器做好测试,就可以执行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文件如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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

posted on   胡彼德  阅读(2212)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话



点击右上角即可分享
微信分享提示