安裝:
yum install libvirt virt-install qemu-kvm -y
介紹:
libvirt服務:管理kvm虛擬機的生命周期
virt-install工具:創建安裝虛擬機
qemu-kvm工具:使用qemu-img為虛擬機提供硬盤
新創建一個虛擬機:
virt-install –virt-type kvm –os-type=linux –os-variant rhel7 –name centos7
–memory 1024 –vcpus 1 –disk /opt/centos2.raw,format=raw,size=10
–cdrom /opt/CentOS-7-x86_64-DVD-1708.iso
–network network=default –graphics vnc,listen=0.0.0.0 –noautoconsole
創建虛擬磁盤
qemu-img create test.raw 10G
qemu-img create -f qcow2 test.qcow2 10G
查看虛擬磁盤信息
qemu-img info test.raw
調整虛擬磁盤容量大小
qemu-img resize test.raw +5G
磁盤格式轉換
qemu-img convert -f raw -O qcow2 test.raw oldboy.qcow2
創建快照
virsh snapshot-create centos7
查看快照
virsh snapshot-list centos7
還原快照
virsh snapshot-revert centos7 –snapshotname 1516574134
刪除快照
virsh snapshot-delete centos7 –snapshotname 1516636570
完整克隆
實現方法:
virt-clone -o web01 –auto-clone
鏈接克隆
1:克隆虛擬磁盤文件
cp centos7.qcow2 web03.qcow2
2:生成新的虛擬機配置文件
name修改
uuid刪掉
disk路徑/opt/web03.qcow2
mac地址刪除
3:測試啟動
virsh define web01.xml
qemu-img create -f qcow2 -b cetnos7.qcow2 web04.qcow2
virt-install –virt-type kvm –os-type=linux –os-variant rhel7 –name web02 –memory 1024 –vcpus 1 –disk /opt/web04.qcow2,format=qcow2,size=10 –boot hd –network network=default –graphics vnc,listen=0.0.0.0 –noautoconsole
創建橋接網絡
1:virsh iface-bridge eth0 br0
基于橋接網絡創建虛擬機
2:virt-install –virt-type kvm –os-type=linux –os-variant rhel7 –name web04 –memory 1024 –vcpus 1 –disk /opt/web04.qcow2,format=qcow2,size=10 –boot hd –network bridge=br0 –graphics vnc,listen=0.0.0.0 –noautoconsole
1:virsh edit centos7