zookeeper Starting error :'JAVA_HOME error in zookeeper.out' - java

When I do
bin/zkServer.sh start #It shows it has started
ZooKeeper JMX enabled by default
Using config: /data/sparkHA/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
Afetr few second when i check status, I got
ZooKeeper JMX enabled by default
Using config: /data/sparkHA/zookeeper-3.4.9/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
My zookeeper.out says
nohup: failed to run command â/usr/bin/java/bin/javaâ: Not a directory
But my JAVA_HOME in bashrc is usr/bin/java, How come one extra /bin/java is added , that results in an invalid directory.
Also echo $JAVA_HOME outputs
/usr/bin/java
How to approach this error. Please Help. Thanks.
Also tried setting JAVA_HOME in zkServer.sh also by following Zookeeper not starting, nohup error but getting same error.

Your JAVA_HOME point to /usr/bin/java file but it should point to root directory of your JDK. For example for me this is:
➜ ~ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
➜ ~ ll $JAVA_HOME
total 52064
-rw-rw-r-- 1 root wheel 3.2K Oct 1 09:00 COPYRIGHT
-rw-rw-r-- 1 root wheel 40B Oct 1 09:01 LICENSE
-rw-rw-r-- 1 root wheel 159B Oct 1 09:01 README.html
-rwxrwxr-x 1 root wheel 108K Sep 22 22:49 THIRDPARTYLICENSEREADME-JAVAFX.txt
-rw-rw-r-- 1 root wheel 173K Oct 1 09:01 THIRDPARTYLICENSEREADME.txt
drwxrwxr-x 46 root wheel 1.5K Oct 1 09:04 bin
drwxrwxr-x 9 root wheel 306B Oct 1 09:00 db
drwxrwxr-x 9 root wheel 306B Oct 1 09:00 include
-rwxrwxr-x 1 root wheel 4.9M Sep 22 22:49 javafx-src.zip
drwxrwxr-x 10 root wheel 340B Oct 1 09:02 jre
drwxrwxr-x 14 root wheel 476B Oct 1 09:02 lib
drwxrwxr-x 5 root wheel 170B Oct 1 09:01 man
-rw-rw-r-- 1 root wheel 529B Oct 1 09:01 release
-rw-rw-r-- 1 root wheel 20M Oct 1 09:01 src.zip
So, try to set valid path to JDK root directory. I think it should fix your problem.

Related

Keep link to /etc/alternatives/jre when switching java

