4

我在 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 无法加载文件,可能是加载顺序问题,我真的不太确定。

4

2 回答 2

5

您应该查看 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";
};

对文件的整个路径的执行权限也是必要的。就我而言:currentcurrent/config

于 2016-02-26T09:38:10.740 回答
0

文件的路径包含在 ES 索引映射中。在创建索引时,文件本身应该存在于 ES 服务器上,但是您已经定义了该文件相对于 Rails 应用程序的路径。

于 2016-02-09T04:11:17.020 回答