我有一台全新的 Macbook Air,配有 M1 处理器
遵循官方指南https://www.elastic.co/guide/en/elasticsearch/reference/current/brew.html我尝试使用以下方式安装elasticsearch 7:
brew tap elastic/tap
brew install elastic/tap/elasticsearch-full
一旦我尝试用
$ elasticsearch
启动它,我就会收到此错误:
/opt/homebrew/Cellar/elasticsearch-full/7.16.2/libexec/bin/elasticsearch-env: line 83: /opt/homebrew/Cellar/elasticsearch-full/7.16.2/libexec/jdk.app/Contents/Home/bin/java: Bad CPU type in executable
如果我尝试使用
brew services start elastic/tap/elasticsearch-full
启动服务,它将失败,并且我会在日志文件中收到相同的错误 /opt/homebrew/var/log/elasticsearch.log
/opt/homebrew/Cellar/elasticsearch-full/7.16.2/libexec/bin/elasticsearch-env: line 83: /opt/homebrew/Cellar/elasticsearch-full/7.16.2/libexec/jdk.app/Contents/Home/bin/java: Bad CPU type in executable
一旦我打开导致问题的文件 (
elasticsearch-env
),第 83 行会显示:
# check the Java version
"$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.java_version_checker.JavaVersionChecker
如果我尝试执行
/opt/homebrew/Cellar/elasticsearch-full/7.16.2/libexec/jdk.app/Contents/Home/bin/java
我收到错误
Bad CPU type in executable
所以在elasticsearch-fullbrew安装过程中似乎安装了一个糟糕的Java架构(也许不是M1,而是x84或其他什么?)。这是几个小时前买的全新 Macbook。 Elasticsearch 是我尝试在其上进行 brew install 的第一件事(因此之前没有安装 Java 应用程序)
有人知道如何解决这个问题吗?
您还可以通过在 ARM Mac 上安装 Rosetta 2 来解决此问题:
softwareupdate --install-rosetta
。
显然brew仍然安装64位版本的elasticsearch。
此说明帮助我解决了 M1 上的此问题https://gist.github.com/todgru/0ba097d63318313f12a52594217f8e2b