Article Directory
Problem Description
There are 4 hosts on my side, and 4 hosts have the same tomca path. I want to directly start the tomcat of 4 hosts through the pssh command tool, the command is as follows:
[root@hadoop-master pssh]# pssh -P -h hosts.text /usr/local/tomcat/apache-tomcat-8.5.57/bin/startup.sh
The exception is as follows:
Unusual problem:
hadoop-master: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
problem analysis
First check the environment variables and find that we have configured
[root@hadoop-master ~]# echo $JAVA_HOME
/usr/local/jdk/jdk1.8.0_261
It is suspected that commands are executed through pssh, and global environment variables cannot be used
Solve the problem
If you cannot set global environment variables, you only need to set the environment variables when tomcat starts. We use a host hadoop-slave1 for testing.
First, enter the bin directory of tomcat and edit
[root@hadoop-slave1 bin]# cd /usr/local/tomcat/apache-tomcat-8.5.57/bin
[root@hadoop-slave1 bin]# vim catalina.sh
Add our environment variables to the second line of the file
#!/bin/sh
export JAVA_HOME="/usr/local/jdk/jdk1.8.0_261"
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
Then wq save and exit. Then execute our pssh command:
[root@hadoop-master pssh]# pssh -P -h hosts.text /usr/local/tomcat/apache-tomcat-8.5.57/bin/startup.sh
Found that the execution was successful, log in to hadoop-slave1 to verify:
[root@hadoop-slave1 bin]# ps -ef|grep tomcat|grep -v grep
root 9820 1 0 18:13 ? 00:00:04 /usr/local/jdk/jdk1.8.0_261/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/apache-tomcat-8.5.57/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/apache-tomcat-8.5.57/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-8.5.57/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat/apache-tomcat-8.5.57 -Dcatalina.home=/usr/local/tomcat/apache-tomcat-8.5.57 -Djava.io.tmpdir=/usr/local/tomcat/apache-tomcat-8.5.57/temp org.apache.catalina.startup.Bootstrap start
Found that tomcat has started successfully. In this way, the problem can be solved by making the same modification to the tomcat of other servers.
The ultimate goal:
[root@hadoop-master pssh]# pssh -h hosts.text /usr/local/tomcat/apache-tomcat-8.5.57/bin/startup.sh
[1] 18:37:04 [SUCCESS] hadoop-slave2
[2] 18:37:04 [SUCCESS] hadoop-master
[3] 18:37:04 [SUCCESS] hadoop-slave1
[4] 18:37:04 [SUCCESS] hadoop-slave3