Bật tắt toàn bộ máy chủ vmguest bằng file batch

Bật tắt toàn bộ máy chủ vmguest bằng file batch

Khi bạn dùng windows cài vmware làm máy chủ ảo hóa phục vụ thử nghiệm nhưng quá lười cho việc vào bật từng máy nên khi cần có thể thực hiện bằng cách:

Cách 1

  1. Bật chế độ tự động khởi động khi máy tính khởi động

Mở cửa sổ VMWare. Phải chuột vào My computer trong của sổ VMWare chọn Configure Auto Start VMs

Nhập số thứ tự rồi nhấn OK. Từ sau các cháy wmware guest sẽ khởi động cùng khi máy tính của mình được bật.

Cách 2

Tạo file batch rồi chạy trên máy khi cần bật

Ví dụ: tạo file vmStart.bat với nội dung sau:

@echo off

rem Define the path to vmrun.exe (assuming default installation)
set "VMWARE_PATH=C:\Program Files (x86)\VMware\VMware Workstation"
set "VMRUN_EXE=%VMWARE_PATH%\vmrun.exe"

rem Define the list of VM names (replace with your actual VM names)
set VM_LIST=NFS mgmt Deployment Master01 Master02 Master03 Worker01 Worker02 Worker03 Worker04  Worker05

rem Loop through each VM name
for %%a in ( %VM_LIST%) do (
  echo "%VMRUN_EXE%" start "D:\VMs\K8s\%%a\Ubuntu 64-bit.vmx"
  start "" /b "%VMRUN_EXE%" start "D:\VMs\K8s\%%a\Ubuntu 64-bit.vmx"  > NUL
)
echo All VMs listed in VM_LIST have been opened.
pause

Tương tự ta có thể thiết lập tắt.

@echo off

rem Define the path to vmrun.exe (assuming default installation)
set "VMWARE_PATH=C:\Program Files (x86)\VMware\VMware Workstation"
set "VMRUN_EXE=%VMWARE_PATH%\vmrun.exe"

rem Define the list of VM names (replace with your actual VM names)
set VM_LIST=Worker01 Worker02 Worker03 Worker04  Worker05 Master01 Master02 Master03 mgmt Deployment NFS

rem Loop through each VM name
for %%a in ( %VM_LIST%) do (
  echo "%VMRUN_EXE%" stop "D:\VMs\K8s\%%a\Ubuntu 64-bit.vmx"
  start "" /b "%VMRUN_EXE%" stop "D:\VMs\K8s\%%a\Ubuntu 64-bit.vmx"  > NUL
)
echo VMs listed in VM_LIST have been Stopped.
pause

Các bạn có thể sử dụng Ansible hoặc các công cụ khác nữa nhưng mình lười lắm không cần dùng dao mổ trâu để giết gà.

Tham khảo

https://virtualizationreview.com/Articles/2023/08/31/workstation-autostart.aspx

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply