Skip to content

Instantly share code, notes, and snippets.

@edwardbeckett
Last active September 5, 2017 14:25
Show Gist options
  • Save edwardbeckett/0d2987647c86eef0344e to your computer and use it in GitHub Desktop.
Save edwardbeckett/0d2987647c86eef0344e to your computer and use it in GitHub Desktop.
Tomcat 8 on Java 8 Behind Apache on CentOS
Tomcat 8 on Java 8 Behind Apache on CentOS
/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
service httpd restart
cd /usr/local/apache/conf/userdata/std/2 && mkdir user1/domain1.com && mkdir user2/domain2.com
/usr/local/apache/conf/userdata/std/2/user1/domain1.com/tomcat.conf
/usr/local/apache/conf/userdata/std/2/user2/domain2.com/tomcat.conf
INFO: Loaded APR based Apache Tomcat Native library 1.1.33 using APR version 1.2.7.
ls /usr/local/apr/lib
httpd -M | grep -i 'proxy'
cat /etc/passwd | grep tomcat
md5sum apache-tomcat-8.0.21.tar.gz
chmod +x /etc/init.d/tomcat_1 && chmod +x /etc/init.d/tomcat_2
chkconfig --add tomcat_1 && chkconfig --add tomcat_2
chkconfig --level 2345 tomcat_1 on && chkconfig --level 2345 tomcat_2 on
chown tomcat.tomcat /opt/tomcat/tomcat_1/bin/setenv.sh && chmod +x /opt/tomcat/tomcat_1/bin/setenv.sh
chown tomcat.tomcat /opt/tomcat/tomcat_2/bin/setenv.sh && chmod +x /opt/tomcat/tomcat_2/bin/setenv.sh
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
export JAVA_HOME=/usr/local/jdk
cd /opt/tomcat/bin && ./configtest.sh
cd /usr/local/apache/conf/userdata/std/2/user1/domain1.com && touch tomcat.conf && vim tomcat.conf
cd /usr/local/apache/conf/userdata/std/2/user2/domain2.com && touch tomcat.conf && vim tomcat.conf
ProxyRequests off
ProxyPreserveHost on
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / ajp://domain1.com:8009/
ProxyPassReverse / ajp://domain1.com:8009/
ProxyRequests off
ProxyPreserveHost on
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / ajp://domain2.com:8010/
ProxyPassReverse / ajp://domain2.com:8010/
cd /opt/tomcat/bin && tar xvzf tomcat-native.tar.gz
tar xvzf apache-tomcat-8.0.21.tar.gz
ln -s /opt/apache-tomcat-8.0.21 tomcat
cd /opt && wget http://www.us.apache.org/dist/tomcat/tomcat-8/v8.0.21/bin/apache-tomcat-8.0.21.tar.gz
ls -l | grep jdk
update-alternatives --install /usr/bin/java java /usr/local/jdk/bin/java 1
update-alternatives --install /usr/bin/javac javac /usr/local/jdk/bin/javac 1
update-alternatives --install /usr/bin/javaws javaws /usr/local/jdk/bin/javaws 1
cd /usr/local/ && wget --no-check-certificate -c \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.tar.gz
yum install -y apr-devel openssl-devel
ls -l /opt/tomcat
./configure --with-apr=/usr/local/apr \
--with-java-home=/usr/local/jdk \
--with-ssl=yes \
--prefix=/opt/tomcat
make && make install
...
proxy_module (static)
proxy_ajp_module (static)
...
mv jdk-8u45-linux-x64.tar.gz\?AuthParam\=1429150407_03533c0686909067456bf8c408ad56c9 jdk-8u45-linux-x64.tar.gz
#!/bin/sh
# Edit this file to set custom options
#
# Notes:
#
# * Tomcat accepts the JAVA_OPTS and CATALINA_OPTS parameters
# * JAVA_OPTS are used during START/STOP/RUN
# Edit this file to set custom options
# Edit this file to set custom options
#
# Notes:
#
# * Tomcat accepts the JAVA_OPTS and CATALINA_OPTS parameters
# * JAVA_OPTS are used during START/STOP/RUN
# * CATALINA_OPTS are used during START/RUN
# * This script is sourced by catalina.sh when it placed inside
# * $CATALINA_BASE/bin (instance specify setup) or $CATALINA_HOME/bin directories.
# ------------------------------------------------------------
JAVA_HOME="/usr/local/jdk"
CATALINA_HOME="/opt/tomcat"
CATALINA_BASE="/opt/tomcat/tomcat_1"
CATALINA_PID="$CATALINA_BASE/temp/tomcat_1.pid"
#################################
# *** JAVA OPTIONS SETTINGS *** #
#################################
JVM_MODE="-server"
HEADLESS_MODE="-Djava.awt.headless=true"
BIT_MODE="-d64"
HEAP_OPTS="-Xms128m -Xmx768m"
GC_OPTS="-XX:+AlwaysPreTouch -XX:+AggressiveOpts -XX:+UseG1GC -XX:ReservedCodeCacheSize=256m -XX:+UseCompressedOops -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -Djsse.enableSNIExtension=false -XX:SoftRefLRUPolicyMSPerMB=50"
#
# Example:
# conf/jmxremote.access
# john readwrite
# conf/jmxremote.password
# john johnpasswd
# Make sure both jmxremote.{access,passsword} files only readable/writeable (600) by the owner, and
# jxmremote.port must be unique for each server instance.
#
#JMXREMOTE_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false
#-Dcom.sun.management.jmxremote.authenticate=true -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.password.file
#=$CATALINA_BASE/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
JAVA_OPTS="$JVM_MODE $HEADLESS_MODE $BIT_MODE $HEAP_OPTS $GC_OPTS"
Usage: /etc/init.d/tomcat_1 {start|stop|kill|status|restart}
service tomcat_1
service tomcat_1 start && service tomcat_2 start && service httpd restart
tar xvzf jdk-8u45-linux-x64.tar.gz
ln -s /opt/apache-tomcat-8.0.21 tomcat
cd /opt/tomcat/tomcat_2/conf && vim server.xml
cd /opt/tomcat/tomcat_1/conf && vim server.xml
cd /opt/tomcat && mkdir tomcat_1 tomcat_2
cp -R bin conf logs temp webapps work tomcat_1
cp -R bin conf logs temp webapps work tomcat_2
rm -rf conf logs temp webapps work
cd /opt/tomcat/bin/tomcat-native-1.1.33-src/jni
groupadd tomcat
useradd -g tomcat -s /usr/sbin/nologin -m -d /opt/tomcat tomcat
chown -R tomcat.tomcat /opt/tomcat
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-
status,admin-gui,admin-script"/>
#!/bin/bash
# chkconfig: 2345 20 80
# description: Tomcat 8 start/stop/status init.d script
JAVA_HOME=/usr/local/jdk
export JAVA_HOME
#Add Java binary files to PATH
PATH=$JAVA_HOME/bin:$PATH
export PATH
#CATALINA_HOME is the location of the bin files of Tomcat
CATALINA_HOME=/opt/tomcat
export CATALINA_HOME
#CATALINA_BASE is the location of the configuration files of this instance of Tomcat
CATALINA_BASE=$CATALINA_HOME/tomcat_1
export CATALINA_BASE
#CATALINA_PID is the Tomcat instance process ID.
CATALINA_PID="$CATALINA_BASE/temp/tomcat_1.pid"
export CATALINA_PID
#TOMCAT_USER is the default user of tomcat
TOMCAT_USER=tomcat
export TOMCAT_USER
#TOMCAT_USAGE is the message if this script is called without any options
TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;31mkill\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"
#SHUTDOWN_WAIT is wait time in seconds for java proccess to stop
SHUTDOWN_WAIT=20
tomcat_pid() {
echo `ps -fe | grep $CATALINA_BASE | grep -v grep | tr -s " "|cut -d" " -f2`
}
#USER LEVEL CHECK
if [[ $EUID -ne 0 ]]; then
echo "`basename $0` requires root privileges." 1>&2
exit 1
fi
start() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m"
else
# Start tomcat
echo -e "\e[00;32mStarting tomcat\e[00m"
if [ `user_exists $TOMCAT_USER` = "1" ]
then
/bin/su - $TOMCAT_USER -s /bin/bash -c $CATALINA_BASE/bin/startup.sh
else
sh $CATALINA_BASE/bin/startup.sh
fi
status
fi
return 0
}
status(){
pid=$(tomcat_pid)
if [ -n "$pid" ]; then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
else echo -e "\e[00;31mTomcat is not running\e[00m"
fi
}
terminate() {
echo -e "\e[00;31mTerminating Tomcat\e[00m"
kill -9 $(tomcat_pid)
}
stop() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo -e "\e[00;31mStoping Tomcat\e[00m"
sh $CATALINA_BASE/bin/shutdown.sh
let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\n\e[00;31mwaiting for processes to exit\e[00m";
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
echo -n -e "\n\e[00;31mkilling processes didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
terminate
fi
else
echo -e "\e[00;31mTomcat is not running\e[00m"
fi
return 0
}
user_exists(){
if id -u $1 >/dev/null 2>&1; then
echo "1"
else
echo "0"
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
kill)
terminate
;;
*)
echo -e $TOMCAT_USAGE
;;
esac
exit 0
update-alternatives --display java
update-alternatives --display javac
update-alternatives --display javaws
java -version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment