改变CPU和内存的配置可以通过编辑VM定义的XML文件或者使用libvrit工具。
(1)获取运行实例的内存信息
[email protected]:~# virsh dommemstat kvm1
actual 1048576
swap_in 0
rss 333644
(2)更新虚拟机的有效内存至2GB
[email protected]:~# virsh setmem kvm1 --size 1049000
(3)停止运行的实例
[email protected]:~# virsh destroy kvm1
Domain kvm1 destroyed
(4)设置可以使用的最大内存为2GB
[email protected]:~# virsh setmaxmem kvm1 --size 2097152
(5)启动虚拟机实例
[email protected]:~# virsh start kvm1
Domain kvm1 started
(6)检查当前分配的有效内存
[email protected]:~# virsh dommemstat kvm1
actual 2097152
swap_in 0
rss 214408
(7)连接KVM实例和在Guest OS中检查有效内存
[email protected]:~# virsh console kvm1
Connected to domain kvm1
Escape character is ^]
Debian GNU/Linux 8 debian ttyS0
debian login: root
Password:
...
[email protected]:~# free -m
total used free shared buffers cached
Mem: 2010 93 1917 5 8 40
-/+ buffers/cache: 43 1966
Swap: 382 0 3 82
(8)在定义的XML文件中检查内存设置
[email protected]:~# virsh dumpxml kvm1 | grep memory
<memory unit=‘KiB‘>2097152</memory>
(9)获取关于CPU的信息
[email protected]:~# virsh vcpuinfo kvm1
VCPU: 0
CPU: 29
State: running
CPU time: 9.7s
CPU Affinity: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
(10)列出Guest OS使用的虚拟CPU数量
[email protected]:~# virsh vcpucount kvm1
maximum config 1
maximum live 1
current config 1
current live 1
(11)在VM的XML文件中把CPU的数量改变为4
[email protected]:~# virsh edit kvm1
...
<vcpu placement=‘static‘>4</vcpu>
...
Domain kvm1 XML configuration edited.
(12)确认一下我们改变的是否有效。
[email protected]:~# virsh vcpucount kvm1
maximum config 4
maximum live 4
current config 4
current live 4
[email protected]:~# virsh dumpxml kvm1 | grep -i cpu
<vcpu placement=‘static‘>4</vcpu>
原文地址:http://blog.51cto.com/aishangwei/2124521
时间: 2024-10-14 04:29:52