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";
};

ファイルまでのパス全体に対する実行権限も必要です。私の場合:currentそしてcurrent/config

于 2016-02-26T09:38:10.740 に答える
0

ファイルへのパスは、ES インデックス マッピングに含まれています。ファイル自体は、インデックスの作成時に ES サーバー上にあると想定されますが、このファイルへのパスは Rails アプリケーションに相対的に定義されています。

于 2016-02-09T04:11:17.020 に答える