06
2025
03
00:35:44

全自动部署ESXI

全自动部署ESXI


全自动安装ESXI有多种方式,具体参考VMware官网:https://docs.vmware.com/cn/VMware-vSphere/8.0/vsphere-esxi-installation/GUID-D0A72192-ED00-4A5D-970F-E44B1ED586C7.html

本期就讲一下脚本和写法和使用脚本从USB盘安装部署,可用于同行、小型ESXI数据中心和ESXI热爱者

一、脚本写法

ESXi 安装程序包含一个默认安装脚本,该脚本可对第一个检测到的磁盘执行标准安装。

默认 ks.cfg 安装脚本位于 /etc/vmware/weasel/ks.cfg 的初始内存磁盘中。您可以使用 ks=file://etc/vmware/weasel/ks.cfg引导选项指定默认 ks.cfg 文件的位置。

使用 ks.cfg 脚本安装 ESXi 时,默认根密码为 myp@ssw0rd

不能在安装介质上修改默认脚本。安装后,可使用 vSphere Client登录到用于管理 ESXi 主机的 vCenter Server 并修改默认设置。

默认脚本包含以下命令:

# # Sample scripted installation file # # Accept the VMware End User License Agreement vmaccepteula # Set the root password for the DCUI and Tech Support Mode rootpw myp@ssw0rd # Install on the first local disk available on machine install --firstdisk --overwritevmfs  In case you system has DPUs, you also specify a PCI slot: install --firstdisk --overwritevmfs --dpuPciSlots=<PCIeSlotID> # Set the network to DHCP on the first network adapter network --bootproto=dhcp --device=vmnic0 # A sample post-install script %post --interpreter=python --ignorefailure=true import time stampFile = open('/finished.stamp', mode='w') stampFile.write( time.asctime() )

上面脚本可以完成我们的esxi安装并不能完成我们的部署,然后我们来稍作修改

抽取精髓,我们写一个自动安装的ks

vmaccepteula install --firstdisk --overwritevmfs network --bootproto=dhcp --device=vmnic0 rootpw Vlan.123 %post --interpreter=python --ignorefailure=true import time stampFile = open('/finished.stamp', mode='w') stampFile.write( time.asctime() )

上面脚本可以自动安装以及

(一)设置最先找到的合格磁盘进行覆盖磁盘上的现有 VMFS 数据存储时需要。

默认情况下,合格磁盘按以下顺序排列:

1、本地连接的存储(local)

2、网络存储(remote)

可以使用附加到参数的逗号分隔列表更改磁盘的顺序。如果提供筛选列表,则会覆盖默认设置。可组合使用筛选器以指定特定磁盘,包括安装有 ESX 的第一个磁盘的 esx、型号和供应商信息,或 VMkernel 设备驱动程序的名称。例如,要首选使用型号名称为 ST3120814A 的磁盘,及使用 mptsas 驱动程序的任何磁盘,而非普通本地磁盘,参数为 --firstdisk=ST3120814A,mptsas,local。可以对包含 ESXi 映像的本地存储使用 localesx,或对包含 ESXi 映像的远程存储使用 remoteesx。

(二)设置第一张网卡为管理网络,自动获取ip地址

(三)设置密码为Vlan.123

完成安装脚本后我们写一下自动部署,先要了解一些常用的命令

1、设置指定网卡为管理网卡和静态IP地址

network --bootproto=static --device=vmnic0 --ip=192.168.11.2 --netmask=255.255.255.0 --gateway=192.168.11.1 --hostname=EsxiServer --nameserver=223.5.5.5

或者dhcp后固定地址以免地址漂移

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="223.5.5.5,223.6.6.6" echo "network --bootproto=static --addvmportgroup=false --device=vmnic0 --ip=${IPADDR} --netmask=${NETMASK} --gateway=${GATEWAY} --nameserver=${DNS} --hostname=EsxiServer" > /tmp/networkconfig


2、加入license后就不用再到ESXI里再添加许可证,不同版本要加入不同许可证

vmserialnum --esx=xxxxx-xxxxx-xxxxx-xxxxx-xxxxx

3、设置密码

rootpw Vlan.123

前面输入安装命令,部署命令要保留从串口访问ESXI的权限

4、保留从串口访问ESXI的权限

%firstboot --interpreter=busybox

5、直通设备(0000:0X:00.0修改为你要直通的设备,管理网卡不能直通,谨慎直通)

esxcli hardware pci pcipassthru set -d 0000:0X:00.0 -e TRUE

6、开启vswitch0的混杂、mac地址更改、伪传输

esxcli network vswitch standard policy  security set  -v vSwitch0 -f True -m True -p True

7、启动ssh以及随主机启动和停止

vim-cmd hostsvc/enable_ssh vim-cmd hostsvc/start_ssh

8、启动shell以及随主机启动和停止

vim-cmd hostsvc/enable_esx_shell vim-cmd hostsvc/start_esx_shell

9、设置虚拟机开机自启动和启动延时为10 停止延时为10 停止操作为关闭电源 不等待检测信号

vim-cmd hostsvc/autostartmanager/enable_autostart 1 vim-cmd hostsvc/autostartmanager/update_defaults 10 10 PowerOff false

10、关闭ipv6,vSphere完整体系对ipv6不太友好,不是需要可以关闭

esxcli network ip set --ipv6-enabled=false esxcli system shutdown reboot -d 60 -r "making IPv6 config changes"

11、关闭ESXI的防火墙,可用于外网访问ESXI

esxcli network firewall set -e  false

12、设置NTP

