KVM虚拟机热添加技术
1.kvm热添加硬盘
临时生效
virsh attach-disk web01 /data/web01-add.qcow2 vdb --subdriver qcow2
永久生效
virsh attach-disk web01 /data/web01-add.qcow2 vdb --subdriver qcow2 --config
临时剥离磁盘
virsh detach-disk web01 vdb
永久剥离磁盘
virsh detach-disk web01 vdb --config
扩容: 在虚拟机里把扩容盘的挂载目录,卸载掉 在宿主机上剥离硬盘virsh detach-disk web01 vdb 在宿主机上调整容量qemu-img resize 在宿主机上再次附加硬盘virsh attach-disk web01 /data/web01-add.qcow2 vdb --subdriver qcow2 在虚拟机里再次挂载扩容盘 在虚拟机里用xfs_growfs更新扩容盘超级块信息
2.kvm虚拟机在线热添加网卡
临时生效
virsh attach-interface web04 --type bridge --source br0 --model virtio
永久生效
virsh attach-interface web04 --type bridge --source br0 --model virtio --config
virsh detach-interface web04 --type bridge --mac 52:54:00:35:d3:71
3.kvm虚拟机在线热添加内存
virt-install --virt-type kvm --os-type=linux --os-variant rhel7 --name web04 --memory 512,maxmemory=2048 --vcpus 1 --disk /data/web04.qcow2 --boot hd --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole
临时增加内存
virsh setmem web04 1024M
永久增加内存
virsh setmem web04 1024M --config
调整虚拟机内存最大值
virsh setmaxmem web04 4G
4. kvm虚拟机在线热添加cpu
virt-install --virt-type kvm --os-type=linux --os-variant rhel7 --name web04 --memory 512,maxmemory=2048 --vcpus 1,maxvcpus=10 --disk /data/web04.qcow2 --boot hd --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole
临时添加CPU核数
virsh setvcpus web04 4
永久添加CPU核数
virsh setvcpus web04 4 --config
调整CPU最大值
virsh setvcpus web01 --maximum 4 --config