Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the version of Java that CDH uses

I currently have CDH 5 installed on CentOS 6.5 with java jdk1.7 and I am trying to get CDH to use jdk1.8.

I do know that Java 1.8 is not a recommended version of CDH, but it is only a test cluster, so it isn't a big deal.

I have installed both Java 1.7 and Java 1.8 from Oracle's website using the RPM installation, so both versions of Java are currently under /usr/java. Using ls -ld my Java directory looks like:

/usr/java/default -> /usr/java/latest
/usr/java/jdk1.7.0_75
/usr/java/jdk1.8.0_31
/usr/java/latest -> /usr/java/jdk1.8.0_31

I also have script set up in /etc/profile.d to set $JAVA_HOME to /usr/java/default. The contents of my profile.d script:

export JAVA_HOME=/usr/java/default
export PATH=${JAVA_HOME}/bin:${PATH}

So when felt that I have this right, I run:

$ which java
/usr/java/default/bin/java

Telling me that it is pointing to the version of Java symlinked in default. And to determine which version of java is running, I run:

$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

And I can see that I have Java 1.8 currently running.

Everything seems great, except when I try to start a Hadoop service. The easiest to start is ZooKeeper, because it only has one service. HDFS has multiple servers so it is more work that to just start and stop ZooKeeper.

Starting ZooKeeper is done with the following command:

$ sudo service zookeeper-server start

Then to check which version of java it is running, I search the running processes list for java:

$ ps -ef | grep java
495       7170     1  7 12:27 ?        00:00:00 /usr/java/jdk1.7.0_75/bin/java -Dzookeeper.datadir.autocreate=false -Dzookeeper.log.dir=/var/log/zookeeper -Dzookeeper.root.logger=INFO,ROLLINGFILE -cp /usr/lib/zookeeper/bin/../build/classes:/usr/lib/zookeeper/bin/../build/lib/*.jar:/usr/lib/zookeeper/bin/../lib/slf4j-log4j12.jar:/usr/lib/zookeeper/bin/../lib/slf4j-log4j12-1.7.5.jar:/usr/lib/zookeeper/bin/../lib/slf4j-api-1.7.5.jar:/usr/lib/zookeeper/bin/../lib/netty-3.2.2.Final.jar:/usr/lib/zookeeper/bin/../lib/log4j-1.2.16.jar:/usr/lib/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/lib/zookeeper/bin/../zookeeper-3.4.5-cdh5.3.0.jar:/usr/lib/zookeeper/bin/../src/java/lib/*.jar:/etc/zookeeper/conf::/etc/zookeeper/conf:/usr/lib/zookeeper/*:/usr/lib/zookeeper/lib/* -Dzookeeper.log.threshold=INFO -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /etc/zookeeper/conf/zoo.cfg

I know that runs off the screen, bu the important part is that Zookeeper is being started by /usr/java/jdk1.7.0_75/bin/java.

To fix this, I have tried a few things:

  1. Looking at the conf files for Hadoop and ZooKeeper under /etc/hadoop/conf and /etc/zookeeper/conf, respectively.

    I found nothing setting JAVA_HOME.

  2. Looking at the /usr/bin/zookeeper script to see if JAVA_HOME was set elsewhere,

    I did find the script /usr/lib/bigtop-utils/bigtop-detect-javahome has the ability to set JAVA_HOME, but my profile.d script overrides that.

  3. Manually moving /usr/java/jdk1.7 to /tmp.

    Sadly, this is the only thing that works. When I move the jdk1.7 dir to another directory, and start ZooKeeper, it will use Java 1.8. Moving the jdk1.7 dir back, reverts to ZooKeeper using Java 1.7.

Has anyone dealt with this problem and does anyone know how to deal with this? I feel that I have Java set up correctly, but something is telling ZooKeeper/Hadoop to use an old version of Java?

like image 296
milk3422 Avatar asked Mar 04 '15 12:03

milk3422


People also ask

How do I switch between versions of Java?

In the Java Control Panel, click on the Java tab. Verify that the latest Java Runtime version is enabled by checking the Enabled box. Click OK in Java Control Panel window to confirm changes and close the window. Try to run same applet and verify it is now running using latest version of Java installed in your system.


2 Answers

I came here because I was looking for ways to upgrade JDK from 1.7 to 1.8 on the latest Coudera QuickStart VM 5.8 (can't believe they still ship it with JDK1.7 by default!). The hints and suggestions in the above answers helped tremendously - but since they were not listing complete steps to achieve the upgrade - I thought I would add that to help others like me.

So, here is a complete set of steps to upgrade Cloudera QuickStart VM from JDK1.7 to 1.8:

  • check your current JDK version - out-of-the-box it is:

    [cloudera@quickstart ~]$ java -version
    java version "1.7.0_67"
    Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
    Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
    
  • download desired version of JDK1.8.xx - in my case: jdk-8u111-linux-x64.tar.gz

as user 'cloudera':

  • untar and move the resulting jdk1.8.0_111 dir to the /usr/java dir:

    tar xzf jdk-8u111-linux-x64.tar.gz    
    sudo mv -f jdk1.8.0_111 /usr/java
    
  • shutdown all Hadoop services:

    $ for x in `cd /etc/init.d ; ls hadoop-*` ; do sudo service $x stop ; done
    
  • update bigtop-utils file - set JAVA_HOME to your new JDK:

     sudo vi /etc/default/bigtop-utils
    
     updated lines:
     # Override JAVA_HOME detection for all bigtop packages
     export JAVA_HOME=/usr/java/jdk1.8.0_111
    
  • update 'cloudera' user's .bash_profile - export JAVA_HOME and add update PATH:

    export JAVA_HOME=/usr/java/jdk1.8.0_111
    PATH=$JAVA_HOME/bin:$PATH:$HOME/bin
    export PATH
    
  • restart your VM

  • check Java version - should be the 1.8 one now:

    [cloudera@quickstart ~]$ java -version
    java version "1.8.0_111"
    Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
    Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
    

By the way, I did not setup the /usr/java/default with the 'latest' sym link as @milk3422 did, for the sake of simplicity, but it would have worked just as well.

thanks!

like image 160
Marina Avatar answered Oct 29 '22 10:10

Marina


I hate to answer my own questions, but here is the answer:

The wrong version of $JAVA_HOME is getting set for 2 reasons:

  1. Using the command service removes most environmental variables. From man service:

    service  runs a System V init script in as predictable environment as 
    possible, removing most environment variables and with current work-
    ing directory set to /.
    
  2. The /usr/lib/bigtop-utils/bigtop-detect-javahome script has the ability to be configured with the environment variable BIGTOP_JAVA_MAJOR to manually set which version of Java to use. I tried setting this as an environment variable, but service removes it :(. It is also important to note that this script will find all versions of java installed, but the order of preference is Java 6, Java 7, Java 8, Open Java. So if you have Java 6, and 8 installed, it will prefer 6 over 8.

In short, to fix my problem, I added the following to the top of /usr/lib/bigtop-utils/bigtop-detect-javahome:

BIGTOP_JAVA_MAJOR=8

You can also set JAVA_HOME in this file to specify a specific version or path.

like image 33
milk3422 Avatar answered Oct 29 '22 10:10

milk3422