KVM是否支持vCPU热插拔? Linux KVM客户端能否识别出新添加的vCPU? 答案是“当然”。 像KVM内存管理一样,您可以使用“virsh”命令将vCPU添加到活动VM。 但是必须已使用Maximum vCPUs参数配置KVM guest虚拟机,则此功能将起作用。 所以在部署新的虚拟机时,您应该始终将此参数视为先决条件。如果已使用已分配的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数量增加到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, 但您可以通过关闭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
网友评论