在一次使用虛擬機做實驗的過程中啟動elasticsearch遇到了這樣的報錯:
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 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 2060255232 bytes for committing reserved memory. # An error report file with more information is saved as: # /usr/local/elasticsearch-5.6.0/bin/hs_err_pid2819.log
問題在於 ES 5.x版本 需要2G內存 -Xms2G -Xmx2G
本地物理內存過小導致
參考
http://blog.51cto.com/10950710/2124131
解決:
原因:
查看了 /usr/local/elasticsearch-5.6.0/bin/hs_err_pid1027.log日志文件,出現這樣的報錯,有兩種可能:
1、系統進程數達到上限了,部署服務的時候/etc/security/limits.conf文件修改沒有生效。
2、確實物理內存不夠
解決:
通過命令查看系統限制:ulimit -a查看open files不夠大,如果不夠大,就嘗試通過設大該值:
[root@docker ~]# ulimit -n 1024
果然是部屬的時候修改的/etc/security/limits.conf文件沒有生效。於是將機器reboot了一下,在查看就生效了:
[root@docker ~]# ulimit -n 65536
但是在啟動的時候還是報同樣的錯,查看了一下內存,這個虛擬機的內存只有1G,那應該就是物理內存不夠了。目前還剩下這么多:
[root@docker ~]# free -h total used free shared buff/cache available Mem: 974M 119M 79M 7.7M 775M 680M Swap: 819M 0B 819M
手動清理了一下內存:
[root@docker ~]# echo 3 > /proc/sys/vm/drop_caches [root@docker ~]# free -h total used free shared buff/cache available Mem: 974M 114M 789M 7.7M 69M 739M Swap: 819M 0B 819M [root@docker ~]#
但是在啟動報錯依舊。
於是增加物理內存到2G:
[root@docker elk]# free -h total used free shared buff/cache available Mem: 1.8G 1.6G 77M 4K 72M 29M Swap: 819M 691M 128M
然后切換到elk用戶去啟動服務,就OK了:
[elk@docker bin]$ ./elasticsearch #為了看啟動日志就前台啟動的,ctrl+c 進程就會over掉
檢查端口,起來了
[root@docker elk]# netstat -tlunp|grep 9200 tcp6 0 0 10.0.0.16:9200 :::* LISTEN 9628/java [root@docker elk]#
然后關掉進程重新后台啟動:
[elk@docker bin]$ nohup ./elasticsearch >/dev/null 2>&1 & #后台啟動 [2] 9808 [elk@docker bin]$ ps -ef|grep elasticsearch #檢查進程 elk 9808 4115 10 01:29 pts/0 00:00:23 /usr/local/jdk1.8.0_151/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/usr/local/elasticsearch-5.6.0 -cp /usr/local/elasticsearch-5.6.0/lib/* org.elasticsearch.bootstrap.Elasticsearch elk 9890 4115 0 01:32 pts/0 00:00:00 grep --color=auto elasticsearch [elk@docker bin]$ [root@docker elk]# netstat -tlunp|grep 9200 #用root用戶檢查端口 tcp6 0 0 10.0.0.16:9200 :::* LISTEN 9808/java [root@docker elk]#