无法在 ubuntu 16.04 中将 elasticsearch 作为服务启动
Can not start elasticsearch as a service in ubuntu 16.04
我最近将我的机器从 Ubuntu 14.04
升级到 16.04
。我面临使用 elasticsearch
作为服务的问题。我 installed elasticsearch
使用:
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.
我找到了这个问题的解决方案。解决方案来自这个讨论线程 - Can’t start elasticsearch with Ubuntu 16.04 在 elastic 的网站上。
It seems that to get Elasticsearch to run on 16.04
you have to set START_DAEMON
to true on /etc/default/elasticsearch
. It comes commented out by default, and uncommenting it makes Elasticsearch start again just fine.
Be sure to use systemctl restart
instead of just start
because the
service is started right after installation, and apparently there's
some socket/pidfile/something
that systemd
keeps that must be released
before being able to start the service again.
在编辑器中打开 /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"
service elasticsearch start
问题出在日志文件上,"No java runtime was found."
Jul 30 18:28:13 dimik elasticsearch[10266]: [warning] /etc/init.d/elasticsearch: No java runtime was found
这是我解决问题的方法。
检查 elasticsearch 初始化文件
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
检查java-wrappers.sh文件
sudo nano /usr/share/java-wrappers/java-wrappers.sh
现在您可以看到警告来自
#Displays a warning
java_warning() {
echo "[warning] [=12=]: $@" >&2;
}
- 不知何故,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*"
现在重启服务,检查elasticsearch服务
sudo systemctl 重启 elasticsearch
sudo systemctl elasticsearch status
curl -X GET “http://localhost:9200”
希望这会有所帮助
我的问题不一样,我以 root 用户手动启动了 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/*
我最近将我的机器从 Ubuntu 14.04
升级到 16.04
。我面临使用 elasticsearch
作为服务的问题。我 installed elasticsearch
使用:
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.
我找到了这个问题的解决方案。解决方案来自这个讨论线程 - Can’t start elasticsearch with Ubuntu 16.04 在 elastic 的网站上。
It seems that to get Elasticsearch to run on
16.04
you have to setSTART_DAEMON
to true on/etc/default/elasticsearch
. It comes commented out by default, and uncommenting it makes Elasticsearch start again just fine.Be sure to use
systemctl restart
instead of juststart
because the service is started right after installation, and apparently there's somesocket/pidfile/something
thatsystemd
keeps that must be released before being able to start the service again.
在编辑器中打开
/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"
service elasticsearch start
问题出在日志文件上,"No java runtime was found."
Jul 30 18:28:13 dimik elasticsearch[10266]: [warning] /etc/init.d/elasticsearch: No java runtime was found
这是我解决问题的方法。
检查 elasticsearch 初始化文件
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
检查java-wrappers.sh文件
sudo nano /usr/share/java-wrappers/java-wrappers.sh
现在您可以看到警告来自
#Displays a warning
java_warning() {
echo "[warning] [=12=]: $@" >&2;
}
- 不知何故,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*"
现在重启服务,检查elasticsearch服务
sudo systemctl 重启 elasticsearch
sudo systemctl elasticsearch status
curl -X GET “http://localhost:9200”
希望这会有所帮助
我的问题不一样,我以 root 用户手动启动了 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/*