我在EC2单服务器设置上使用Rails,Tire和Elasticsearch,没有分片或复制(这是Jenkins CI服务器)。使用自定义初始化程序:
analysis:
filter:
name_synonyms:
type: synonym
synonyms_path: <%= Rails.root.join("config", "synonyms", "name_synonyms.txt") %>
此文件通过Erubis运行,同义词路径转换为如下所示:
/root/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms/term_synonyms.txt
当我列出服务器中的文件时,我看到以下内容:
root@ip-XX-XXX-XX-XXX:~/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms# ls -la
total 20
drwxr-xr-x 2 root root 4096 Feb 11 18:25 .
drwxr-xr-x 7 root root 4096 Feb 11 18:25 ..
-rw-r--r-- 1 root root 3117 Feb 11 18:25 location_synonyms.txt
-rw-r--r-- 1 root root 3999 Feb 11 18:25 name_synonyms.txt
-rw-r--r-- 1 root root 2144 Feb 11 18:25 term_synonyms.txt
这正是我所期待的,但是在运行rake spec
500 : {"error":"IndexCreationException[[test_facilities] failed to create index]; nested: FailedToResolveConfigException[Failed to resolve config path [/root/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms/term_synonyms.txt], tried file path [/root/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms/term_synonyms.txt], path file [/etc/elasticsearch/root/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms/term_synonyms.txt], and classpath]; ","status":500}
在我看来Elasticsearch无法加载文件,虽然路径正确,可能是一个加载订单问题,我真的不太确定。
答案 0 :(得分:3)
您应该查看elasticsearch日志文件。就我而言/var/log/elasticsearch/elasticsearch.log
就我而言,我有这个:
[2016-02-26 10:28:26,321][WARN ][cluster.action.shard ] [Batragon] [myindex-1][2] received shard failed for [myindex-1][2], node[mynode], [P], v[1223], s[INITIALIZING], a[id=myid], unassigned_info[[reason=ALLOCATION_FAILED], at[2016-02-26T09:28:26.168Z], details[failed to create index, failure IndexCreationException[failed to create index]; nested: AccessControlException[access denied ("java.io.FilePermission" "/home/myuser/elasticsearch/my_synonyms.txt" "read")]; ]], indexUUID [haZBzLsuSmmxteIq-1K0vw], message [failed to create index], failure [IndexCreationException[failed to create index]; nested: AccessControlException[access denied ("java.io.FilePermission" "/home/myuser/elasticsearch/my_synonyms.txt" "read")]; ]
[myindex-1] IndexCreationException[failed to create index]; nested: AccessControlException[access denied ("java.io.FilePermission" "/home/myuser/elasticsearch/my_synonyms.txt" "read")];
at org.elasticsearch.indices.IndicesService.createIndex(IndicesService.java:360)
at org.elasticsearch.indices.cluster.IndicesClusterStateService.applyNewIndices(IndicesClusterStateService.java:307)
at org.elasticsearch.indices.cluster.IndicesClusterStateService.clusterChanged(IndicesClusterStateService.java:176)
at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:494)
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:231)
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:194)
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: java.security.AccessControlException: access denied ("java.io.FilePermission" "/home/myuser/elasticsearch/my_synonyms.txt" "read")
...
我通过授予java.policy文件的读取权限(在我的情况下为/usr/lib/jvm/java-7-oracle/jre/lib/security/java.policy
)来解决这个问题:
grant {
permission java.io.FilePermission "/home/myuser/elasticsearch/my_synonyms.txt", "read";
};
并重新启动elasticsearch服务。
您可以以更通用的方式将目录级别的权限授予目录中的任何文件,例如:
grant {
permission java.io.FilePermission "/home/myuser/current/config/elasticsearch/-", "read";
permission java.io.FilePermission "/home/myuser/current/config/elasticsearch/", "read";
};
也需要对文件的整个路径执行权限。就我而言:current
和current/config
答案 1 :(得分:0)
文件的路径包含在ES索引映射中。在创建索引时,文件本身应该存在于ES服务器上,但是您已经相对于Rails应用程序定义了此文件的路径。