在ESXi shell 使用esxcli 命令強制把沒反應的VM關閉

ewelamb發表於2014-01-09

最近學到一個在VMware ESXi 下面強制關閉一個沒有反應的VM的方法, 一般正常都是使用vSphere Client 去控制VM電源, 但是有時會發生即使用裡面的Power Off 按鈕但是還是無法關閉我的VM, 而且最終會出現一串錯誤訊息「An unexpected error was received from the ESX host while powering off VM ..」這時要解決問題的方法是讓ESXi host整個重開機一次, 但是如果不想整臺伺服器重新開機時要怎麼樣呢...

透過Google大神的搜尋下, 找到可以透過Shell的命令來對系統進行一些操作, 我找到一頁對於開關VM有幫助的網頁 ""

只要使用esxcli 命令打入相關的引數就可以了, 要做遠端shell command的操作首先要在ESXi 開啟「Shell Service 和 SSH Service」

esxcli vm process kill --type --world-id

接下來利用putty連入後打入「esxcli vm process list 」命令去獲取現在系統裡的動作中的VM資訊, 會得到類似下面的訊息...

~ # esxcli vm process list

WinXP CHT (netComputer)
   World ID: 4171
   Process ID: 0
   VMX Cartel ID: 4170
   UUID: 56 4d 8b 2a 9c 6c fa b4-b3 77 19 21 69 05 09 25
   Display Name: WinXP CHT (netComputer)
   Config File: /vmfs/volumes/4ef37e4a-50fb6d27-df84-001018185495/WinXP CHT (netComputer)/WinXP CHT (netComputer).vmx
 
Windows 7 Eng
   World ID: 196949
   Process ID: 0
   VMX Cartel ID: 196948
   UUID: 42 3b 85 7b 89 ee 38 bc-61 c2 70 b9 4b 29 26 62
   Display Name: Windows 7 Eng
   Config File: /vmfs/volumes/4ef37e4a-50fb6d27-df84-001018185495/Windows 7 Eng/Windows 7 Eng.vmx
 
Debian Router
   World ID: 4839
   Process ID: 0
   VMX Cartel ID: 4682
   UUID: 56 4d 96 78 75 90 80 a8-25 08 12 ba 5a e7 94 99
   Display Name: Debian Router
   Config File: /vmfs/volumes/4ef37e4a-50fb6d27-df84-001018185495/Debian Router/Debian Router.vmx
 
Windows 7 Home x64
   World ID: 211699
   Process ID: 0
   VMX Cartel ID: 211698
   UUID: 42 3b e7 9b 3b e0 78 1d-a5 bc 8b a4 4d 98 3a 79
   Display Name: Windows 7 Home x64
   Config File: /vmfs/volumes/4ef37e4a-50fb6d27-df84-001018185495/Windows 7 Home x64/Windows 7 Home x64.vmx
 
Major Storage Server
   World ID: 4860
   Process ID: 0
   VMX Cartel ID: 4844
   UUID: 56 4d 3e 4a e7 d1 8d 55-20 70 50 af 3c 22 27 b2
   Display Name: Major Storage Server
   Config File: /vmfs/volumes/4ef37e4a-50fb6d27-df84-001018185495/Cloud/Major Storage Server/Major Storage Server.vmx

接下來你要找尋無法控制開關機的VM, 找到它的「World ID」, 比如說接「Windows 7 Home x64 」失去連線且透過vSphere Client完全無法控制, 我只要輸入以下命令就可以強制將VM關閉, 然後再啟動

esxcli vm process kill --type hard --world-id 211699

如果還是不行可能就要試試用 --type force, 再不行也只能重新開伺服器了。

詳細命令用法可以參考 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7191998/viewspace-1068796/,如需轉載,請註明出處,否則將追究法律責任。

相關文章