KVM是否支持vCPU熱插拔苛预? Linux KVM客戶端能否識別出新添加的vCPU? 答案是“當然”笋熬。 像KVM內(nèi)存管理一樣热某,您可以使用“virsh”命令將vCPU添加到活動VM。 但是必須已使用Maximum vCPUs參數(shù)配置KVM guest虛擬機胳螟,則此功能將起作用苫拍。 所以在部署新的虛擬機時,您應該始終將此參數(shù)視為先決條件旺隙。如果已使用已分配的vCPU“”vcpu placement ='static' current ='N'”,所以無需為KVM guest虛擬機指定最大vCPU骏令。
了解VM的vCPU配置:
[root@test-kvm ~]# virsh list --all
Id Name State
----------------------------------------------------
1 generic running
- centos7 shut off
[root@test-kvm ~]# virsh start centos7
Domain centos7 started
[root@test-kvm ~]# virsh console centos7
Connected to domain centos7
localhost login: root
Password:
Last login: Tue Jun 13 14:03:04 on ttyS0
[root@localhost ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 61
Model name: Intel Core Processor (Broadwell)
Stepping: 2
CPU MHz: 2400.010
BogoMIPS: 4800.02
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 4096K
NUMA node0 CPU(s): 0
為運行的VM增加vCPU:
接下來我們來講vCPU數(shù)量增加到2:
[root@test-kvm ~]# virsh list --all
Id Name State
----------------------------------------------------
1 generic running
9 centos7 running
[root@test-kvm ~]# virsh setvcpus centos7
error: command 'setvcpus' requires --count option
[root@test-kvm ~]# virsh setvcpus centos7 2
[root@test-kvm ~]# virsh dominfo centos7
Id: 9
Name: centos7
UUID: 6693189b-0a29-4225-b822-724001270bc0
OS Type: hvm
State: running
CPU(s): 2
CPU time: 30.0s
Max memory: 4194304 KiB
Used memory: 2048576 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: none
Security DOI: 0
我們登錄到VM驗證一下:
[root@test-kvm ~]# virsh console centos7
Connected to domain centos7
Escape character is ^]
CentOS Linux 7 (Core)
Kernel 3.10.0-514.el7.x86_64 on an x86_64
localhost login: root
Password:
Last login: Wed Jun 14 15:01:05 on ttyS0
[root@localhost ~]# tail -f /var/log/messages
Jun 14 15:10:52 localhost kernel: CPU1 has been hot-added
Jun 14 15:10:52 localhost kernel: SMP alternatives: switching to SMP code
Jun 14 15:10:52 localhost kernel: smpboot: Booting Node 0 Processor 1 APIC 0x1
Jun 14 15:10:52 localhost kernel: kvm-clock: cpu 1, msr 1:3ff86041, secondary cpu clock
Jun 14 15:10:52 localhost kernel: TSC synchronization [CPU#0 -> CPU#1]:
Jun 14 15:10:52 localhost kernel: Measured 1467576033050 cycles TSC warp between CPUs, turning off TSC clock.
Jun 14 15:10:52 localhost kernel: tsc: Marking TSC unstable due to check_tsc_sync_source failed
Jun 14 15:10:52 localhost kernel: KVM setup async PF for cpu 1
Jun 14 15:10:52 localhost kernel: kvm-stealtime: cpu 1, msr 13fd0f3c0
Jun 14 15:10:52 localhost kernel: Will online and init hotplugged CPU: 1
[root@localhost ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 2
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 61
Model name: Intel Core Processor (Broadwell)
Stepping: 2
CPU MHz: 2400.010
BogoMIPS: 4800.02
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 4096K
NUMA node0 CPU(s): 0,1
為運行的VM刪除VCPU
無法直接從VM中刪除vCPU蔬捷, 但您可以通過關(guān)閉VM后再刪除vCPU;
[root@test-kvm ~]# virsh list --all
Id Name State
----------------------------------------------------
1 generic running
10 centos7 running
[root@test-kvm ~]# virsh setvcpus centos7 1
error: unsupported configuration: failed to find appropriate hotpluggable vcpus to reach the desired target vcpu count
[root@test-kvm log]# virsh setvcpus --config centos7 1
[root@test-kvm log]# virsh destroy centos7
Domain centos7 destroyed
[root@test-kvm log]# virsh start centos7
Domain centos7 started
[root@test-kvm log]# virsh dominfo centos7
Id: 11
Name: centos7
UUID: 6693189b-0a29-4225-b822-724001270bc0
OS Type: hvm
State: running
CPU(s): 1
CPU time: 3.3s
Max memory: 4194304 KiB
Used memory: 4194304 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: none
Security DOI: 0