无法在 ubuntu 16.04 中启动 elasticsearch 即服务

2022-09-03 03:26:42

我最近将我的机器从 Ubuntu 升级到 .我面临着将 作为服务使用的问题。我使用以下方法安装14.0416.04elasticsearchelasticsearch

sudo apt-get install elasticsearch

现在命令显示我这个结果:sudo service elasticsearch status

elasticsearch.service - LSB: Starts elasticsearch
   Loaded: loaded (/etc/init.d/elasticsearch; bad; vendor preset: enabled)
   Active: active (exited) since Sat 2016-07-30 18:28:13 BDT; 1h 19min ago
     Docs: man:systemd-sysv-generator(8)
 Main PID: 7988 (code=exited, status=1/FAILURE)
   CGroup: /system.slice/elasticsearch.service

Jul 30 18:28:13 dimik elasticsearch[10266]: [warning] /etc/init.d/elasticsearch: No java runtime was found
Jul 30 18:28:13 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 18:28:46 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 18:35:30 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 19:04:36 dimik systemd[1]: Started A search engine.
Jul 30 19:07:48 dimik systemd[1]: Started A search engine.
Jul 30 19:27:01 dimik systemd[1]: Started A search engine.
Jul 30 19:27:51 dimik systemd[1]: Started A search engine.
Jul 30 19:28:54 dimik systemd[1]: Started A search engine.
Jul 30 19:29:18 dimik systemd[1]: Started LSB: Starts elasticsearch.

虽然Java已安装在我的机器中,但我可以使用此命令启动服务器。

sudo /usr/share/elasticsearch/bin/elasticsearch

我有点被困在这里。任何帮助将不胜感激。

编辑

为 root 设置后出现错误:JAVA_HOME

elasticsearch.service - LSB: Starts elasticsearch
   Loaded: loaded (/etc/init.d/elasticsearch; bad; vendor preset: enabled)
   Active: active (exited) since Sat 2016-07-30 18:28:13 BDT; 3h 32min ago
     Docs: man:systemd-sysv-generator(8)
 Main PID: 7988 (code=exited, status=1/FAILURE)
   CGroup: /system.slice/elasticsearch.service

Jul 30 18:35:30 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 19:04:36 dimik systemd[1]: Started A search engine.
Jul 30 19:07:48 dimik systemd[1]: Started A search engine.
Jul 30 19:27:01 dimik systemd[1]: Started A search engine.
Jul 30 19:27:51 dimik systemd[1]: Started A search engine.
Jul 30 19:28:54 dimik systemd[1]: Started A search engine.
Jul 30 19:29:18 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 20:02:07 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 20:20:21 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 21:59:21 dimik systemd[1]: Started LSB: Starts elasticsearch.

答案 1

我找到了这个问题的解决方案。解决方案来自这个讨论线程 - 无法在elastic的网站上使用Ubuntu 16.04启动elasticsearch

似乎要让 Elasticsearch 在 上运行,您必须在 上运行,您必须在 上设置为 true。默认情况下,它被注释掉了,取消注释会使Elasticsearch再次启动。16.04START_DAEMON/etc/default/elasticsearch

请务必使用,而不仅仅是因为服务是在安装后立即启动的,显然有一些保留必须释放才能再次启动服务。systemctl restartstartsocket/pidfile/somethingsystemd


答案 2

问题在于日志文件“未找到 Java 运行时”。

Jul 30 18:28:13 dimik elasticsearch[10266]: [warning] /etc/init.d/elasticsearch: No java runtime was found

这是我对这个问题的解决方案。

  1. 检查弹性搜索初始化文件

    sudo nano /etc/init.d/elasticsearch

寻找

. /usr/share/java-wrappers/java-wrappers.sh
find_java_runtime openjdk8 oracle8 openjdk7 oracle7 openjdk6 sun6 default
export JAVA_HOME
  1. 检查 java-wrappers.sh 文件

    sudo nano /usr/share/java-wrappers/java-wrappers.sh

现在你可以看到警告来自

#Displays a warning
java_warning() {
    echo "[warning] $0: $@" >&2;
}
  1. 不知何故,java目录未在 jvm-list.sh 文件中列出

现在编辑 jvm-list.sh 文件

sudo nano /usr/lib/java-wrappers/jvm-list.sh

编辑行添加您的java目录文件,在我的情况下添加/usr/lib/jvm/java-8-oracle*

__jvm_oracle8="/usr/lib/jvm/jdk-8-oracle-* /usr/lib/jvm/jre-8-oracle-* /usr/lib/jvm/java-8-oracle*"
  1. 现在重新启动服务并检查弹性搜索服务

    sudo systemctl restart elasticsearch
    sudo systemctl elasticsearch status
    curl -X GET “http://localhost:9200"

希望这会有所帮助