elasticsearch : which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
查看 elasticsearch 服务状态是,报出以下错误
[root@elk-node1 ~]# systemctl status elasticsearch.service
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 五 2020-04-10 23:51:54 CST; 5min ago
Docs: http://www.elastic.co
Main PID: 1253 (code=exited, status=1/FAILURE)4月 10 23:51:54 elk-node1 systemd[1]: Starting Elasticsearch...
4月 10 23:51:54 elk-node1 systemd[1]: Started Elasticsearch.
4月 10 23:51:54 elk-node1 elasticsearch[1253]: which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
4月 10 23:51:54 elk-node1 systemd[1]: elasticsearch.service: main process exited, code=exited, status=1/FAILURE
4月 10 23:51:54 elk-node1 systemd[1]: Unit elasticsearch.service entered failed state.
4月 10 23:51:54 elk-node1 systemd[1]: elasticsearch.service failed.
解决方法:
方法一:
查看 java 安装位置
[root@elk-node1 ~]# which java
/usr/local/java/jdk1.8.0_191/bin/java
建立软连接
[root@elk-node1 ~]# ln -s /usr/local/java/jdk1.8.0_191/bin/java /usr/bin/java
方法二:
在 /etc/sysconfig/elasticsearch 中添加 JAVA_HOME 环境变量的配置
vim /etc/sysconfig/elasticsearch
文件部分展示:
################################
# Elasticsearch
################################# Elasticsearch home directory
ES_HOME=/usr/share/elasticsearch# Elasticsearch Java path
JAVA_HOME=/usr/local/java/jdk1.8.0_191
Process: 2000 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet -Edefault.path.logs=${LOG_DIR} -Edefault.path.data=${DATA_DIR} -Edefault.path.conf=${CONF_DIR} (code=exited, status=1/FAILURE)
Process: 1999 ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec (code=exited, status=0/SUCCESS)
Main PID: 2000 (code=exited, status=1/FAILURE)
查看 elasticsearch 服务器状态,如下:
[root@elk-node1 ~]# systemctl status elasticsearch.service
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 六 2020-04-11 11:26:09 CST; 2s ago
Docs: http://www.elastic.co
Process: 2107 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet -Edefault.path.logs=${LOG_DIR} -Edefault.path.data=${DATA_DIR} -Edefault.path.conf=${CONF_DIR} (code=exited, status=1/FAILURE)
Process: 2106 ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec (code=exited, status=0/SUCCESS)
Main PID: 2107 (code=exited, status=1/FAILURE)4月 11 11:26:06 elk-node1 systemd[1]: Starting Elasticsearch...
4月 11 11:26:06 elk-node1 systemd[1]: Started Elasticsearch.
4月 11 11:26:09 elk-node1 elasticsearch[2107]: Exception in thread ...
4月 11 11:26:09 elk-node1 systemd[1]: elasticsearch.service: main ...E
4月 11 11:26:09 elk-node1 systemd[1]: Unit elasticsearch.service e....
4月 11 11:26:09 elk-node1 systemd[1]: elasticsearch.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
解决方法:
在 /etc/sysconfig/elasticsearch 中配置环境
vim /etc/sysconfig/elasticsearch
文件部分展示:
################################
# Elasticsearch
################################# Elasticsearch home directory
ES_HOME=/usr/share/elasticsearch# Elasticsearch Java path
JAVA_HOME=/usr/local/java/jdk1.8.0_191# Elasticsearch configuration directory
CONF_DIR=/etc/elasticsearch# Elasticsearch data directory
DATA_DIR=/data/elk_data# Elasticsearch logs directory
LOG_DIR=/var/log/elasticsearch# Elasticsearch PID directory
PID_DIR=/var/run/elasticsearch