Ubuntu 16 (AWS) fresh install - Java?

194 views
Skip to first unread message

Kat

unread,
Jan 22, 2018, 12:36:56 PM1/22/18
to Wazuh mailing list
Ok, someone is going to say, "Kat, how silly (stupid?) are you - it is right here..."

But for the life of me, I can 't get ElasticSearch to pick up the setting for JAVA_HOME, no matter where I put it. In /etc/defaults/elasticsearch, in the startup init.d script directly, just exporting it by hand - nothing will get Elasticsearch started on a clean AWS instance of Ubuntu 16.04

Comments? Should I just go back to Linux Admin School - this one is driving me nutty.

Kat

jesus.g...@wazuh.com

unread,
Jan 23, 2018, 3:39:15 AM1/23/18
to Wazuh mailing list
Hi Kat, sometimes Java could be a bit ugly but don't worry, let's do some steps to verify it.
Assuming you have installed Elasticsearch from packages, and it's running as service, you
should not edit any configuration file from Elasticsearch related to Java.

Try to install  it as follow before continue the tutorial:

# add-apt-repository ppa:webupd8team/java
# apt-get update
# apt-get install -y oracle-java8-installer

Once time you have installed Java, check this:

# file $(which java)
 
// You should see -->
/usr/bin/java: symbolic link to /etc/alternatives/java


$ file /etc/alternatives/java
// You should see --> /etc/alternatives/java: symbolic link to /usr/lib/jvm/java-8-oracle/jre/bin/java

Copy and paste the bellow lines on the .bashrc files of root and ec2-user located on their home directories:

export JAVA_HOME="/usr/lib/jvm/java-8-oracle"
PATH
=$JAVA_HOME/bin:$PATH

Refresh environment:

# source /path_to_root_home/.bashrc
# source /path_to_ec2_user_home/.bashrc

Now you could do this:

$ echo $JAVA_HOME
 
// You should see
/usr/lib/jvm/java-8-oracle

That's all my friend, now you should have Java on the right way and running without any more troubles.

Best regards,
Jesús.

Kat

unread,
Jan 23, 2018, 7:50:38 AM1/23/18
to Wazuh mailing list
None of that has ever been the problem. It was installed with no issues at all, and all my test programs work fine, it is only Elasticsearch that fails:

ubuntu@wazuh:~$ java -version

java version "1.8.0_161"

Java(TM) SE Runtime Environment (build 1.8.0_161-b12)

Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)


ubuntu@wazuh:~$ sudo su -


root@wazuh:~# java -version

java version "1.8.0_161"

Java(TM) SE Runtime Environment (build 1.8.0_161-b12)

Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

root@wazuh:~# echo $JAVA_HOME

/opt/jre1.8.0_161


From /var/log/syslog



root@wazuh:~# systemctl restart elasticsearch


Jan 23 12:46:51 wazuh elasticsearch[12380]: could not find java; set JAVA_HOME or ensure java is in PATH

Jan 23 12:46:51 wazuh systemd[1]: elasticsearch.service: Main process exited, code=exited, status=1/FAILURE

Jan 23 12:46:51 wazuh systemd[1]: elasticsearch.service: Unit entered failed state.

Jan 23 12:46:51 wazuh systemd[1]: elasticsearch.service: Failed with result 'exit-code'.

Kat

unread,
Jan 23, 2018, 8:43:10 AM1/23/18
to Wazuh mailing list
And now it gets stranger - 

Spun up vanilla Ubuntu 16.04 on VM under VIrtualBox and installed the same way. IT WORKS!

AWS Install of Ubuntu 16.04 does NOT! 

Time to go troubleshoot some very strange weirdness indeed. 


On Monday, January 22, 2018 at 11:36:56 AM UTC-6, Kat wrote:

Jesús Ángel González

unread,
Jan 23, 2018, 8:57:59 AM1/23/18
to Kat, Wazuh mailing list
Hi again Kat, the error message is saying that could be a problem with
JAVA_HOME and/or PATH variables.
In your case as I can see you have the JAVA_HOME fixed, but maybe is
not in your PATH variable. Try to add this line
to your .bashrc:

PATH=$JAVA_HOME/bin:$PATH

and refresh:

$ source /path_your_home/.bashrc

That's could be the trick Kat, Java bin directory must to bein the
PATH. In your installation I think it should be
/opt/jre1.8.0_161/bin

Best regards,
Jesús
> --
> You received this message because you are subscribed to the Google Groups
> "Wazuh mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wazuh+un...@googlegroups.com.
> To post to this group, send email to wa...@googlegroups.com.
> Visit this group at https://groups.google.com/group/wazuh.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wazuh/46de1987-d8c7-4c29-867e-1d52a3f0b2be%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Kat

unread,
Jan 23, 2018, 9:02:59 AM1/23/18
to Wazuh mailing list
Nope - not the issue. Both PATH and JAVA_HOME have always been defined. Tried in:
/etc/profile
/etc/defaults/elasticsearch
~/.bashrc

and you missed the part of not only does java -version always run, but any jar file I load works fine. Only Elasticsearch that fails.


On Monday, January 22, 2018 at 11:36:56 AM UTC-6, Kat wrote:

jesus.g...@wazuh.com

unread,
Jan 23, 2018, 9:32:45 AM1/23/18
to Wazuh mailing list
Hi Kat, it sounds stranger. This is the script that Elasticsearch runs to determine Java path when it starts:

# now set the path to java
if [ -x "$JAVA_HOME/bin/java" ]; then
  JAVA="$JAVA_HOME/bin/java"
else
  set +e
  JAVA=`which java`
  set -e
fi

if [ ! -x "$JAVA" ]; then
  echo "could not find java; set JAVA_HOME or ensure java is in PATH"
  exit 1
fi

There are two ways to get the Java path. 

- Using $JAVA_HOME variable to check if $JAVA_HOME/bin/java exists. 
- The second step if the above step fails, is to set the JAVA variable using which command.

If both fails, it will output the error message you are getting. 

Let's simulate the script behaviour manually:

1. sudo -H -u elasticsearch bash -c 'echo $JAVA_HOME/bin/java'
2. sudo -H -u elasticsearch bash -c 'which java'

Please, send us the output of the above commands, then we can keep troubleshooting.

King regards,
Jesús

Kat

unread,
Jan 23, 2018, 9:42:10 AM1/23/18
to Wazuh mailing list
Will debug later, but for now, I re-installed JAVA so it is in /usr/bin -- now everything works. Will spin up another instance to troubleshoot later.

One other interesting bit of info - I had an old instance running Elasticsearch and it was working UNTIL I did the last update for Meltdown - so there might be something related. It stopped working the same way as the fresh install - JAVA_HOME and java are not found.

At any rate, with java in a system path, it is now working.

Kat


On Monday, January 22, 2018 at 11:36:56 AM UTC-6, Kat wrote:

jesus.g...@wazuh.com

unread,
Jan 23, 2018, 10:20:28 AM1/23/18
to Wazuh mailing list
Ok Kat, I'm glad to help you. Let us know if you have any more troubles. 
Also it's interesting that you have said about Meltdown, I don't know
how much it could modify the widesystem. If you finally run another instance,
please feedback me if you face any trouble.

Have a nice day.

Best regards,
Jesús
Reply all
Reply to author
Forward
0 new messages