安裝:
yum install libvirt virt-install qemu-kvm -y
介紹:
libvirt服務(wù):管理kvm虛擬機(jī)的生命周期
virt-install工具:創(chuàng)建安裝虛擬機(jī)
qemu-kvm工具:使用qemu-img為虛擬機(jī)提供硬盤
新創(chuàng)建一個(gè)虛擬機(jī):
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
創(chuàng)建虛擬磁盤
qemu-img create test.raw 10G
qemu-img create -f qcow2 test.qcow2 10G
查看虛擬磁盤信息
qemu-img info test.raw
調(diào)整虛擬磁盤容量大小
qemu-img resize test.raw +5G
磁盤格式轉(zhuǎn)換
qemu-img convert -f raw -O qcow2 test.raw oldboy.qcow2
創(chuàng)建快照
virsh snapshot-create centos7
查看快照
virsh snapshot-list centos7
還原快照
virsh snapshot-revert centos7 –snapshotname 1516574134
刪除快照
virsh snapshot-delete centos7 –snapshotname 1516636570
完整克隆
實(shí)現(xiàn)方法:
virt-clone -o web01 –auto-clone
鏈接克隆
1:克隆虛擬磁盤文件
cp centos7.qcow2 web03.qcow2
2:生成新的虛擬機(jī)配置文件
name修改
uuid刪掉
disk路徑/opt/web03.qcow2
mac地址刪除
3:測(cè)試啟動(dòng)
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
創(chuàng)建橋接網(wǎng)絡(luò)
1:virsh iface-bridge eth0 br0
基于橋接網(wǎng)絡(luò)創(chuàng)建虛擬機(jī)
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