<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 前言 上面一篇介紹了使用vm的工具vmrun.exe來操作vm創建,克隆,啟動關閉和刪除虛擬機. 但是在windows下調用命令需要使用bat批量執行腳本來完成,語法需要重新學習,成本有點高 我比較熟悉shell,那有沒有可能在windows下使用shell命令或者shell腳本來操作呢,那豈不是很爽? 答案是肯定的,下面我們就來操作 ## 實驗環境 ``` 操作系統: windows10 vm版本: VMware Workstation Pro12或以上 gitbash: 官網下載最新版即可,作用是在windows下可以執行linux的shell命令.因為windows的命令很難用 vm虛擬機操作系統: linux和windwos都可以,但是如果想在windows下執行虛擬機里面的腳本或命令則必須安裝vm-tools ``` ## vm命令說明 批量操作虛擬機本質上就是調用vm自己的命令vmrun.exe來執行一些操作 這個工具位置是你的vm軟件的安裝目錄, 執行的時候需要使用全路徑來執行,或者加入環境變量PATH 使用幫助說明: ``` $ /E/SOFT/VM/vmrun.exe /? vmrun version 1.15.8 build-5813279 Usage: vmrun [AUTHENTICATION-FLAGS] COMMAND [PARAMETERS] AUTHENTICATION-FLAGS -------------------- These must appear before the command and any command parameters. -h <hostName> (not needed for Workstation) -P <hostPort> (not needed for Workstation) -T <hostType> (ws|server|server1|fusion|esx|vc|player) for example, use '-T server' for Server 2.0 use '-T server1' for Server 1.0 use '-T ws' for VMware Workstation use '-T ws-shared' for VMware Workstation (shared mode) use '-T esx' for VMware ESX use '-T vc' for VMware vCenter Server -u <userName in host OS> (not needed for Workstation) -p <password in host OS> (not needed for Workstation) -vp <password for encrypted virtual machine> -gu <userName in guest OS> -gp <password in guest OS> POWER COMMANDS PARAMETERS DESCRIPTION -------------- ---------- ----------- start Path to vmx file Start a VM or Team [gui|nogui] stop Path to vmx file Stop a VM or Team [hard|soft] reset Path to vmx file Reset a VM or Team [hard|soft] suspend Path to vmx file Suspend a VM or Team [hard|soft] pause Path to vmx file Pause a VM unpause Path to vmx file Unpause a VM SNAPSHOT COMMANDS PARAMETERS DESCRIPTION ----------------- ---------- ----------- listSnapshots Path to vmx file List all snapshots in a VM [showTree] snapshot Path to vmx file Create a snapshot of a VM Snapshot name deleteSnapshot Path to vmx file Remove a snapshot from a VM Snapshot name [andDeleteChildren] revertToSnapshot Path to vmx file Set VM state to a snapshot Snapshot name GUEST OS COMMANDS PARAMETERS DESCRIPTION ----------------- ---------- ----------- runProgramInGuest Path to vmx file Run a program in Guest OS [-noWait] [-activeWindow] [-interactive] Complete-Path-To-Program [Program arguments] fileExistsInGuest Path to vmx file Check if a file exists in Guest OS Path to file in guest directoryExistsInGuest Path to vmx file Check if a directory exists in Guest OS Path to directory in guest setSharedFolderState Path to vmx file Modify a Host-Guest shared folder Share name Host path writable | readonly addSharedFolder Path to vmx file Add a Host-Guest shared folder Share name New host path removeSharedFolder Path to vmx file Remove a Host-Guest shared folder Share name enableSharedFolders Path to vmx file Enable shared folders in Guest [runtime] disableSharedFolders Path to vmx file Disable shared folders in Guest [runtime] listProcessesInGuest Path to vmx file List running processes in Guest OS killProcessInGuest Path to vmx file Kill a process in Guest OS process id runScriptInGuest Path to vmx file Run a script in Guest OS [-noWait] [-activeWindow] [-interactive] Interpreter path Script text deleteFileInGuest Path to vmx file Delete a file in Guest OS Path in guest createDirectoryInGuest Path to vmx file Create a directory in Guest OS Directory path in guest deleteDirectoryInGuest Path to vmx file Delete a directory in Guest OS Directory path in guest CreateTempfileInGuest Path to vmx file Create a temporary file in Guest OS listDirectoryInGuest Path to vmx file List a directory in Guest OS Directory path in guest CopyFileFromHostToGuest Path to vmx file Copy a file from host OS to guest OS Path on host Path in guest CopyFileFromGuestToHost Path to vmx file Copy a file from guest OS to host OS Path in guest Path on host renameFileInGuest Path to vmx file Rename a file in Guest OS Original name New name captureScreen Path to vmx file Capture the screen of the VM to a local file Path on host writeVariable Path to vmx file Write a variable in the VM state [runtimeConfig|guestEnv|guestVar] variable name variable value readVariable Path to vmx file Read a variable in the VM state [runtimeConfig|guestEnv|guestVar] variable name getGuestIPAddress Path to vmx file Gets the IP address of the guest [-wait] GENERAL COMMANDS PARAMETERS DESCRIPTION ---------------- ---------- ----------- list List all running VMs upgradevm Path to vmx file Upgrade VM file format, virtual hw installTools Path to vmx file Install Tools in Guest checkToolsState Path to vmx file Check the current Tools state register Path to vmx file Register a VM unregister Path to vmx file Unregister a VM listRegisteredVM List registered VMs deleteVM Path to vmx file Delete a VM clone Path to vmx file Create a copy of the VM Path to destination vmx file full|linked [-snapshot=Snapshot Name] [-cloneName=Name] Examples: Starting a virtual machine with Workstation on a Windows host vmrun -T ws start "c:\my VMs\myVM.vmx" Stopping a virtual machine on an ESX host vmrun -T esx -h https://myHost.com/sdk -u hostUser -p hostPassword stop "[storage1] vm/myVM.vmx" Running a program in a virtual machine with Workstation on a Windows host with Windows guest vmrun -T ws -gu guestUser -gp guestPassword runProgramInGuest "c:\my VMs\myVM.vmx" "c:\Program Files\myProgram.exe" Running a program in a virtual machine with Server on a Linux host with Linux guest vmrun -T server -h https://myHost.com:8333/sdk -u hostUser -p hostPassword -gu guestUser -gp guestPassword runProgramInGuest "[standard] vm/myVM.vmx" /usr/bin/X11/xclock -display :0 Creating a snapshot of a virtual machine with Workstation on a Windows host vmrun -T ws snapshot "c:\my VMs\myVM.vmx" mySnapshot Reverting to a snapshot with Workstation on a Windows host vmrun -T ws revertToSnapshot "c:\my VMs\myVM.vmx" mySnapshot Deleting a snapshot with Workstation on a Windows host vmrun -T ws deleteSnapshot "c:\my VMs\myVM.vmx" mySnapshot Enabling Shared Folders with Workstation on a Windows host vmrun -T ws enableSharedFolders "c:\my VMs\myVM.vmx" ``` 簡單說明一下使用vmrun.exe可以實現以下功能,僅列出我們目前需要的命令,更多的命令可以查看幫助 ``` - 創建虛擬機 - 啟動虛擬機 - 關閉虛擬機 - 創建虛擬機快照并指定快照名稱 - 從指定快照中恢復 - 從指定快照克隆虛擬機 - 執行虛擬機中的腳本 ``` ## 實驗步驟 這里我們分為兩個階段 第一個階段是用windows自己的cmd命令操作 第二階段是使用shell腳本批量操作 ### 創建虛擬機模版 這里我們先把要實現的效果說一下: 1.首先手動安裝一臺虛擬機,并把相關配置都配置好,然后就當作是模版機,以后這臺機器的作用只有一個.就是創建鏈接克隆其他的虛擬機. 2.當這臺模版機已經配置好之后,我們需要做一個快照,以后的克隆虛擬機都從這個快照克隆 3.命名規范,為了后面的腳本,我們需要把路徑,機器名和快照名都規范下來.規范如下 ``` 軟件安裝目錄名: D:\soft\VM vmrun路徑: D:\soft\VM\vmrun.exe 虛擬機目錄: D:\VMS\集群名\服務名-端口號\服務名-端口號.vmx 例如我們需要創建一個nginx的集群2臺機器,那么目錄名就是: D:\VMS\nginx-cluster\nginx-21\nginx-21.vmx D:\VMS\nginx-cluster\nginx-22\nginx-22.vmx ``` 注意: windwos下是D:\VMS\這樣的命名 但是linux的命名規則是/D/VMS 所以寫腳本的時候需要轉換成linux的命名格式 ###
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看