2013/08/26

ESXi 5.1的Guest VM機器遠端開機

建立了公用虛擬機器,平常用不到保持關機狀態,如果臨時想用還需要IT人員在有安裝VMware vSphere Client的電腦上才能執行開機,這也太麻煩了。

目的:
1.一鍵開機或關機
2.任何人皆能操作

項目:
必備:ESXi的主機開啟SSH連線功能
方式一:vsphere CLI(付費軟體),請參考這邊
方式二:Putty+適當的批次檔
方式三:以網頁執行Bat、Exe

必備1:ESXi的主機開啟SSH連線功能
1. start the vSphere Client
2.Select the ESXi host in the configurations / Security Profile
3.Click on Properties in the upper right corner and you will get the a popup with all the services on this ESXi 5.0 hosts. Select the SSH service and press the Options button.
4.start the services and set the startup options

必備2.取得虛擬機器的id
先到ESXi主機,或是遠端登入之後,以下面指令取得虛擬機器的VMID:
vim-cmd vmsvc/getallvms,最前面的就是VMID
vim-cmd vmsvc/power.getstate VMID 可顯示該VM的狀態

方法一掠過不提。

方式二:以Putty+適當的批次檔(script.txt )進行VM機器遠端開機
作法是: 以Putty遠端登入ESXi主機並執行指令
指令為:putty -ssh user@IP -pw password -m script.txt
或是:putty -ssh IP -l user -pw password -m script.txt

script.txt的內容就是想要執行的指令,例如:
vim-cmd vmsvc/power.on VMID,將虛擬機器開機
vim-cmd vmsvc/power.off VMID,將虛擬機器關機

問題:批次檔屬於文字,帳號密碼都洩漏了
可行方式1:將putty -ssh user@IP -pw password -m script.txt 使用bat2exe打包過(疑問:高手仍能找到密碼)
可行方式2:在ESXi主機上設定限定連線來源IP
可行方式3:使用rsa key登入ssh,請參考這邊

方式三:以網頁執行Bat、Exe
Google的結果,有很多Linux+php可執行Bat、Exe,請自行研究
至於IIS可以嗎?我還沒找到。

參考:
Putty官網: http://www.chiark.greenend.org.uk/~sgtatham/putty/
Pietty官網: http://ntu.csie.org/~piaip/pietty/
Pietty 源自於 PuTTY ,修正與完整支援亞洲等多國語系字元、 並在使用界面上大幅改進、易學易用的版本
使用putty自動登入並執行遠端主機的程式或指令
ESXi 5.1的Guest VM機器可以遠端開機嗎?
PHP遠端執行cmd

沒有留言:

張貼留言