无法在 Mac Sierra (10.12.2) 上安装 Elasticsearch

Unable to install Elasticsearch on Mac Sierra (10.12.2)

尝试通过

启动 Elasticsearch 5.1.1 时

$ elasticsearch

我得到输出:

Error: Could not find or load main class -Xms2g

我调查过:

  1. 我读到它可能是如何调用 class 的错误?但我不会这样做。这 thread 没有帮助,也不是我的问题,因为我没有安装插件。
  2. 我是通过 Homebrew 安装的。这是其中的一些输出:

    $ brew info elasticsearch
    elasticsearch: stable 5.1.1, HEAD
    Distributed search & analytics engine
    https://www.elastic.co/products/elasticsearch
    Conflicts with: elasticsearch@1.7, elasticsearch@2.4
    /usr/local/Cellar/elasticsearch/5.1.1 (98 files, 35.2M) *
      Built from source on 2016-12-14 at 09:23:56
    From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/elasticsearch.rb
    ==> Requirements
    Required: java >= 1.8 ✔
    ==> Caveats
    Data:    /usr/local/var/elasticsearch/elasticsearch_GabbAHH/
    Logs:    /usr/local/var/log/elasticsearch/elasticsearch_GabbAHH.log
    Plugins: /usr/local/Cellar/elasticsearch/5.1.1/libexec/plugins/
    Config:  /usr/local/etc/elasticsearch/
    plugin script: /usr/local/Cellar/elasticsearch/5.1.1/libexec/bin/plugin
    
    To have launchd start elasticsearch now and restart at login:
      brew services start elasticsearch
    Or, if you don't want/need a background service you can just run:
      elasticsearch
    
    $ brew doctor
    Please note that these warnings are just used to help the Homebrew maintainers
    with debugging if you file an issue. If everything you use Homebrew for is
    working fine: please don't worry and just ignore them. Thanks!
    Warning: You have unlinked kegs in your Cellar
    Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
    those kegs to fail to run properly once built. Run `brew link` on these:
      mongodb
      ruby
    
  3. 我最初也尝试通过 manually extracting the .tar.gz package 安装。我一开始遇到了一些 Java 权限被拒绝的错误,但是在 运行 一个 chown 给自己管理之后,我也遇到了同样的 Error: Could not find or load main class 类型错误。

  4. 我刚刚将我的 Java JDK 更新到最新版本:1.8.0_112 并将我的 JAVA_HOME 变量相应地设置到该目录。

  5. 最新版本的 Elasticsearch 2 (2.4.3) 有效。同时,Elasticsearch v5.0.2 失败。

如何才能在我的 Mac 上正确安装 Elasticsearch?

我通常使用以下脚本在我的机器上升级和使用多个项目:

#!/bin/bash

CURRENT_PROJECT=$(pwd)
CONFIG=$CURRENT_PROJECT/config
DATA=$CURRENT_PROJECT/data
LOGS=$CURRENT_PROJECT/logs

BASH_ES_OPTS="-Epath.conf=$CONFIG -Epath.data=$DATA -Epath.logs=$LOGS"

ELASTICSEARCH=$HOME/Development/elastic/elasticsearch/elasticsearch-5.1.1

$ELASTICSEARCH/bin/elasticsearch $BASH_ES_OPTS

注意 BASH_ES_OPTS 中的选项,这些选项在版本 5 中发生了很大变化。我的结构是每个项目一个文件夹,其中包含此脚本和一些文件夹:config、data 和 logs。配置文件夹包含来自弹性分布的文件:elasticsearch.yml、jvm.properties 和 log4j2.properties.

您的 .bash_profile 很可能有问题。通常弹性开箱即用 mac.

注意 .bashrc 或类似文件中的这一行:

导出GREP_OPTIONS='--color=always'

这会破坏许多 shell 的管道,因此许多跑步者会在没有给您任何线索的情况下失败。

作为 Ubuntu 的发行版通常默认为系统用户提供此功能。小心并检查 shell 环境变量。

这个问题在我的服务器上解决了,只是取消设置这个变量。