VMware ESXi本地登陆命令行关机、启动虚拟机

VMware ESXi版本:6.7

本地登陆ESXi主机后,切换命令行界面再次登陆,然后通过命令行方式关闭、启动和重启虚拟机系统。

本地登陆ESXi主机并切换到命令行界面

第一步:按“F2”本地登陆ESXi主机

第二步:进入“Troubleshooting Options”页面

默认情况,“ESXi Shell is Disabled”,如下图所示,按“Enter”开启ESXi Shell;

第三步:ESXi Shell开启后,如下图所示,按“Alt+F1”可切换至ESXi主机命令行界面,再次输入用户名和密码即可

按按“Alt+F2”可切换至ESXi主机图形化界面

esxcli方式关闭虚拟机系统

第一步:在命令行界面使用命令行获取正在运行的虚拟机信息并关闭虚拟机

#获取正在运行的虚拟机信息

esxcli vm process list

#以soft模式关闭该虚拟机

esxcli vm process kill -t=soft -w=2100428

虚拟机名称显示为方块,说明该虚拟化名称含中文字符。

采用esxcli方式关闭虚拟机系统,有三种模式,分别是soft、hard和force,详细的释义如下所示;

esxcli vm process kill –help

Usage: esxcli vm process kill [cmd options]

Description:

kill Used to forcibly kill Virtual Machines that are stuck and not responding to normal stop operations.

Cmd options:

-t|–type=<str> The type of kill operation to attempt. There are three types of VM kills that can be attempted: [soft, hard, force]. Users should always attempt ‘soft’ kills first, which will give the VMX

process a chance to shutdown cleanly (like kill or kill -SIGTERM). If that does not work move to ‘hard’ kills which will shutdown the process immediately (like kill -9 or kill -SIGKILL). ‘force’

should be used as a last resort attempt to kill the VM. If all three fail then a reboot is required. (required)

-w|–world-id=<long> The World ID of the Virtual Machine to kill. This can be obtained from the ‘vm process list’ command (required)

第二步:再次查看虚拟机的运行状态并切换到图形化界面关闭“ESXi Shell”。

vim-cmd方式启动、关闭、重启虚拟机系统

第一步:在命令行界面使用命令行获取该ESXi主机承载的所有虚拟机及其对应的vmid

vim-cmd vmsvc/getallvms

第二步:根据获取虚拟机vmid可查看该虚拟机的当前的运行状态,关闭、打开、重置虚拟机的电源,挂起、重启和关闭虚拟机系统,详情如下所示;

#开启vmid是1的虚拟机电源

vim-cmd vmsvc/power.on 1

#关闭vmid是1的虚拟机电源

vim-cmd vmsvc/power.off 1

#重置vmid是1的虚拟机电源,即先关闭电源再开启电源

vim-cmd vmsvc/power.reset 1

#挂起vmid是1的虚拟机

vim-cmd vmsvc/power.suspend 1

#重启vmid是1的虚拟机系统,依赖虚拟机系统安装VMware Tools;

vim-cmd vmsvc/power.reboot 1

#关闭vmid是1的虚拟机系统,依赖虚拟机系统安装VMware Tools;

vim-cmd vmsvc/power.shutdown 1

#获取vmid是1的虚拟机系统的当前运行状态;

vim-cmd vmsvc/power.getstat 1