java 无法在ubuntu 16.04中启动elasticsearch作为服务

kyks70gy  于 2023-01-19  发布在  Java
关注(0)|答案(6)|浏览(160)

我最近将我的计算机从Ubuntu 14.04升级到16.04。我遇到了将elasticsearch用作服务的问题。我使用installedelasticsearch

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.
iq0todco

iq0todco1#

我找到了这个问题的解决方案,这个解决方案来自于elastic网站上的这个讨论线程-Can’t start elasticsearch with Ubuntu 16.04
看起来要让Elasticsearch在16.04上运行,你必须在/etc/default/elasticsearch上将START_DAEMON设置为true。默认情况下,它被注解掉了,取消注解可以让Elasticsearch重新启动。
请确保使用systemctl restart而不仅仅是start,因为该服务在安装后立即启动,并且显然systemd保留了一些socket/pidfile/something,必须在能够再次启动该服务之前释放这些socket/pidfile/something

8fq7wneg

8fq7wneg2#

问题出在日志文件中,“未找到java运行时”。

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

这是我解决这个问题的办法。
1.检查ElasticSearch初始化文件
sudo纳米/等/初始化.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 /用户名/共享/Java Package 器/java-wrappers.sh
现在你可以看到警告来自

#Displays a warning
java_warning() {
    echo "[warning] $0: $@" >&2;
}

1.由于某种原因,java目录未在www.example.com文件中列出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.现在重新启动服务并检查elasticsearch服务
sudo systemtl重新启动ElasticSearch
sudo系统tlElasticSearch状态
curl -X获取“http://localhost:9200
希望这能有所帮助

7eumitmz

7eumitmz3#

我的问题是不同的,我启动elasticsearch手动作为根用户,所以有些文件是用错误的所有权创建的,所以elasticsearch用户不能写他们。
您可以尝试从控制台启动elasticsearch来查看错误:

sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch \
 -Des.default.config=/etc/elasticsearch/elasticsearch.yml \
 -Des.default.path.home=/usr/share/elasticsearch \
 -Des.default.path.logs=/var/log/elasticsearch \
 -Des.default.path.data=/var/lib/elasticsearch \
 -Des.default.path.work=/tmp/elasticsearch \
 -Des.default.path.conf=/etc/elasticsearch

要修复我的机器,我必须这样做:

rm -rf /var/log/elasticsearch/*
rm -rf /var/lib/elasticsearch/*
owfi6suc

owfi6suc4#

1.在编辑器中打开/etc/init.d/elasticsearch文件,在行下方注解

. /usr/share/java-wrappers/java-wrappers.sh
find_java_runtime openjdk8 oracle8 openjdk7 oracle7 openjdk6 sun6 default

手动设置JAVA_HOME,如下所示:

export JAVA_HOME="/usr"
  1. service elasticsearch start
svmlkihl

svmlkihl5#

使用删除不必要的java包

sudo apt autoremove

然后再次安装elasticsearch并启动它

sudo apt install elasticsearch
service elasticsearch status
6l7fqoea

6l7fqoea6#

是否已启用该服务?
systemctl启用ElasticSearch

相关问题