KVM主机动态更改cpu数量和内存大小
关机状态下设置最大cpu颗数和最大内存使用量:
1
2
3
4
5
6
7
|
# virsh list --all Id Name State ------------------------------------------------- - bbotte shut off # virsh setvcpus bbotte --maximum 4 --config # virsh setmaxmem bbotte 1048576 --config |
用virsh命令调整cpu的数量(cpu颗数,已经上线主机只增不减)
现在主机状态:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# virsh dominfo bbotte Id: 2 Name: bbotte UUID: bd22f444-ee7f-7f00-3d1b-1bb0d0857e43 OS Type: hvm State: running CPU(s): 4 CPU time : 152.3s
Max memory: 1048576 KiB Used memory: 524288 KiB Persistent: yes
Autostart: disable Managed save: no Security model: none Security DOI: 0 # ps -C qemu-kvm -o rss,cmd RSS CMD
388736 /usr/libexec/qemu-kvm -name bbotte -S -M rhel6.6.0 - enable -kvm -m 1024 -realtime mlock
|
调整cpu数量:
virsh setvcpus [domain-name, domain-id or domain-uuid] [count]
减少核数:
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
1 bbotte running
[root@localhost ~]# virsh setvcpus bbotte 2 #原来4颗cpu,现在为2颗,下图为guest主机
从2颗cpu增至4颗
# virsh setvcpus bbotte 4
guest主机里面:
# CPU 2 got hotplugged
Booting Node 0 Processor 2 APIC 0x2
CPU 3 got hotplugged
kvm-clock: cpu 2, msr 0:23167c1, secondary cpu clock
Disabled fast string operations
kvm-stealtime: cpu 2, msr 230e880
Will online and init hotplugged CPU: 2
Booting Node 0 Processor 3 APIC 0x3
kvm-clock: cpu 3, msr 0:23967c1, secondary cpu clock
Disabled fast string operations
kvm-stealtime: cpu 3, msr 238e880
Will online and init hotplugged CPU: 3
KVM调整内存使用量:
virsh setmem [domain-id or domain-name] [count]
现在的内存为512M,调整为800M的话:
# virsh setmem bbotte 819200 --config --live
或者# virsh setmem bbotte 800M
# virsh dominfo bbotte
Id: 2
Name: bbotte
UUID: bd22f444-ee7f-7f00-3d1b-1bb0d0857e43
OS Type: hvm
State: running
CPU(s): 4
CPU time: 163.9s
Max memory: 1048576 KiB
Used memory: 819200 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: none
Security DOI: 0