I have 2 java on my server, where I installed java8 first, then java 11
by default, there is no jre -> /etc/alternatives/jre
[root#server-1:jvm]# ls -all
...
lrwxrwxrwx 1 root root 26 Mar 17 09:10 java -> /etc/alternatives/java_sdk
drwxr-xr-x 9 root root 215 Mar 17 09:10 java-11-amazon-corretto
drwxr-xr-x 3 root root 17 Mar 17 07:17 java-1.8.0-amazon-corretto.x86_64
While after I set the default java with alternative command, the link to /etc/alternatives/jre is created automatically
[root#server-1:jvm]# alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
+ 1 /usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64/jre/bin/java
* 2 /usr/lib/jvm/java-11-amazon-corretto/bin/java
Enter to keep the current selection[+], or type selection number: 2
[root#server-1:jvm]# ls -all
...
lrwxrwxrwx 1 root root 26 Mar 17 09:10 java -> /etc/alternatives/java_sdk
drwxr-xr-x 9 root root 215 Mar 17 09:10 java-11-amazon-corretto
drwxr-xr-x 3 root root 17 Mar 17 07:17 java-1.8.0-amazon-corretto.x86_64
lrwxrwxrwx 1 root root 21 Mar 17 09:21 jre -> /etc/alternatives/jre <<<<< i want to keep this
But once I switch back to java8, the jre -> /etc/alternatives/jre was removed.
How can I keep the link?
UPDATE: example problem what to be solved
A application have to access the cacert file in java, e.g.
***/usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64/jre***/lib/security/cacerts
***/usr/lib/jvm/java-11-amazon-corretto.x86_64***/lib/security/cacerts
So I would like to have the /usr/lib/jvm/jre or /etc/alternatives/jre pointing to the java home
In case of corretto8
/usr/lib/jvm/jre -> /etc/alternatives/jre -> /usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64/jre
In case of corretto11 (which the 'alternative' already did if I switch to )
/usr/lib/jvm/jre -> /etc/alternatives/jre -> /usr/lib/jvm/java-11-amazon-corretto.x86_64

Can't startup Tomcat

I'm just trying to setup a tomcat server. I got the following setting:
Tomcat 9 installation inside: /opt/apache-tomcat-9.0.0.M1
WebAppliction located at: /srv/appsiting-dev/
Structure of the WebApplication:
drwxrwsr-x 2 root appsiting 4096 Jan 15 20:08 bin
drwxrws--- 2 root appsiting 4096 Jan 16 18:52 doc
drwxrwsr-x 2 root www-data 4096 Jan 16 19:48 etc
drwxr-xr-x 2 root root 4096 Jan 15 19:56 log
drwxrwsr-x 2 root appsiting 4096 Jan 15 19:56 php-lib
drwxrwsr-x 2 root appsiting 4096 Jan 16 02:38 public_html
drwxrwxrwt 2 root root 4096 Jan 15 19:57 tmp
drwxrwsr-x 7 root root 4096 Jan 16 00:45 tomcat
drwxrwsr-x 3 root appsiting 4096 Jan 15 21:30 var
drwxrwsr-x 2 root appsiting 4096 Jan 15 19:57 zend-app
Inside the tomcat directory there is the following:
drwxrwsr-x 3 appsiting appsiting 4096 Jan 16 20:25 conf
drwxrws--- 2 appsiting appsiting 4096 Jan 16 20:07 logs
drwxrwsr-x 2 appsiting appsiting 4096 Jan 16 20:20 temp
-rwxr-xr-x 1 root root 3015 Jan 16 00:45 tomcat
drwxrwsr-x 7 appsiting appsiting 4096 Jan 15 23:32 webapps
drwxrwsr-x 2 appsiting appsiting 4096 Jan 15 23:32 work
tomcatis a start-up script. I got the following inside of my tomcat.conf, which is located inside of conf
USERNAME="appsiting"
PORTBASE="40000"
JAVA_OPTS="$JAVA_OPTS -Xmx1024m -XX:MaxPermSize=256m"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=$(($PORTBASE+2))"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
JAVA_OPTS="$JAVA_OPTS -XX:+CMSClassUnloadingEnabled"
#JAVA_OPTS="$JAVA_OPTS -XX:+CMSPermGenSweepingEnabled"
#JAVA_OPTS="$JAVA_OPTS -verbose:gc -XX:+PrintClassHistogram"
JAVA_OPTS="$JAVA_OPTS -server"
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
export JAVA_OPTS
export JAVA_HOME="/usr"
export CATALINA_HOME="/opt/apache-tomcat-9.0.0.M1"
export CATALINA_BASE="/srv/appsiting-dev/tomcat"
So when I startup my server I get a tomcat.err and a catalina.out. And even though the tomcat.errtells me the Tomcat has started, catalina.out doesn't have a "Server starup in xx ms" inside of it.
tomcat.err
Using CATALINA_BASE: /srv/appsiting-dev/tomcat
Using CATALINA_HOME: /opt/apache-tomcat-9.0.0.M1
Using CATALINA_TMPDIR: /srv/appsiting-dev/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat- 9.0.0.M1/bin/bootstrap.jar:/opt/apache-tomcat-9.0.0.M1/bin/tomcat-juli.jar
Using CATALINA_PID: /srv/appsiting-dev/tomcat/temp/tomcat.pid
Tomcat started.
catalina.out is empty. Here is the start up script as well:
https://www.refheap.com/113725
When running it I'm getting a
sudo ./tomcat start
Starting Tomcat (appsiting-dev) ............................... failed.
Does anyone know what the issue is here?
Thanks in advance
local host port is already using in other service or process.find and kill(stop) it.

Fixed Rest Endpoints

I have a war file deployed on tomcat ( /var/lib/tomcat7/webapps folder ), say, rest-api-webapp-0.0.1.war
To access the rest endpoint check, exposed in this war, I use curl in the format
curl -X POST -H "Content-Type:application/x-www-form-urlencoded" -d "remarks=Tester" https://localhost:8080/rest-api-webapp-0.0.1/check The problem I face is, whenever I up the patch/major/minor versions of my webapp, I need to change the curl appropriately (say the version is now 0.1.4, then the curl must change as curl -X POST -H "Content-Type:application/x-www-form-urlencoded" -d "remarks=Tester" https://localhost:8080/rest-api-webapp-0.1.4/check. I donot wish to change the way the client calls the endpoint (because it requires the client to upgrade their app, which they resent and see as high maintenance) Can this be avoided by doing something like this
Create a symbolic link as below ln -s rest-api-webapp-0.0.1.war rest-api inside the /var/log/tomcat7/webapps folder so that whennever I up the version, I just change the symlink to point to the new version and the client need not do anything to use the new version of the api. In effect, I need the api endpoint to be fixed and not change as and when I up the versions on the server. For Ex: I need the endpoint to be fixed as https:gva.atr.in/colouring-api/check and whenever I have a major change in the controllers and all that I need to do is just update the symlink and not change the endpoint. If you find that this approach is flawed, please show me the right direction as I have been trying to read about this from the past 2 days, but found very less articles that address my problem.
I read the tomcat documentation and realised that I need to create a symbolic link to the war file and give the symbolic file the war extension. So If this is what you have in your tomcat webapps directory
/var/lib/tomcat7/webapps user1$ ls
drwxr-xr-x 11 user1 wheel 374 Oct 19 21:52 .
drwxr-xr-x 9 user1 admin 306 Oct 19 19:36 ..
drwxr-xr-x 19 user1 wheel 646 Aug 29 20:19 ROOT
drwxr-xr-x 55 user1 wheel 1870 Aug 29 20:19 docs
drwxr-xr-x 4 user1 wheel 136 Oct 19 19:46 rest-api-webapp-0.2.1
-rw-r--r-- 1 user1 wheel 48258097 Oct 19 19:46 rest-api-webapp-0.2.1.war
drwxr-xr-x 7 user1 wheel 238 Aug 29 20:19 host-manager
drwxr-xr-x 8 user1 wheel 272 Aug 29 20:19 manager
Do this,
ln -s rest-api-webapp-0.2.1.war rest-api.war So that the directory looks like this (Wait for sometime for the tomcat engine to deploy the new war)
drwxr-xr-x 11 user1 wheel 374 Oct 19 21:52 .
drwxr-xr-x 9 user1 admin 306 Oct 19 19:36 ..
drwxr-xr-x 19 user1 wheel 646 Aug 29 20:19 ROOT
drwxr-xr-x 4 user1 wheel 136 Oct 19 21:52 rest-api
drwxr-xr-x 4 user1 wheel 136 Oct 19 19:46 rest-api-webapp-0.2.1
-rw-r--r-- 1 user1 wheel 48258097 Oct 19 19:46 rest-api-webapp-0.2.1.war
lrwxr-xr-x 1 user1 wheel 25 Oct 19 21:51 rest-api.war -> rest-api-webapp-0.2.1.war
drwxr-xr-x 7 user1 wheel 238 Aug 29 20:19 host-manager
drwxr-xr-x 8 user1 wheel 272 Aug 29 20:19 manager If needed restart your tomcat and you can use the curl command like this curl -X POST -H "Content-Type:application/x-www-form-urlencoded" -d "remarks=Tester" https://localhost:8080/rest-api/check totally not bothering about the major, minor, patch versions. All that you need to do once you have a new version is unlink rest-apiln -s rest-api-webapp-X.Y.Z.war rest-api.war

JConsole location in Linux

I am trying to run jconsole from my machine but I can't find the location of the .sh . I have tried finding it in different directories and setting JAVA_HOME to the jdk.
$which java
/usr/bin/java
$java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (rhel-2.4.4.1.el6_5-x86_64 u51-b02)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
$whereis java
java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java /usr/share/man/man1/java.1.gz
I looked in /usr/lib/jvm and I found
drwxr-xr-x. 3 root root 4096 Apr 23 2013 java-1.5.0-gcj-1.5.0.0
drwxr-xr-x. 3 root root 4096 Jan 27 2014 java-1.6.0-openjdk-1.6.0.0.x86_64
drwxr-xr-x. 3 root root 4096 Feb 5 2014 java-1.7.0-openjdk-1.7.0.51.x86_64
lrwxrwxrwx. 1 root root 21 Feb 5 2014 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 27 Apr 23 2013 jre-1.5.0 -> /etc/alternatives/jre_1.5.0
lrwxrwxrwx. 1 root root 26 Apr 23 2013 jre-1.5.0-gcj -> java-1.5.0-gcj-1.5.0.0/jre
lrwxrwxrwx. 1 root root 27 Feb 5 2014 jre-1.6.0 -> /etc/alternatives/jre_1.6.0
lrwxrwxrwx. 1 root root 37 Feb 5 2014 jre-1.6.0-openjdk.x86_64 -> java-1.6.0-openjdk- 1.6.0.0.x86_64/jre
lrwxrwxrwx. 1 root root 27 Feb 5 2014 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx. 1 root root 38 Feb 5 2014 jre-1.7.0-openjdk.x86_64 -> java-1.7.0-openjdk-1.7.0.51.x86_64/jre
lrwxrwxrwx. 1 root root 25 Apr 23 2013 jre-gcj -> /etc/alternatives/jre_gcj
lrwxrwxrwx. 1 root root 29 Feb 5 2014 jre-openjdk -> /etc/alternatives/jre_openjdk
and in java-1.7.0-openjdk-1.7.0.51.x86_64/jre/bin/, I only found
[root#portal01 bin]# ll
total 200
-rwxr-xr-x. 1 root root 9536 Jan 14 2014 java
-rwxr-xr-x. 1 root root 9656 Jan 14 2014 keytool
-rwxr-xr-x. 1 root root 9856 Jan 14 2014 orbd
-rwxr-xr-x. 1 root root 9688 Jan 14 2014 pack200
-rwxr-xr-x. 1 root root 10984 Jan 14 2014 policytool
-rwxr-xr-x. 1 root root 9648 Jan 14 2014 rmid
-rwxr-xr-x. 1 root root 9656 Jan 14 2014 rmiregistry
-rwxr-xr-x. 1 root root 9688 Jan 14 2014 servertool
-rwxr-xr-x. 1 root root 9896 Jan 14 2014 tnameserv
-rwxr-xr-x. 1 root root 92264 Jan 14 2014 unpack200
..even though there are 200 files. How can I find and run jconsole?
jconsole is part of the Java SDK, it appears you only have the JRE installed.
You can run jconsole directly from your terminal by running the command jconsole.
reena#IM-1500:~$ jconsole
It will launch java monitoring console dialog.
From https://serverfault.com/questions/179908/fedora-jconsole-location:
Try running: yum provides */jconsole
that will tell you what package you need as well as where it's located in the package.
Once you set the path of JDK in Linux then this command execute easily might be you had not included the JAVA_HOME with PATH variable.
plz follow this discussion
If you have Java JDK installed in your Linux machine, usually jconsole is located at /usr/bin/ as a symbolic link.
Example from my Linux VM running Centos6
$ which jconsole
/usr/bin/jconsole
$ ls -l /usr/bin/jconsole
lrwxrwxrwx. 1 root root 26 Sep 4 10:05 /usr/bin/jconsole -> /etc/alternatives/jconsole
$ ls -l /etc/alternatives/jconsole
lrwxrwxrwx. 1 root root 51 Sep 4 10:05 /etc/alternatives/jconsole -> /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/jconsole
But you mentioned you got the a command not found error when you typed jconsole at the prompt. Can you find if jconsole is available in one of the jdk's bin directory?
$ ls -l /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin | grep jconsole
If yes, then add this in your PATH environment variable like so
$ export PATH=$PATH:/usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin
or put this in your ~/.bashrc if you are using Bash.
If jconsole is not there, then maybe you need to try another jdk which you have installed or re-install the jdk.
Please install JDK Development Package to get Jconsole

How to add timestamp to the log file name when we are using size based log files in log4j?

I want to create size based log files. I am setting the following entry in the log4j.properties file:
log4j.appender.UserFileAppenderDebug=org.apache.log4j.RollingFileAppender
log4j.appender.UserFileAppenderDebug.Threshold=TRACE
log4j.appender.UserFileAppenderDebug.File=../log/coordinator-debug.log
log4j.appender.UserFileAppenderDebug.MaxFileSize=1KB
log4j.appender.UserFileAppenderDebug.MaxBackupIndex=7
log4j.appender.UserFileAppenderDebug.layout=org.apache.log4j.PatternLayout
log4j.appender.UserFileAppenderDebug.layout.ConversionPattern=%m%n
multiple log files are created based on size but with following names:
-rw-r--r-- 1 root root 32 Aug 6 11:28 coordinator-debug.log
-rw-r--r-- 1 root root 1.1K Aug 6 11:28 coordinator-debug.log.1
-rw-r--r-- 1 root root 1.1K Aug 6 11:28 coordinator-debug.log.2
-rw-r--r-- 1 root root 1.2K Aug 6 11:28 coordinator-debug.log.3
-rw-r--r-- 1 root root 1.1K Aug 6 11:28 coordinator-debug.log.4
-rw-r--r-- 1 root root 1.1K Aug 6 11:28 coordinator-debug.log.5
-rw-r--r-- 1 root root 1.1K Aug 6 11:28 coordinator-debug.log.6
-rw-r--r-- 1 root root 1.1K Aug 6 11:28 coordinator-debug.log.7
I would like to have the file name as follows
coordinator-debug.log.2013-08-01 11:28:39, 232
I would appreciate if you please share your comments/suggestions.
Thanks.
Have you tried:
log4j.appender.UserFileAppenderDebug.DatePattern='.'yyyy-MM-dd_HH-mm-ss
(remember that your filename will not allow : e.g 11:28:39, you will need to replace them to e.g. 11-28-39 )
(edited)
Sorry, I thought you used the *Daily*RollingFileAppender...
There are RollingPolicys that you might use to get filename pattern for the RollingFileAppender.
E.g.
log4j.appender.UserFileAppenderDebug.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.UserFileAppenderDebug.RollingPolicy.FileNamePattern=../log/coordinator-debug.log.%d{yyyy-MM-dd-HH-mm-ss}

Categories