当前位置: 代码迷 >> 综合 >> could not find java;set JAVA_HOME or ensure java报错
  详细解决方案

could not find java;set JAVA_HOME or ensure java报错

热度:82   发布时间:2023-10-21 23:22:14.0
问题一:
在安装logstash时出现如下报错:“could not find java; set JAVA_HOME or ensure java is in PATH
chmod: cannot access ‘/etc/default/logstash’: No such file or directory
warning: %post(logstash-1:6.6.0-1.noarch) scriptlet failed, exit status 1”
could not find java; set JAVA_HOME or ensure java is in PATH
chmod: cannot access ‘/etc/default/logstash’: No such file or directory
warning: %post(logstash-1:6.6.0-1.noarch) scriptlet failed, exit status 1

原以为是jdk没有安装经查是正常的。但启动logstash 的时候也是报错的。

[root@ES3-4 opt]# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

猜测应该是环境变量的事了。

[root@ES4-4 config]# echo $PATH
/usr/local/jdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

但是发现是有的。

查看整个系统的变量,发现没有,应该就是这个问题了。
[root@kafka1-master preuser-0]# set |grep JAVA_HOME

解决步骤如下:
1、设置变量

[root@ES3-4 opt]# vim ~/.bash_profile # .bash_profile# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrc
fiPATH=$PATH:$HOME/bin
export JAVA_HOME=/usr/local/jdk
export PATH=$PATH:/usr/local/jdk/bin
[root@ES3-4 opt]# source  ~/.bash_profile

2、查看变量值
[root@ES3-4 opt]# set |grep JAVA_HOME
JAVA_HOME=/usr/local/jdk

3、重新安装ok了,问题解决。

[root@ES3-4 opt]# rpm -ivh logstash-6.6.0.rpm 
warning: logstash-6.6.0.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...1:logstash-1:6.6.0-1               ################################# [100%]
Using provided startup.options file: /etc/logstash/startup.options
Successfully created system startup script for Logstash

问题二:当设置完毕的时候还是出现如下报错"logstash: could not find java; set JAVA_HOME or ensure java is in PATH"
这是因为缺少个java的软连接,做个软连接即可解决此问题

[root@ES3-4 conf.d]# ln -s /usr/local/jdk/bin/java   /usr/bin/java[root@ES3-4 conf.d]# systemctl restart logstash
[root@ES3-4 conf.d]# systemctl status logstash
● logstash.service - logstashLoaded: loaded (/etc/systemd/system/logstash.service; enabled; vendor preset: disabled)Active: active (running) since Wed 2019-06-26 11:06:47 CST; 27s agoMain PID: 5543 (java)CGroup: /system.slice/logstash.service└─5543 /usr/bin/java -Xms1g -Xmx1g -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+...Jun 26 11:06:47 ES3-4.217 systemd[1]: Started logstash.
Jun 26 11:06:47 ES3-4.217 systemd[1]: Starting logstash...
  相关解决方案