3
votes

I have Downloaded zookeeper-3.4.5.tar.gz and after extracting it I wrote conf/zoo.cfg as

tickTime=2000

dataDir=/var/zookeeper

clientPort=2181

Now I tried to start zookeeper by bin/zkServer.sh start it gives

mohit@mohit:~/zookeeper-3.4.5/bin$ sudo sh zkServer.sh start
[sudo] password for mohit: 
JMX enabled by default
Using config: /home/mohit/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

But

$ echo ruok | nc localhost 2181

is not giving any output.

I checked zookeeper.out, it gives

mohit@mohit:~/zookeeper-3.4.5/bin$ cat zookeeper.out 
nohup: failed to run command ‘java’: No such file or directory
mohit@mohit:~/zookeeper-3.4.5/bin$ 

But my JAVA variables are set, I am not getting why this error is coming?

mohit@mohit:~/zookeeper-3.4.5/bin$ echo $JAVA_HOME 
/usr/lib/jdk
mohit@mohit:~/zookeeper-3.4.5/bin$ echo $PATH 
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jdk/bin

please help.Thanks in advance:)

2
What is the result of java -version? - Elliott Frisch
Also, sudo sh is going to replace your environment. - Elliott Frisch
Thanks a lot @ElliottFrisch , yes sudo was changing my environment. - Mahi Singh

2 Answers

3
votes

Solution:

Sudo was changing the environment.

So I set the environment variables for root.

Thanks to Elliott Frisch.

0
votes

simply add following lines to beginning of zkServer.sh

export JAVA_HOME=/usr/lib/jdk
export PATH=$JAVA_HOME/bin:$PATH

btw1: you can make the script executable by:

 sudo chmod a+x zkServer.sh

I suppose that first line is: #!/bin/bash so you can start it by:

sudo zkServer.sh start

BTW2: it is bad practice to run java code as root if it is not rally necessary. good luck.

BTW3: are you sure that you jdk is directly in folder :/usr/jib/jdk and not in some subfolder? You can validate it by running the exports and then try: java -version