cat >/etc/ntp.conf<<NTP_CONFIG restrict default kod nomodify notrap noquerynopeer restrict 127.0.0.1 server ntp.aliyun.com NTP_CONFIG /sbin/chkconfig ntpd on

13、屏蔽掉开启shell后再UI界面的警告

esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1

14、shell交互式空闲时间注销

esxcli system settings advanced set -o /UserVars/ESXiShellInteractiveTimeOut -i 3600

15、将本地数据存储重命名

vim-cmd hostsvc/datastore/rename datastore1 "$(hostname -s)-local-storage-1"

开始编写自己的脚本,这个是我们家的机器脚本作为参考

vmaccepteula install --firstdisk --overwritevmfs network --bootproto=static --device=vmnic0 --ip=192.168.11.2 --netmask=255.255.255.0 --gateway=192.168.11.1 --hostname=EsxiServer --nameserver=223.5.5.5 vmserialnum --esx=4V492-44210-48830-931GK-2PRJ4 rootpw Vlan.123 reboot %firstboot --interpreter=busybox esxcli hardware pci pcipassthru set -d 0000:02:00.0 -e TRUE esxcli hardware pci pcipassthru set -d 0000:03:00.0 -e TRUE esxcli hardware pci pcipassthru set -d 0000:04:00.0 -e TRUE esxcli network vswitch standard policy  security set  -v vSwitch0 -f True -m True -p True vim-cmd hostsvc/enable_ssh vim-cmd hostsvc/start_ssh vim-cmd hostsvc/enable_esx_shell vim-cmd hostsvc/start_esx_shell vim-cmd hostsvc/autostartmanager/enable_autostart 1 vim-cmd hostsvc/autostartmanager/update_defaults 10 10 PowerOff false esxcli network ip set --ipv6-enabled=false esxcli system shutdown reboot -d 60 -r "making IPv6 config changes" esxcli system settings advanced set -o /UserVars/ESXiShellInteractiveTimeOut -i 3600 esxcli network firewall set -e  false cat >/etc/ntp.conf<<NTP_CONFIG restrict default kod nomodify notrap noquerynopeer restrict 127.0.0.1 server ntp.aliyun.com NTP_CONFIG /sbin/chkconfig ntpd on esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1 reboot %post --interpreter=python --ignorefailure=true import time stampFile = open('/finished.stamp', mode='w') stampFile.write( time.asctime() )

二、从USB盘安装部署

获取一个本机器可安装的镜像

https://pan.baidu.com/s/1kCQAVdnBWK2pRko1XOt51w?pwd=xqlj

交互安装可参考这期视频

先烧入一个ESXI到U盘

u盘备份好数据

在u盘根目录创建一个ks(Kickstart)文件,xxxxx.cfg,并写入脚本

分别在根目录和efi\boot目录修改boot.cfg文件

源文件

原本的kernelopt=runweasel cdromBoot修改为

kernelopt=ks=usb:/xxxxx.cfg

修改后文件

也可以加一下东西,比如可以在title加入自己的名字

会出现在u盘启动的第一个画面

还可以在kernelopt结尾加空格加入以下内容

修改vmfsl大小为8G:autoPartitionOSDataSize=8192

12代处理器大小核设计蓝屏:cpuUniformityHardCheckPanic=FALSE

支持老旧CPU(新版本ESXI默认对一些老旧CPU不支持,设为true后可支持):allowLegacyCPU=true

1、上面我们介绍的是通过Kickstart脚本自动化安装ESXi,假如我们有多个不同的配置需求,也就是说我们按需求制作了多份Kickstart自动安装脚本,是否可以将这些脚本整合到一个安装映像中呢,答案是肯定的。我们可以通过启动菜单的方式来将多份Kickstart安装脚本整合到一起。

2、首先,在安装U盘的根目录创建一个目录,例autoinstall目录

3、将已经创建好的Kickstart脚本拷贝到这个目录当中。例如这里我们创建了4个Kickstart脚本,分别命名为autoinstall1.cfg~autoinstall4.cfg可以编写不同脚本

修改根目录的isolinux.cfg

DEFAULT menu.c32 MENU TITLE ESXi-8.0b-21203435-standard-customized Boot Menu NOHALT 1 PROMPT 0 TIMEOUT 80 LABEL install ESXI on autoinstall1   KERNEL mboot.c32   APPEND -c boot.cfg ks=usb:/autoinstall/autoinstall1.cfg   MENU LABEL ^1 Install ESXI on USB autoinstall1 LABEL install ESXI on autoinstall2   KERNEL mboot.c32   APPEND -c boot.cfg ks=usb:/autoinstall/autoinstall2.cfg   MENU LABEL ^1 Install ESXI on USB autoinstall2 LABEL install ESXI on autoinstall3   KERNEL mboot.c32   APPEND -c boot.cfg ks=usb:/autoinstall/autoinstall3.cfg   MENU LABEL ^1 Install ESXI on USB autoinstall3 LABEL install ESXI on autoinstall4   KERNEL mboot.c32   APPEND -c boot.cfg ks=usb:/autoinstall/autoinstall4.cfg   MENU LABEL ^1 Install ESXI on USB autoinstall4 LABEL hddboot   LOCALBOOT 0x80   MENU LABEL ^Boot from local disk


ps:在ESXI8中手动指定管理口网卡速度导致设备失联的恢复办法

解决方案来自b站博主:https://www.bilibili.com/read/cv23622162/

VMware链接:https://kb.vmware.com/s/article/2054090




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://sg.hqyman.cn/post/9361.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

请先 登录 再评论,若不是会员请先 注册
51La

您的IP地址是: