配置CPU virsh edit CentOS-7-x86_64
修改cpu从静态1个到动态2个,只用1个 <vcpu placement='static'>1</vcpu>→ <vcpu placement='auto' current="1">2</vcpu> 关闭、启动虚拟机后cat /proc/cupinfo processor 0 代表1个

热添加cpu到2个,contos7才支持,只支持热添加,不支持热减少 virsh setvcpus CentOS-7-x86_64 2 --live

cat /proc/cupinfo processor 1 代表2个 查看cpu工作情况 [root@kvm1 ~]# cat /proc/interrupts CPU0 CPU1
0: 145 0 IO-APIC-edge timer 1: 10 0 IO-APIC-edge i8042 6: 3 0 IO-APIC-edge floppy 8: 0 0 IO-APIC-edge rtc0 9: 1 0 IO-APIC-fasteoi acpi 10: 0 0 IO-APIC-fasteoi uhci_hcd:usb3, uhci_hcd:usb4 11: 26 0 IO-APIC-fasteoi ehci_hcd:usb1, uhci_hcd:usb2, virtio3 12: 15 0 IO-APIC-edge i8042 14: 535 0 IO-APIC-edge ata_piix 15: 0 0 IO-APIC-edge ata_piix 24: 0 0 PCI-MSI-edge virtio2-config 25: 5675 0 PCI-MSI-edge virtio2-req.0 26: 0 0 PCI-MSI-edge virtio0-config 27: 459 0 PCI-MSI-edge virtio0-input.0 28: 1 0 PCI-MSI-edge virtio0-output.0 29: 0 0 PCI-MSI-edge virtio1-config 30: 5 0 PCI-MSI-edge virtio1-virtqueues NMI: 0 0 Non-maskable interrupts LOC: 25713 2829 Local timer interrupts SPU: 0 0 Spurious interrupts PMI: 0 0 Performance monitoring interrupts IWI: 1073 1 IRQ work interrupts RTR: 0 0 APIC ICR read retries RES: 6 48 Rescheduling interrupts CAL: 0 350 Function call interrupts TLB: 0 2 TLB shootdowns TRM: 0 0 Thermal event interrupts THR: 0 0 Threshold APIC interrupts DFR: 0 0 Deferred Error APIC interrupts MCE: 0 0 Machine check exceptions MCP: 2 1 Machine check polls ERR: 0 MIS: 0 PIN: 0 0 Posted-interrupt notification event PIW: 0 0 Posted-interrupt wakeup event

配置内存 virsh edit CentOS-7-x86_64
修改最大内存和当前内存,内存可以热添加和热减少 <memory unit='KiB'>2048576</memory> <currentMemory unit='KiB'>1048576</currentMemory>

查看当前内存 virsh qemu-monitor-command CentOS-7-x86_64 --hmp --cmd info balloon 设置内存为600M virsh qemu-monitor-command CentOS-7-x86_64 --hmp --cmd balloon 600

硬盘 全镜像模式 raw:全占用,性能好 稀疏模式 qcow2:用多少,占用多少,支持压缩,快照功能。openstack首先 查看硬盘占用 root@kvm ~]# cd /opt [root@kvm opt]# qemu-img info CentOS7-x86_64.raw image: CentOS7-x86_64.raw file format: raw virtual size: 10G (10737418240 bytes) disk size: 1.2G 网络 编辑虚拟机网卡修改为桥接,让外部可以访问 命令添加网桥br0 brctl addbr br0 查看网桥 brctl show 将eth0加入br0 brctl addif br0 eth0 删除原eth0的ip ip addre del dev eth0 10.0.0.111/24 设置br0的ip ifconfig br0 10.0.0.111/24 up

virsh edit Centos6.5 修改

<interface type='default'> 改为<interface type='bridge'>

<source network='default'/> 改为<source bridge='br0'/> 在物理机中 eth0→新增BRIDGE=br0 br0→ TYPE=Bridge NAME=br0 DEVICE=br0

删除虚拟机 virsh undefine Centos6.5 关闭虚拟机电源 virsh destroy Centos6.5 挂起虚拟机 virsh suspend Centos6.5 恢复 virsh resume Centos6.5