#########################
####15.系統虛拟機管理####
####1.安裝####
#!/bin/bash ##指令運作環境的指定
virt-install \ ##安裝虛拟機
--name $1 \ ##虛拟機名稱指定,$1表示腳本後的第一串字元
--ram 1000 \ ##記憶體
--file /var/lib/libvirt/images/$1.img \ ##硬碟檔案
--file-size 8 \ ##硬碟檔案大小
--cdrom /var/ftp/pub/iso/rhel-server-7.1-x86_64-dvd.iso & ##安裝源指定
<a href="https://s4.51cto.com/wyfs02/M00/9C/FE/wKiom1l4jpezgwixAACSr3wg5m0505.png" target="_blank"></a>
####2.管理####
virt-manager ##開啟圖形管理工具
virt-viewer vmname ##顯示虛拟機,vmname表示虛拟機名稱
virsh list ##列出正在運作的vm
virsh list --all ##列出所有vm
virsh start vmname ##運作指定vm
virsh shutdown vmname ##正常關閉指定vm
virsh destroy vmname ##強行結束指定vm
virsh create vmname.xml ##臨時恢複指定vm,vmname表示前端管理檔案
virsh define vmname.xml ##永久恢複vm
virsh undefine vmname ##删除vm的前端管理,不會删除存儲
<a href="https://s5.51cto.com/wyfs02/M01/9C/FE/wKiom1l4jxWzMqcWAACyGru75tA140.png" target="_blank"></a>
<a href="https://s5.51cto.com/wyfs02/M00/9C/FE/wKioL1l4jxXwBaunAACuXaGTf6g253.png" target="_blank"></a>
<a href="https://s1.51cto.com/wyfs02/M01/9C/FE/wKiom1l4jxbxFFMZAAHyLRojr8w751.png" target="_blank"></a>
<a href="https://s1.51cto.com/wyfs02/M01/9C/FE/wKioL1l4jxeCnhlOAAHfF9jI7h8353.png" target="_blank"></a>
<a href="https://s4.51cto.com/wyfs02/M01/9C/FE/wKioL1l4jxfRBkz_AACwv4LeI1A414.png" target="_blank"></a>
<a href="https://s5.51cto.com/wyfs02/M02/9C/FE/wKiom1l4jxiieuvoAADnfCJ8FZA101.png" target="_blank"></a>
<a href="https://s5.51cto.com/wyfs02/M02/9C/FE/wKiom1l4jxiibS5FAABEuzFIZdo199.png" target="_blank"></a>
####3.虛拟機快照####
qemu-img create -f qcow2 -b vm2.qcow2 node1.qcow2
!/bin/bash
virsh destroy $1 &> /dev/null
virsh undefine $1 &> /dev/null
qemu-img create -f qcow2 -b /var/lib/libvirt/images/$1.qcow2 /var/lib/libvirt/images/$2.qcow2 &> /dev/null
virt-install \
--name $2 \
--ram 1000 \
--disk /var/lib/libvirt/images/$2.qcow2 \
--import &> /dev/null &
<a href="https://s2.51cto.com/wyfs02/M01/9C/FE/wKioL1l4j3ThbBFeAAUpseQWvz0686.png" target="_blank"></a>
<a href="https://s5.51cto.com/wyfs02/M01/9C/FE/wKiom1l4j3XxOBZ8AAENN9EFgmI133.png" target="_blank"></a>
<a href="https://s5.51cto.com/wyfs02/M01/9C/FE/wKioL1l4j3axsa9zAAEy7JVW4Dg811.png" target="_blank"></a>
本文轉自 lulu2017 51CTO部落格,原文連結:http://blog.51cto.com/13132425/1951234