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

问题一:
在安装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
fi

PATH=$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 - logstash
   Loaded: loaded (/etc/systemd/system/logstash.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-06-26 11:06:47 CST; 27s ago
 Main 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...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值