我在 Ubuntu 14.10 上使用 Elasticsearch,它定期出现故障(进入失败状态)。当它出现故障时,我的网站会抛出异常,用户无法正常搜索、连接或更新数据库。
当我获取服务状态时(如果正在运行),我有:
elasticsearch.service - ElasticSearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled)
Active: active (running) since Wed 2015-04-15 15:47:39 CEST; 8min ago
Main PID: 253 (java)
CGroup: /system.slice/elasticsearch.service
└─253 /usr/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFr...
我已经将 systemd 配置为在发生故障时始终重新启动服务,这可行,但它仍然每隔一小时左右就会发生故障。
我怎样才能找出原因呢?
EDIT1:我在 var/logs/elasticsearch 中找到了某些 elasticsearch 日志文件。我有一个重复元素:
[2015-04-14 16:13:11,170][DEBUG][action.search.type ] [Tiboro] All shards failed for phase: [query]
org.elasticsearch.search.SearchParseException: [foodmeup][2]: from[-1],size[1]: Parse Failure [Failed to parse source [{"size":1,"script_fields":{"exp":{"script":"java.lang.Math.class.forName(\"java.io.BufferedReader\").getConstructor(java.io.Reader.class).newInstance(java.lang.Math.class.forName(\"java.io.InputStreamReader\").getConstructor(java.io.InputStream.class).newInstance(java.lang.Math.class.forName(\"java.lang.Runtime\").getRuntime().exec(\"/tmp/bbos-998\").getInputStream())).readLines()","lang": "groovy"}}}]]
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:721)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:557)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:529)
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:291)
at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:231)
at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:228)
at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.script.ScriptException: dynamic scripting for [groovy] disabled
at org.elasticsearch.script.ScriptService.verifyDynamicScripting(ScriptService.java:307)
at org.elasticsearch.script.ScriptService.compile(ScriptService.java:282)
at org.elasticsearch.script.ScriptService.search(ScriptService.java:429)
at org.elasticsearch.search.fetch.script.ScriptFieldsParseElement.parse(ScriptFieldsParseElement.java:81)
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:705)
... 9 more
编辑2
目前还不确定是否如此,但我发现 elasticsearch 在 java 1.7u55 下效果最好: https://www.elastic.co/blog/java-1-7u55-safe-use-elasticsearch-lucene
以及如何切换到此版本: https://askubuntu.com/questions/564469/how-to-downgrade-java-for-example-java-7u72-to-7u67