CentOS7.6中 KVM虚拟机内存、CPU调整

CentOS7.6中 KVM虚拟机内存、CPU调整

 

一、调小虚拟机内存

调小虚拟机内存可以动态实现,不用关机

1.查看当前内存大小

[root@heyong kvm]# virsh dominfo test
Id:             7
名称:       test
UUID:           8f2bb4b7-c7ed-31aa-3676-9fb04923163d
OS 类型:    hvm
状态:       running
CPU:          4
CPU 时间:   3985.0s
最大内存: 12024832 KiB
使用的内存: 12024000 KiB
持久:       否
自动启动: 禁用
管理的保存: 否
安全性模式: none
安全性 DOI: 0

或者

[root@heyong kvm]# virsh dominfo test|grep 内存
最大内存: 12024832 KiB
使用的内存: 12024000 KiB

  

2.设置虚拟机内存大小为4G

[root@heyong ~]# virsh setmem test 4097152

  

3.再次查看当前内存大小

[root@heyong kvm]# virsh dominfo test|grep 内存
最大内存: 4098048 KiB
使用的内存: 4097152 KiB

  

二、增大虚拟机内存和CPU个数

增大虚拟机内存、增加虚拟机CPU个数需要首先关机虚拟机

1.关闭虚拟机

[root@heyong kvm]# virsh shutdown test

  

2.编辑虚拟机配置文件

修改内存大小、CPU个数

[root@heyong kvm]# virsh edit test

<domain type='kvm'>
  <name>test</name>
  <uuid>619066ac-c7b9-4d99-9b48-560112520890</uuid>
  <memory unit='KiB'>4097152</memory>
  <currentMemory unit='KiB'>4097152</currentMemory>
  <vcpu placement='static'>2</vcpu>
....

  

3.从配置文件启动虚拟机

[root@heyong kvm]# virsh create /etc/libvirt/qemu/test.xml  

  

4.查看当前内存大小

[root@heyong kvm]# virsh dominfo test|grep 内存
最大内存: 4098048 KiB
使用的内存: 4097152 KiB

  

5.设置虚拟机内存大小为6G

[root@heyong ~]# virsh setmem test 6048432

  

6.验证

查看当前内存大小

[root@heyong ~]# virsh dominfo test | grep 内存
最大内存:     6048432 KiB  
使用的内存:    6048432 KiB  

  

查看当前CPU个数

[root@heyong kvm]# virsh dominfo test|grep CPU
CPU:          2
CPU 时间:   37.6s

  

 

posted @ 2019-08-07 16:27  何宇泽  阅读(899)  评论(0编辑  收藏  举报