调整内存
virsh setmem 命令帮助:
[root@ubuntu ~]# virsh setmem --help
NAME
setmem - change memory allocation
SYNOPSIS
setmem <domain> <size> [--config] [--live] [--current]
DESCRIPTION
Change the current memory allocation in the guest domain.
OPTIONS
[--domain] <string> domain name, id or uuid
[--size] <number> new memory size, as scaled integer (default KiB)
--config affect next boot
--live affect running domain
--current affect current domain
实验一下,调小一台虚拟机的内存:
[root@ubuntu ~]# virsh dominfo centos_server01
Id: 6
Name: centos_server01
UUID: 9953497f-930f-fa61-a0dc-174f1872294e
OS Type: hvm
State: running
CPU(s): 2
CPU time: 6.7s
Max memory: 1048576 KiB
Used memory: 1048576 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: apparmor
Security DOI: 0
Security label: libvirt-9953497f-930f-fa61-a0dc-174f1872294e (enforcing)
[root@ubuntu ~]# virsh setmem centos_server01 --size 524288 --live --config
[root@ubuntu ~]# virsh dominfo centos_server01
Id: 6
Name: centos_server01
UUID: 9953497f-930f-fa61-a0dc-174f1872294e
OS Type: hvm
State: running
CPU(s): 2
CPU time: 26.9s
Max memory: 1048576 KiB
Used memory: 524288 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: apparmor
Security DOI: 0
Security label: libvirt-9953497f-930f-fa61-a0dc-174f1872294e (enforcing)
设置最大内存限制
virsh setmaxmem 命令帮助:
[root@ubuntu ~]# virsh setmaxmem --help
NAME
setmaxmem - change maximum memory limit
SYNOPSIS
setmaxmem <domain> <size> [--config] [--live] [--current]
DESCRIPTION
Change the maximum memory allocation limit in the guest domain.
OPTIONS
[--domain] <string> domain name, id or uuid
[--size] <number> new maximum memory size, as scaled integer (default KiB)
--config affect next boot
--live affect running domain
--current affect current domain
需要关闭虚拟机再配置
[root@ubuntu ~]# virsh setmaxmem centos_server01 1572864 --config
error: Unable to change MaxMemorySize
error: Requested operation is not valid: cannot resize the maximum memory on an active domain
[root@ubuntu ~]# virsh shutdown centos_server01
Domain centos_server01 is being shutdown
[root@ubuntu ~]# virsh setmaxmem centos_server01 1572864 --config
[root@ubuntu ~]# virsh dominfo centos_server01
Id: -
Name: centos_server01
UUID: 9953497f-930f-fa61-a0dc-174f1872294e
OS Type: hvm
State: shut off
CPU(s): 2
Max memory: 1572864 KiB
Used memory: 524288 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: apparmor
Security DOI: 0
#然后现在给他加大到1G
[root@ubuntu ~]# virsh setmem centos_server01 --size 1048576 --live --config
[root@ubuntu ~]# virsh dominfo centos_server01
Id: 5
Name: centos_server01
UUID: 9953497f-930f-fa61-a0dc-174f1872294e
OS Type: hvm
State: running
CPU(s): 2
CPU time: 30.5s
Max memory: 1572864 KiB
Used memory: 1048576 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: apparmor
Security DOI: 0
Security label: libvirt-9953497f-930f-fa61-a0dc-174f1872294e (enforcing)