kvm热添加和热迁移

热添加磁盘

1.创建磁盘

qemu-img create -f qcow2 web01-add01.qcow2 5G

2.附加磁盘设备

virsh attach-disk web01 /opt/web01-add01.qcow2 vdb --live --cache=none --subdriver=qcow2

3.格式化磁盘

mkfs.xfs /dev/vdb

4.挂载

mount /dev/vdb /data

磁盘扩容

1.卸载挂载磁盘

umount /dev/vdb

2.分离磁盘设备

virsh detach-disk web01 vdb

3.增加磁盘大小

qemu-img resize web01-add01.qcow2 +3G

 4.挂载

mount /dev/vdb /data

5.重新分配磁盘空间

xfs_growfs /dev/vdb

热添加网卡

virsh attach-interface web01 --type network  --model  virtio --source default    #添加nat模式网卡
virsh attach-interface web01 --type bridge  --model  virtio --source br0    #添加桥接网卡

或修改配置文件

virsh edit web01

    <interface type='bridge'>
      <mac address='52:54:00:45:02:55'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <interface type='network'>
      <source network='default'/>
      <model type='virtio'/>
    </interface>

热添加CPU

安装参数

virt-install --virt-type kvm --os-type=linux --os-variant rhel7 --name web01 --memory 1024 --vcpus 1,maxvcpus=4 --disk /opt/web01.qcow2,format=qcow2,size=10 --boot hd --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole

添加CPU

virsh setvcpus web01 --count=2

热添加内存

安装参数

virt-install --virt-type kvm --os-type=linux --os-variant rhel7 --name web01 --memory 1024,maxmemory=4096 --vcpus=1,maxvcpus=4 --disk /opt/web01.qcow2,format=qcow2,size=10 --boot hd --network bridge=br0 --graphics vnc,listen=0.0.0.0  --noautoconsole

添加内存

virsh setmem web01 2G

 

posted @ 2019-03-26 10:44  chili7  阅读(1486)  评论(0编辑  收藏  举报