centos启动tomcat报错 failed; error=‘Cannot allocate memory’ (errno=12)服务器内存不足
1. 问题
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=256m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c0000000, 358088704, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 358088704 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/platform/tomcat/apache-tomcat-9.0.31/bin/hs_err_pid21205.log
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=256m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c0000000, 358088704, 0) failed; error='Cannot allocate memory' (errno=12)
报错信息显示项目配置的启动内存比服务器空闲内存更大。
2. 解决方法
(1)杀死没有用的进程
使用命令ps -ef
查看正在运行的进程,如果确定无用,使用命令kill -9 pid
杀死进程
一次性杀死多个java进程:
pkill java
(2)扩大内存
① 使用命令sysctl -a|grep vm.max_map_count
查询内存大小
② 调整内存大小为默认的4倍
临时修改:
[root@localhost ~]# sysctl -w vm.max_map_count=262144
永久修改:
直接写到/etc/sysctl.conf中,然后执行sysctl -p
[root@localhost ~]# vim /etc/sysctl.conf
vm.max_map_count=262144
[root@localhost ~]# sysctl -p
③ 查看修改结果
[root@localhost ~]# sysctl -a|grep vm.max_map_count
vm.max_map_count = 262144