elasticsearch5.X版本运行jvm内存溢出

在docker容器中通过yml文件启动elasticsearch5.X版本提示jvm内存溢出错误

错误如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
wenbo-elasticsearch_1  | OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
wenbo-elasticsearch_1 | #
wenbo-elasticsearch_1 | # There is insufficient memory for the Java Runtime Environment to continue.
wenbo-elasticsearch_1 | # Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
wenbo-elasticsearch_1 | # Can not save log file, dump to screen..
wenbo-elasticsearch_1 | #
wenbo-elasticsearch_1 | # There is insufficient memory for the Java Runtime Environment to continue.
wenbo-elasticsearch_1 | # Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
wenbo-elasticsearch_1 | # Possible reasons:
wenbo-elasticsearch_1 | # The system is out of physical RAM or swap space
wenbo-elasticsearch_1 | # In 32 bit mode, the process size limit was hit
wenbo-elasticsearch_1 | # Possible solutions:
wenbo-elasticsearch_1 | # Reduce memory load on the system
wenbo-elasticsearch_1 | # Increase physical memory or swap space
wenbo-elasticsearch_1 | # Check if swap backing store is full
wenbo-elasticsearch_1 | # Use 64 bit Java on a 64 bit OS
wenbo-elasticsearch_1 | # Decrease Java heap size (-Xmx/-Xms)
wenbo-elasticsearch_1 | # Decrease number of Java threads
wenbo-elasticsearch_1 | # Decrease Java thread stack sizes (-Xss)
wenbo-elasticsearch_1 | # Set larger code cache with -XX:ReservedCodeCacheSize=
wenbo-elasticsearch_1 | # This output file may be truncated or incomplete.
wenbo-elasticsearch_1 | #
wenbo-elasticsearch_1 | # Out of Memory Error (os_linux.cpp:2643), pid=1, tid=0x00007f17613e4700
wenbo-elasticsearch_1 | #
wenbo-elasticsearch_1 | # JRE version: (8.0_151-b12) (build )
wenbo-elasticsearch_1 | # Java VM: OpenJDK 64-Bit Server VM (25.151-b12 mixed mode linux-amd64 compressed oops)
wenbo-elasticsearch_1 | # Core dump written. Default location: /usr/share/elasticsearch/core or core.1

###解决办法
在yml文件中添加environment:ES_JAVA_OPTS: -Xms512m -Xmx512m这样一个配置内存环境的语句即可。完整配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
version: '2'
services:
wenbo-elasticsearch:
image: elasticsearch:5.6.5
# volumes:
# - ~/volumes/jhipster/tz/elasticsearch/:/usr/share/elasticsearch/data/
ports:
- 9200:9200
- 9300:9300
environment:
ES_JAVA_OPTS: -Xms512m -Xmx512m
command: -Enetwork.host=0.0.0.0 -Ediscovery.type=single-node