Java not found by Elasticsearch on Centos 6.6, all path variables are set and working

I recently deployed a roaming server and wanted Elicsearch to keep it running. So, I have installed Oracle Java and ES on the "chef / Centos-6.6" virtual virtual machine. I have set my Java path using a shell script in "etc / profile.d".

Here is my setup script:

#!/usr/bin/env bash
yum -y update

wget -O /opt/jdk-7u67-linux-x64.tar.gz --no-cookies --no-check-certificate --header   "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz"
tar xzf /opt/jdk-7u67-linux-x64.tar.gz -C /opt/
touch /etc/profile.d/java.sh
echo "export JAVA_HOME=/opt/jdk1.7.0_67" >> /etc/profile.d/java.sh
echo "export JRE_HOME=/opt/jdk1.7.0_67/jre" >> /etc/profile.d/java.sh
echo "export PATH=$PATH:/opt/jdk1.7.0_67/bin:/opt/jdk1.7.0_67/jre/bin" >> /etc/profile.d/java.sh

rpm --import http://packages.elasticsearch.org/GPG-KEY-elasticsearch
REPO="[elasticsearch-1.3]
name=Elasticsearch repository for 1.3.x packages
baseurl=http://packages.elasticsearch.org/elasticsearch/1.3/centos
gpgcheck=1
gpgkey=http://packages.elasticsearch.org/GPG-KEY-elasticsearch
enabled=1"
echo "$REPO" > /etc/yum.repos.d/elasticsearch.repo
yum install -y elasticsearch

      

The installation is going well. However, when I run "sudo service elasticsearch start" I get:

which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)

      

but if I "echo $ PATH" for the home user, I get:

/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/jdk1.7.0_67/bin:/opt/jdk1.7.0_67/jre/bin:/home/vagrant/bin

      

and for root user $ PATH I get:

/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/jdk1.7.0_67/bin:/opt/jdk1.7.0_67/jre/bin

      

and "echo $ JAVA_HOME" I get:

/opt/jdk1.7.0_67

      

if i run "which java" i get:

/opt/jdk1.7.0_67/bin/java

      

and if i run "java" it shows up with a man page.

What does elasticsearch look like not looking at my path for java? Why is it only looking at the default Centos path? What am I missing here?

+3


source to share


1 answer


Probably the source of your problem is that the init scripts (Elastic init script in this case) do not see most of the environment variables (for example JAVA_HOME

, JRE_HOME

etc.).

If you look at the ElasticSearch init script , you can see that the variable is PATH

set explicitly in what the init script is and JAVA_HOME

is defined by looping through a predefined set of possible locations:

JDK_DIRS="/usr/lib/jvm/jdk-7-oracle-x64 /usr/lib/jvm/java-7-oracle /usr/lib/jvm/java-7-openjdk /usr/lib/jvm/java-7-openjdk-amd64/ /usr/lib/jvm/java-7-openjdk-armhf /usr/lib/jvm/java-7-openjdk-i386/ /usr/lib/jvm/default-java"

      



So, you can place your Java installation in a directory /usr/lib/jvm/jdk-7-oracle-x64

, for example , and the init script should pick it up.

Update

Looking at the init script, I noticed that you can set JAVA_HOME

in /etc/default/elasticsearch

to loop through the predefined JDK locations as above ( Source ).

+1


source







All Articles