Tomcat: Difference between revisions
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
{{merge|[[Training:Tomcat]]}} | |||
{{besteffort}} | |||
= What is Tomcat = | |||
Tomcat is the open source implementation of the Java servlet, released under an Apache license. It allows for easy and rapid deployment of Java servlets, typically packaged as "war" files, which contain all of the directories and code necessary to run the application. | Tomcat is the open source implementation of the Java servlet, released under an Apache license. It allows for easy and rapid deployment of Java servlets, typically packaged as "war" files, which contain all of the directories and code necessary to run the application. | ||
Tomcat can run as a standalone webserver, handling all requests for HTTP content, or it can be behind more traditional web servers such as Apache, and only used to serve the dynamic content for which the Java servlet or JavaServer Pages (JSP) are needed. | Tomcat can run as a standalone webserver, handling all requests for HTTP content, or it can be behind more traditional web servers such as Apache, and only used to serve the dynamic content for which the Java servlet or JavaServer Pages (JSP) are needed. | ||
= Windows = | |||
== Plesk-Managed == | |||
Tomcat is integrated with Plesk on Plesk-managed servers, but the customer must have the Plesk Power Pack licensed (+$10/month) in order to actually use Tomcat. This means there is little to nothing that should be manually configured outside of Plesk. | |||
For troubleshooting steps check [[Plesk_TomCat_Fixes]] | |||
== Core-Managed == | |||
There are two primary functions that Liquid Web will support on core-managed server regarding Tomcat: | |||
=== Installation === | |||
This is as simply as downloading the "Windows Service Installer" package from [http://tomcat.apache.org/ here], for whatever version of Tomcat the customer would like, and running it. This will result in a very basic installation. The customer is responsible for setting up their sites. | |||
=== SSL === | |||
Along with ordering a certificate for the customer, we can also install the certificate into Tomcat. Full documentation for this is available [http://tomcat.apache.org/tomcat-7.0-doc/apr.html here], but below is a sample SSL connector. This entry would be added to ''${catalina.base}/conf/server.xml'' with appropriate SSLCertificate values: | |||
<Connector port="443" maxHttpHeaderSize="8192" | |||
maxThreads="150" minSpareThreads="25" maxSpareThreads="75" | |||
enableLookups="false" disableUploadTimeout="true" | |||
acceptCount="100" scheme="https" secure="true" | |||
SSLEngine="on" | |||
SSLCertificateFile="${catalina.base}/conf/certificate.crt" | |||
SSLCertificateKeyFile="${catalina.base}/conf/certificate.key" | |||
SSLCACertificateFile="${catalina.base}/conf/ca.bundle.crt" /> | |||
You will very likely need to download the APR/OpenSSL binaries in order to use a PEM-format SSL with Tomcat. This can be downloaded [http://apache.mirrorcatalogs.com/tomcat/tomcat-connectors/native/ here] (version > binaries > tomcat-native-[version]-win32-bin.zip). Extract ''bin\openssl.exe'' and ''bin\tcnative-1.dll'' or ''bin\x64\tcnative-1.dll'' the 64-bit DLL goes in %windir%\system32 the 32-bit DLL goes in %windir%\syswow64. | |||
'''Alternate''' | |||
edit the server XML to read: | |||
<Connector port="443" protocol="HTTP/1.1" | |||
maxThreads="200" scheme="https" secure="true" | |||
SSLEnabled="true" | |||
keystoreType="PKCS12" | |||
keystoreFile="${catalina.base}/conf/pass1.keystore" | |||
keystorePass="password" | |||
clientAuth="false" SSLProtocol="TLS"/> | |||
and create the pass1.keystore using open SSL with this command: | |||
openssl pkcs12 -export -in <certificate>.crt -inkey <key>.key -out C:\pass1.keystore -name tomcat -CAfile <bundle>.cer -caname root -chain | |||
where: | |||
*path to certificate = The actual Certificate | |||
*key = The certificate private key | |||
*bundle = Globalsign's root bundle followed bu Globalsigns intermediate bundle as shown [https://support.globalsign.com/customer/portal/articles/1224583-root-intermediate-certificate-bundles here] | |||
RESTART TOMCAT! | |||
== Configuration == | |||
=== MySQL/JDBC Driver === | |||
# Download the driver from [http://dev.mysql.com/downloads/connector/j/ here] | |||
# Extract ''mysql-connector-java-[version]-bin.jar'' from the downloaded archive to ''%plesk_dir%\Additional\JDK\jre[version]\lib\ext\'' | |||
# Restart Tomcat | |||
= Linux = | |||
{{Box Warning| Stop HAMMERTIME. Don't read further. Check the firewall and make sure port 8080 is opened. Thank you. }} | |||
{{Box Notice| cPanel discontinued support for Tomcat 5.5 through EasyApache. cPanel now supports Tomcat 7 through EA, but its location has changed to | |||
/usr/local/easy/etc/easy-tomcat7/ and /var/lib/easy-tomcat7/webapps/ and logs are now in /var/log/easy-tomcat7/}} | |||
Tomcat Can be installed through an EasyApache rebuild. | |||
Cpanel has a good intro to tomcat article here for both versions 5.5 and 7.0 : http://docs.cpanel.net/twiki/bin/view/EasyApache/Tomcat/TomcatIntroduction | |||
[https://wiki.int.liquidweb.com/images/1/10/Tomcat.pdf cpanel tomcat infos] | |||
Tomcat listens on port 8080. | |||
Apache listens on port 80. | |||
mod_jk.so is an apache module that passes all jsp/servlet requests to tomcat. | |||
Jsp stands for java server pages. A typical JSP page is similar to that of PHP except that jsp | |||
is invoked via <%-- --%> instead of the typical <? ?> php tags, and uses the java compiler instead of | |||
the php interpreter. | |||
A servlet is a collection of java classes used to create web applications. Think of it as a package. Standard web | |||
applications come packaged in *.war files (web application archive). A simple WAR file is simply a compressed (zipped) | |||
package consisting of jsp files, classes, and a web.xml file. The web.xml file is used to designate custom classes/servlets | |||
to be included in the web application and is to be configured by the programmer. | |||
The mod_jk apache module is configured via JkMount directives designated in httpd.conf. Arguments to the JkMount directive | |||
specify which file types are to be passed to the tomcat server. JkMount also designates paths to where a specific servlet | |||
is located. | |||
eg.. | |||
<IfModule mod_jk.c> | |||
JkMount /*.jsp ajp13 | |||
</IfModule> | |||
The above directive defines all files with .jsp file types as files that should be passed to the tomcat server. | |||
The ajp13 argument is a class engine definition used to define how the jsp files are to be handled and passed to the | |||
tomcat server. The ajp13 class engine is defined in: | |||
/usr/local/apache/conf/workers.properties | |||
This file should not need to be modified under normal circumstances. | |||
The following defines the location of a servlet: | |||
<IfModule mod_jk.c> | |||
JkMount /examples/*.jsp ajp13 | |||
JkMount /examples/webapp_servlet/* ajp13 | |||
</IfModule> | |||
where again the first directive defines all files of type .jsp in the /examples to be handled by the jsp server | |||
and the second directive defines ALL files in the /examples/webapp_servlet/ directory to be passed to the tomcat | |||
server. (when all files are denoted it would be considered a webapp) | |||
Within the servlet directory will be a WEB-INF directory which contains all custom classes and the web.xml file, | |||
while the root of the servlet directory will contain all of the .jsp files. | |||
The above containers must be included in the VirtualHost container in httpd.conf for all sites that require use | |||
of the tomcat server. | |||
New cpanel stores the JkMount directives in: | |||
/usr/local/apache/conf/userdata/std/2/username/domainname/cp_jkmount.conf | |||
Double check the Include link in the apache vhost for proper path info. | |||
The tomcat server must also be configured to handle requests for the domain via a tomcat virtual host entry which | |||
looks like this: | |||
<Host name="starlabproductions.com" appBase="/home/starlab2/public_html" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" reloadable="true"> | |||
<Alias>www.starlabproductions.com</Alias> | |||
<Context path="" reloadable="true" docBase="/home/starlab2/public_html" debug="1" privileged="true" autoDeploy="true" liveDeploy="true"/> | |||
<Context path="/manager" debug="0" privileged="true" docBase="/usr/local/jakarta/tomcat/server/webapps/manager"> | |||
</Context> | |||
</Host> | |||
The above definition is to be included in: | |||
/usr/local/jakarta/tomcat/conf/server.xml within the <Engine> </Engine> tags. | |||
attributes will need to be modified for the above example to match the domain, which includes "Host name", appBase, docBase, prefix, and <Alias> tags. | |||
You can automagically use a default set of values by running: | |||
/scripts/addservlets2 --domain=domain-you-want-to-have-jsp-and-servlets.com | |||
OR | |||
/scripts/remservlets2 --domain=domain-you-want-to-have-jsp-and-servlets.com | |||
[[Note:]] You will need to use the above commands for adding subdomain support for servlets as they do not automatically include that support and WHM does not have any option to add servlets to subdomains. | |||
The unpackWAR and autoDeploy boolean values indicate whether or not the tomcat server is to autodeploy war files or not. When autodeploy is true, the | |||
user will simply upload a .war file to his docbase and the tomcat server will automatically unpack the war file and install the webapplication. | |||
After all configurations are complete the tomcat and httpd server must be restarted. | |||
/usr/sbin/stoptomcat | |||
/usr/sbin/starttomcat | |||
scripts to invoke the tomcat server. Usually the JAVA_HOME shell variable will need to be set which can be done via: | |||
export JAVA_HOME="/usr/local/jdk" | |||
Troubleshooting is rather intuitive as is any other function of this job, the error files can be located in: | |||
/usr/local/jakarta/tomcat/logs | |||
and the files to be examined are catalina.out and catalina.err | |||
/var/cpanel/tomcat.options | |||
This file you can use to set various Tomcat options, most importantly -Xmx an -Xms | |||
eg -Xmx200M -Xms100M | |||
These limit the amount memory each java process starts with and can use, very useful on VPS accounts. | |||
For full list. See here. | |||
http://blogs.sun.com/watt/resource/jvm-options-list.html | |||
If a user would like his web manager activated you can add a user account in: | |||
/usr/local/jakarta/tomcat/conf/tomcat-users.xml | |||
Add a line like: | |||
<user username="starlab2" password="pack?" roles="standard,manager"/> | |||
Then restart tomcat. | |||
Url can be accessed via: | |||
http://tomcat.liquidweb.com:8080/manager/html | |||
go configure!!.. | |||
any questions see me please. | |||
matt terry (mterry) | |||
== Installing Tomcat == | == Installing Tomcat == | ||
Line 19: | Line 217: | ||
is enough to get tomcat installed. | is enough to get tomcat installed. | ||
== | == Upgrading to Tomcat6 == | ||
{{notice| As far as I have tested this will only work on a cpanel box that has had tomcat installed via Easyapache.}} | |||
After Tomcat 5.5 has been installed via EA, proceed with the following steps to upgrade to 6.0.37. | |||
cd /usr/local/src/ | |||
wget -O /etc/init.d/tomcat6 http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/tomcat6 | |||
chmod +x /etc/init.d/tomcat6 | |||
wget apache-tomcat-6.0.37.tar.gz | |||
tar -zxvf apache-tomcat-6.0.37.tar.gz | |||
mv pache-tomcat-6.0.37 tomcat-6.0.37 | |||
cp -R tomcat-6.0.37 /usr/local/jakarta/ | |||
chown -R tomcat.nobody /usr/local/jakarta/tomcat-6.0.37 | |||
mv /usr/local/jakarta/apache-tomcat-5.5.35 /usr/local/jakarta/apache-tomcat-5.5.35.bak | |||
cp /usr/local/jakarta/apache-tomcat-5.5.35.bak/conf/workers.properties /usr/local/jakarta/tomcat-6.0.37/conf/workers.properties | |||
unlink /usr/local/jakarta/tomcat | |||
ln -s /usr/local/jakarta/tomcat-6.0.37/ /usr/local/jakarta/tomcat | |||
Now you will need to try to restart apache | |||
/etc/init.d/httpd restart | |||
If apache has problems restarting ask the mentors or escalations for help. | |||
==== tomcat6 startup issues ==== | |||
If the init script is having problems use the following. | |||
You can start up tomcat6 directly with the following. | |||
/usr/local/jakarta/tomcat-6.0.32/bin/startup.sh | |||
You can stop up tomcat6 directly with the following. | |||
/usr/local/jakarta/tomcat-6.0.32/bin/shutdown.sh | |||
==== Tomcat6 does not appear to start ==== | |||
Now if you try to startup tomcat and it doesn't appear to run do the following. | |||
java -version | |||
and if you get the following, proceed. | |||
root@host [/usr/local/jakarta/tomcat/bin]# java -version | |||
Error occurred during initialization of VM | |||
Could not reserve enough space for object heap | |||
Could not create the Java virtual machine. | |||
Run the following lines to add to the bashrc. | |||
echo "alias java=\"java -Xms32M -Xmx64M\"" >> /etc/bashrc | |||
source /etc/bashrc | |||
Also you will need to modify the tomcat startup and stop scripts with the following. | |||
vim /usr/local/jakarta/tomcat-6.0.32/bin/catalina.sh | |||
Find the following lines: | |||
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" | |||
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER" | |||
Append to them as follows: | |||
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms32M -Xmx64M" | |||
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER -Xms32M -Xmx64M" | |||
Now run the command to start it and it should work with no issues. | |||
== Tomcat 7 == | |||
{{Warning| Tomcat is not available through cpanel on servers that run CentOS 7, CloudLinux™ 7, or Red Hat® Enterprise Linux (RHEL) 7 as cpanel has dropped support for it BUT... It can be installed in a standalone fashion}} | |||
{{Notice| Tomcat7 will be installed with EA since cpanel 11.40. on Centos 6 and older, and on Centos7 boxes, you have to source install it and cannot access it from cpanel.}} | |||
===Centos 6 and older Installation=== | |||
==== Pre-requisites ==== | |||
{{Notice|I still recommend that you install tomcat via Easyapache first. This will ensure that mod_jk is setup and configured properly, and also provides us with a pre-written workers.properties file to steal.}} | |||
According to the tomcat website it will be easier to do a fresh install of tomcat 7 rather then upgrade. So here goes with a fresh install: | |||
First we should open the following ports in the firewall | |||
Port: '''8080''' | |||
Now lets get the files we will need: | |||
Install Java 7 as per the [[Java]] Wiki. | |||
==== Installation ==== | |||
{{Notice| Tomcat 7 will be installed with EA since about cpanel 11.40. The following is old info}} | |||
If installing it through Easyapache fails, expand and do the following. | |||
<div class="mw-collapsible mw-collapsed"> | |||
cd /usr/local/src/ | |||
wget http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/apache-tomcat-7.0.68.tar.gz | |||
tar -zxvf apache-tomcat-7.0.68.tar.gz | |||
mv apache-tomcat-7.0.68 tomcat-7.0.68 | |||
mkdir -p /usr/local/jakarta/ | |||
cp -R /usr/local/src/tomcat-7.0.68 /usr/local/jakarta/ | |||
unlink /usr/local/jakarta/tomcat | |||
ln -s /usr/local/jakarta/tomcat-7.0.68 /usr/local/jakarta/tomcat | |||
echo "export CATALINA_HOME=/usr/local/jakarta/tomcat" >> /etc/profile | |||
source /etc/profile | |||
cd /usr/local/jakarta/tomcat/bin/ | |||
tar -zxvf commons-daemon-native.tar.gz | |||
cd commons-daemon-1.0.15-native-src/unix/ | |||
./configure | |||
make | |||
cp jsvc ../.. | |||
echo "JAVA_OPTS="\$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true "" >> /usr/local/jakarta/tomcat-7.0.68/bin/setenv.sh | |||
useradd tomcat | |||
chown -R tomcat.tomcat /usr/local/jakarta/tomcat-7.0.68 | |||
wget -O /etc/init.d/tomcat7 http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/tomcat7 | |||
chmod +x /etc/init.d/tomcat7 | |||
Now you should be able restart tomcat with the following lines now. | |||
[root@Shooltz.net [/usr/local/jakarta/tomcat/bin]$ /etc/init.d/tomcat7 | |||
Usage: tomcat7 ( commands ... ) | |||
commands: | |||
run Start Catalina without detaching from console | |||
start Start Catalina | |||
stop Stop Catalina | |||
version What version of commons daemon and Tomcat are you running? | |||
</div> | |||
==== Removal ==== | |||
{{Warning| Make sure the customer wants this as it will delete all the webapps. (aka their data)}} | |||
Do the following to remove all of tomcat from this installation guide. | |||
sed -i -e 's#export CATALINA_HOME=/usr/local/jakarta/tomcat##g' /etc/profile | |||
rm -rf /usr/local/jakarta/tomcat-7.0.68 | |||
unlink /usr/local/jakarta/tomcat | |||
rm -rf /usr/local/src/apache-tomcat-7.0.68.tar.gz /usr/local/src/tomcat-7.0.68 | |||
rm -rf /etc/init.d/tomcat7 | |||
=== Centos 7 === | |||
==== Tomcat 7 ==== | |||
===== Pre-requisites ===== | |||
First we should open the following ports in the firewall | |||
Port: '''8080''' | |||
Now lets get the files we will need: | |||
Install Java 7 as per the [[Java]] Wiki. | |||
wget -O /scripts/plbake http://layer3.liquidweb.com/scripts/plBake/plBake | |||
chmod 700 /scripts/plbake | |||
/scripts/plbake java --installjava7 | |||
===== Installation ===== | |||
Copy pasta for the win. | |||
cd /usr/local/src/ | |||
wget http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/apache-tomcat-7.0.68.tar.gz | |||
tar -zxvf apache-tomcat-7.0.68.tar.gz | |||
mv apache-tomcat-7.0.68 tomcat-7.0.68 | |||
mkdir -p /usr/local/jakarta/ | |||
cp -R /usr/local/src/tomcat-7.0.68 /usr/local/jakarta/ | |||
unlink /usr/local/jakarta/tomcat | |||
ln -s /usr/local/jakarta/tomcat-7.0.68 /usr/local/jakarta/tomcat | |||
echo "export CATALINA_HOME=/usr/local/jakarta/tomcat" >> /etc/profile | |||
source /etc/profile | |||
cd /usr/local/jakarta/tomcat/bin/ | |||
tar -zxvf commons-daemon-native.tar.gz | |||
cd commons-daemon-1.0.15-native-src/unix/ | |||
./configure | |||
make | |||
cp jsvc ../.. | |||
echo "JAVA_OPTS="\$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true "" >> /usr/local/jakarta/tomcat-7.0.68/bin/setenv.sh | |||
useradd tomcat | |||
chown -R tomcat.tomcat /usr/local/jakarta/tomcat-7.0.68 | |||
wget -O /etc/systemd/system/tomcat.service http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/tomcat.service | |||
systemctl enable tomcat | |||
Now you should be able to control tomcat via systemctl: | |||
<pre> | <pre> | ||
- | root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl status tomcat | ||
● tomcat.service - Apache Tomcat Web Application Container | |||
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled) | |||
Active: inactive (dead) | |||
root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl start tomcat | |||
root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl status tomcat | |||
● tomcat.service - Apache Tomcat Web Application Container | |||
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled) | |||
Active: active (running) since Sat 2016-04-02 17:50:06 EDT; 3s ago | |||
Process: 25742 ExecStart=/usr/local/jakarta/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS) | |||
Main PID: 25759 (java) | |||
CGroup: /system.slice/tomcat.service | |||
└─25759 /usr/bin/java -Djava.util.logging.config.file=/usr/local/jakarta/tomcat/conf/logging.properties -Djava.util.l... | |||
Apr 02 17:50:05 cent7.shooltz.net systemd[1]: Starting Apache Tomcat Web Application Container... | |||
Apr 02 17:50:05 cent7.shooltz.net startup.sh[25742]: /usr/local/jakarta/tomcat/bin/setenv.sh: line 1: -Djava.net.preferIPv4...found | |||
Apr 02 17:50:05 cent7.shooltz.net startup.sh[25742]: /usr/local/jakarta/tomcat/bin/setenv.sh: line 2: -Djava.net.preferIPv4...found | |||
Apr 02 17:50:06 cent7.shooltz.net systemd[1]: Started Apache Tomcat Web Application Container. | |||
Hint: Some lines were ellipsized, use -l to show in full. | |||
</pre> | |||
Enjoy! | |||
===== Removal ===== | |||
{{Warning| Make sure the customer wants this as it will delete all the webapps. (aka their data)}} | |||
Do the following to remove all of tomcat from this installation guide. | |||
sed -i -e 's#export CATALINA_HOME=/usr/local/jakarta/tomcat##g' /etc/profile | |||
rm -rf /usr/local/jakarta/tomcat-7.0.68 | |||
unlink /usr/local/jakarta/tomcat | |||
rm -rf /usr/local/src/apache-tomcat-7.0.68.tar.gz /usr/local/src/tomcat-7.0.68 | |||
systemctl disable tomcat.service | |||
rm -rf /etc/systemd/system/tomcat.service | |||
==== Tomcat 8 ==== | |||
----------------- | ===== Pre-requisites ===== | ||
First we should open the following ports in the firewall | |||
Port: '''8080''' | |||
Now lets get the files we will need: | |||
Install Java 8 as per the [[Java]] Wiki. | |||
wget -O /scripts/plbake http://layer3.liquidweb.com/scripts/plBake/plBake | |||
chmod 700 /scripts/plbake | |||
/scripts/plbake java --installjava8 | |||
===== Installation ===== | |||
Copy pasta for the win. | |||
cd /usr/local/src/ | |||
wget http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/apache-tomcat-8.0.33.tar.gz | |||
tar -zxvf apache-tomcat-8.0.33.tar.gz | |||
mv apache-tomcat-8.0.33 tomcat-8.0.33 | |||
mkdir -p /usr/local/jakarta/ | |||
cp -R /usr/local/src/tomcat-8.0.33 /usr/local/jakarta/ | |||
unlink /usr/local/jakarta/tomcat | |||
ln -s /usr/local/jakarta/tomcat-8.0.33 /usr/local/jakarta/tomcat | |||
echo "export CATALINA_HOME=/usr/local/jakarta/tomcat" >> /etc/profile | |||
source /etc/profile | |||
cd /usr/local/jakarta/tomcat/bin/ | |||
tar -zxvf commons-daemon-native.tar.gz | |||
cd commons-daemon-1.0.15-native-src/unix/ | |||
./configure | |||
make | |||
cp jsvc ../.. | |||
echo "JAVA_OPTS="\$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true "" >> /usr/local/jakarta/tomcat-8.0.33/bin/setenv.sh | |||
useradd tomcat | |||
chown -R tomcat.tomcat /usr/local/jakarta/tomcat-8.0.33 | |||
wget -O /etc/systemd/system/tomcat.service http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/tomcat.service | |||
systemctl enable tomcat | |||
Now you should be able to control tomcat via systemctl: | |||
<pre> | |||
root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl status tomcat | |||
● tomcat.service - Apache Tomcat Web Application Container | |||
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled) | |||
Active: inactive (dead) | |||
root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl start tomcat | |||
root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl status tomcat | |||
● tomcat.service - Apache Tomcat Web Application Container | |||
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled) | |||
Active: active (running) since Fri 2016-04-29 18:20:51 EDT; 3s ago | |||
Process: 15517 ExecStop=/usr/local/jakarta/tomcat/bin/shutdown.sh (code=exited, status=0/SUCCESS) | |||
Process: 15613 ExecStart=/usr/local/jakarta/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS) | |||
Main PID: 15628 (java) | |||
CGroup: /system.slice/tomcat.service | |||
└─15628 /usr/bin/java -Djava.util.logging.config.file=/usr/local/jakarta/tomcat/conf/logging.properties -Djava.util.l... | |||
Apr 29 18:20:51 cent7.shooltz.net systemd[1]: Starting Apache Tomcat Web Application Container... | |||
Apr 29 18:20:51 cent7.shooltz.net startup.sh[15613]: /usr/local/jakarta/tomcat/bin/setenv.sh: line 1: -Djava.net.preferIPv4...found | |||
Apr 29 18:20:51 cent7.shooltz.net systemd[1]: Started Apache Tomcat Web Application Container. | |||
</pre> | </pre> | ||
Enjoy! | |||
===== Removal ===== | |||
{{Warning| Make sure the customer wants this as it will delete all the webapps. (aka their data)}} | |||
Do the following to remove all of tomcat from this installation guide. | |||
sed -i -e 's#export CATALINA_HOME=/usr/local/jakarta/tomcat##g' /etc/profile | |||
rm -rf /usr/local/jakarta/tomcat-8.0.33 | |||
unlink /usr/local/jakarta/tomcat | unlink /usr/local/jakarta/tomcat | ||
rm -rf /usr/local/src/apache-tomcat-8.0.33.tar.gz /usr/local/src/tomcat-8.0.33 | |||
systemctl disable tomcat.service | |||
rm -rf /etc/systemd/system/tomcat.service | |||
== Core-Managed SSL Installation == | |||
You should have the certificate and CA bundle downloaded to the server. If not, place them in /etc/pki/tls/certs/. From here we are going to create a keystore that can be used in the Tomcat config: | |||
openssl pkcs12 -export -in $nameofcertificate.crt -inkey $nameofkey.key -out $newkeystorename.pfx -name tomcat -CAfile $cabundlename.crt -caname root -chain | |||
Enter in a password for the keystore when prompted. Remember this password (or copy it into a note) as we need to update the server.xml file with it. | |||
Edit $TOMCAT/server.xml and add the following, changing the file name and password to what was just specified: | |||
<Connector port="443" maxHttpHeaderSize="8192" | |||
maxThreads="150" minSpareThreads="25" maxSpareThreads="75" | |||
enableLookups="false" disableUploadTimeout="true" | |||
acceptCount="100" scheme="https" secure="true" | |||
SSLEngine="on" | |||
keystoreType="PKCS12" | |||
keystoreFile="/etc/pki/tls/certs/newkeystorename.pfx" | |||
keystorePass="changeit"/> | |||
Restart Tomcat and verify your work. | |||
== Troubleshooting == | |||
===Syntax error on line 1 of /usr/local/apache/conf/jk.conf=== | |||
Now in the event that you get this error copy that file I mentioned earlier from the cpanel tomcat install I said to run before hand if it wasnt already installed. | |||
[root@Shooltz.net [/home/shooltz/public_html]$ /etc/init.d/httpd restart | [root@Shooltz.net [/home/shooltz/public_html]$ /etc/init.d/httpd restart | ||
Line 86: | Line 539: | ||
httpd not running, trying to start | httpd not running, trying to start | ||
Do the following. | |||
cp /usr/local/jakarta/apache-tomcat-5.5.30.bak/conf/workers.properties /usr/local/jakarta/tomcat/conf/workers.properties | |||
This should resolve that issue if not check and make sure that the paths in the commands above are correct. | |||
=== Cannot find any VM in Java Home === | |||
[guy@bat]# /etc/init.d/tomcat7 version | |||
Cannot find any VM in Java Home /usr/java/jdk1.6.0_06 | |||
Cannot find any VM in Java Home /usr/java/jdk1.6.0_06 | |||
Cannot locate JVM library file | |||
The system /etc/profile was not edited correctly. Find the correct path: | |||
/usr/local/jakarta/ | |||
[guy@bat]# /usr/local/jakarta]# find / -type d -name 'jdk1.6.0_*' | |||
/usr/local/jdk1.6.0_29 | |||
/usr/local/jdk1.6.0_29/jdk1.6.0_06 | |||
Edit and retry as necessary. | |||
=== Memory Problems === | |||
You can | Having out of memory problems with tomcat?... or perhaps an application won't start? You can actually add a line to the catalina.sh file to add some java options to tomcat when tomcat is started. | ||
Locate this file running on the tomcat server... | |||
/usr/local/jakarta/tomcat/bin/catalina.sh | |||
Then you could add something like this to the file... | |||
JAVA_OPTS= "-server -Xms256m -Xmx768m -XX:MaxPermSize=96m -XX:+UseParallelGC" | |||
After this stop tomcat and then start tomcat to verify that the new options will be loaded. | |||
== Remove Tomcat from server== | == Remove Tomcat from server== | ||
Check to see if it was installed VIA EasyApache First. NOTE: This will remove customer data in some cases. | |||
Uninstall / Remove Tomcat from Linux server | Uninstall / Remove Tomcat from Linux server | ||
rm -Rf /usr/local/jakarta | rm -Rf /usr/local/jakarta | ||
Line 129: | Line 594: | ||
echo “## Now exexute restart apache ##” | echo “## Now exexute restart apache ##” | ||
echo “## DONE! ##” | echo “## DONE! ##” | ||
[[Category:Windows]] | |||
[[Category:Support]] | |||
[[Category:Merge]] |
Latest revision as of 05:10, 6 May 2016
Template loop detected: Template:Besteffort
What is Tomcat
Tomcat is the open source implementation of the Java servlet, released under an Apache license. It allows for easy and rapid deployment of Java servlets, typically packaged as "war" files, which contain all of the directories and code necessary to run the application.
Tomcat can run as a standalone webserver, handling all requests for HTTP content, or it can be behind more traditional web servers such as Apache, and only used to serve the dynamic content for which the Java servlet or JavaServer Pages (JSP) are needed.
Windows
Plesk-Managed
Tomcat is integrated with Plesk on Plesk-managed servers, but the customer must have the Plesk Power Pack licensed (+$10/month) in order to actually use Tomcat. This means there is little to nothing that should be manually configured outside of Plesk.
For troubleshooting steps check Plesk_TomCat_Fixes
Core-Managed
There are two primary functions that Liquid Web will support on core-managed server regarding Tomcat:
Installation
This is as simply as downloading the "Windows Service Installer" package from here, for whatever version of Tomcat the customer would like, and running it. This will result in a very basic installation. The customer is responsible for setting up their sites.
SSL
Along with ordering a certificate for the customer, we can also install the certificate into Tomcat. Full documentation for this is available here, but below is a sample SSL connector. This entry would be added to ${catalina.base}/conf/server.xml with appropriate SSLCertificate values:
<Connector port="443" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true" acceptCount="100" scheme="https" secure="true" SSLEngine="on" SSLCertificateFile="${catalina.base}/conf/certificate.crt" SSLCertificateKeyFile="${catalina.base}/conf/certificate.key" SSLCACertificateFile="${catalina.base}/conf/ca.bundle.crt" />
You will very likely need to download the APR/OpenSSL binaries in order to use a PEM-format SSL with Tomcat. This can be downloaded here (version > binaries > tomcat-native-[version]-win32-bin.zip). Extract bin\openssl.exe and bin\tcnative-1.dll or bin\x64\tcnative-1.dll the 64-bit DLL goes in %windir%\system32 the 32-bit DLL goes in %windir%\syswow64.
Alternate
edit the server XML to read:
<Connector port="443" protocol="HTTP/1.1" maxThreads="200" scheme="https" secure="true" SSLEnabled="true" keystoreType="PKCS12" keystoreFile="${catalina.base}/conf/pass1.keystore" keystorePass="password" clientAuth="false" SSLProtocol="TLS"/>
and create the pass1.keystore using open SSL with this command:
openssl pkcs12 -export -in <certificate>.crt -inkey <key>.key -out C:\pass1.keystore -name tomcat -CAfile <bundle>.cer -caname root -chain
where:
- path to certificate = The actual Certificate
- key = The certificate private key
- bundle = Globalsign's root bundle followed bu Globalsigns intermediate bundle as shown here
RESTART TOMCAT!
Configuration
MySQL/JDBC Driver
- Download the driver from here
- Extract mysql-connector-java-[version]-bin.jar from the downloaded archive to %plesk_dir%\Additional\JDK\jre[version]\lib\ext\
- Restart Tomcat
Linux
Tomcat Can be installed through an EasyApache rebuild.
Cpanel has a good intro to tomcat article here for both versions 5.5 and 7.0 : http://docs.cpanel.net/twiki/bin/view/EasyApache/Tomcat/TomcatIntroduction
cpanel tomcat infos Tomcat listens on port 8080. Apache listens on port 80.
mod_jk.so is an apache module that passes all jsp/servlet requests to tomcat.
Jsp stands for java server pages. A typical JSP page is similar to that of PHP except that jsp is invoked via <%-- --%> instead of the typical <? ?> php tags, and uses the java compiler instead of the php interpreter.
A servlet is a collection of java classes used to create web applications. Think of it as a package. Standard web applications come packaged in *.war files (web application archive). A simple WAR file is simply a compressed (zipped) package consisting of jsp files, classes, and a web.xml file. The web.xml file is used to designate custom classes/servlets to be included in the web application and is to be configured by the programmer.
The mod_jk apache module is configured via JkMount directives designated in httpd.conf. Arguments to the JkMount directive specify which file types are to be passed to the tomcat server. JkMount also designates paths to where a specific servlet is located.
eg..
<IfModule mod_jk.c> JkMount /*.jsp ajp13 </IfModule>
The above directive defines all files with .jsp file types as files that should be passed to the tomcat server. The ajp13 argument is a class engine definition used to define how the jsp files are to be handled and passed to the tomcat server. The ajp13 class engine is defined in:
/usr/local/apache/conf/workers.properties
This file should not need to be modified under normal circumstances.
The following defines the location of a servlet:
<IfModule mod_jk.c> JkMount /examples/*.jsp ajp13 JkMount /examples/webapp_servlet/* ajp13 </IfModule>
where again the first directive defines all files of type .jsp in the /examples to be handled by the jsp server and the second directive defines ALL files in the /examples/webapp_servlet/ directory to be passed to the tomcat server. (when all files are denoted it would be considered a webapp)
Within the servlet directory will be a WEB-INF directory which contains all custom classes and the web.xml file, while the root of the servlet directory will contain all of the .jsp files.
The above containers must be included in the VirtualHost container in httpd.conf for all sites that require use of the tomcat server.
New cpanel stores the JkMount directives in:
/usr/local/apache/conf/userdata/std/2/username/domainname/cp_jkmount.conf
Double check the Include link in the apache vhost for proper path info.
The tomcat server must also be configured to handle requests for the domain via a tomcat virtual host entry which looks like this:
<Host name="starlabproductions.com" appBase="/home/starlab2/public_html" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" reloadable="true"> <Alias>www.starlabproductions.com</Alias> <Context path="" reloadable="true" docBase="/home/starlab2/public_html" debug="1" privileged="true" autoDeploy="true" liveDeploy="true"/> <Context path="/manager" debug="0" privileged="true" docBase="/usr/local/jakarta/tomcat/server/webapps/manager"> </Context> </Host>
The above definition is to be included in:
/usr/local/jakarta/tomcat/conf/server.xml within the <Engine> </Engine> tags.
attributes will need to be modified for the above example to match the domain, which includes "Host name", appBase, docBase, prefix, and <Alias> tags.
You can automagically use a default set of values by running:
/scripts/addservlets2 --domain=domain-you-want-to-have-jsp-and-servlets.com OR /scripts/remservlets2 --domain=domain-you-want-to-have-jsp-and-servlets.com
Note: You will need to use the above commands for adding subdomain support for servlets as they do not automatically include that support and WHM does not have any option to add servlets to subdomains.
The unpackWAR and autoDeploy boolean values indicate whether or not the tomcat server is to autodeploy war files or not. When autodeploy is true, the
user will simply upload a .war file to his docbase and the tomcat server will automatically unpack the war file and install the webapplication.
After all configurations are complete the tomcat and httpd server must be restarted.
/usr/sbin/stoptomcat /usr/sbin/starttomcat
scripts to invoke the tomcat server. Usually the JAVA_HOME shell variable will need to be set which can be done via:
export JAVA_HOME="/usr/local/jdk"
Troubleshooting is rather intuitive as is any other function of this job, the error files can be located in:
/usr/local/jakarta/tomcat/logs
and the files to be examined are catalina.out and catalina.err
/var/cpanel/tomcat.options
This file you can use to set various Tomcat options, most importantly -Xmx an -Xms
eg -Xmx200M -Xms100M
These limit the amount memory each java process starts with and can use, very useful on VPS accounts.
For full list. See here. http://blogs.sun.com/watt/resource/jvm-options-list.html
If a user would like his web manager activated you can add a user account in:
/usr/local/jakarta/tomcat/conf/tomcat-users.xml
Add a line like:
<user username="starlab2" password="pack?" roles="standard,manager"/>
Then restart tomcat.
Url can be accessed via:
http://tomcat.liquidweb.com:8080/manager/html
go configure!!..
any questions see me please.
matt terry (mterry)
Installing Tomcat
On a cPanel server typically checking the Tomcat option in EasyApache is enough to install Tomcat:
/scripts/easyapache
However, occasionally it will report that it has successfully installed Tomcat, but Tomcat will fail to run due to Java not being installed.
On core managed servers,
yum install tomcat5
is enough to get tomcat installed.
Upgrading to Tomcat6
After Tomcat 5.5 has been installed via EA, proceed with the following steps to upgrade to 6.0.37.
cd /usr/local/src/ wget -O /etc/init.d/tomcat6 http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/tomcat6 chmod +x /etc/init.d/tomcat6 wget apache-tomcat-6.0.37.tar.gz tar -zxvf apache-tomcat-6.0.37.tar.gz mv pache-tomcat-6.0.37 tomcat-6.0.37 cp -R tomcat-6.0.37 /usr/local/jakarta/ chown -R tomcat.nobody /usr/local/jakarta/tomcat-6.0.37 mv /usr/local/jakarta/apache-tomcat-5.5.35 /usr/local/jakarta/apache-tomcat-5.5.35.bak cp /usr/local/jakarta/apache-tomcat-5.5.35.bak/conf/workers.properties /usr/local/jakarta/tomcat-6.0.37/conf/workers.properties unlink /usr/local/jakarta/tomcat ln -s /usr/local/jakarta/tomcat-6.0.37/ /usr/local/jakarta/tomcat
Now you will need to try to restart apache
/etc/init.d/httpd restart
If apache has problems restarting ask the mentors or escalations for help.
tomcat6 startup issues
If the init script is having problems use the following.
You can start up tomcat6 directly with the following.
/usr/local/jakarta/tomcat-6.0.32/bin/startup.sh
You can stop up tomcat6 directly with the following.
/usr/local/jakarta/tomcat-6.0.32/bin/shutdown.sh
Tomcat6 does not appear to start
Now if you try to startup tomcat and it doesn't appear to run do the following.
java -version
and if you get the following, proceed.
root@host [/usr/local/jakarta/tomcat/bin]# java -version Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.
Run the following lines to add to the bashrc.
echo "alias java=\"java -Xms32M -Xmx64M\"" >> /etc/bashrc source /etc/bashrc
Also you will need to modify the tomcat startup and stop scripts with the following.
vim /usr/local/jakarta/tomcat-6.0.32/bin/catalina.sh
Find the following lines:
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
Append to them as follows:
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms32M -Xmx64M" JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER -Xms32M -Xmx64M"
Now run the command to start it and it should work with no issues.
Tomcat 7
Centos 6 and older Installation
Pre-requisites
According to the tomcat website it will be easier to do a fresh install of tomcat 7 rather then upgrade. So here goes with a fresh install:
First we should open the following ports in the firewall
Port: 8080
Now lets get the files we will need:
Install Java 7 as per the Java Wiki.
Installation
If installing it through Easyapache fails, expand and do the following.
cd /usr/local/src/ wget http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/apache-tomcat-7.0.68.tar.gz tar -zxvf apache-tomcat-7.0.68.tar.gz mv apache-tomcat-7.0.68 tomcat-7.0.68 mkdir -p /usr/local/jakarta/ cp -R /usr/local/src/tomcat-7.0.68 /usr/local/jakarta/ unlink /usr/local/jakarta/tomcat ln -s /usr/local/jakarta/tomcat-7.0.68 /usr/local/jakarta/tomcat echo "export CATALINA_HOME=/usr/local/jakarta/tomcat" >> /etc/profile source /etc/profile cd /usr/local/jakarta/tomcat/bin/ tar -zxvf commons-daemon-native.tar.gz cd commons-daemon-1.0.15-native-src/unix/ ./configure make cp jsvc ../.. echo "JAVA_OPTS="\$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true "" >> /usr/local/jakarta/tomcat-7.0.68/bin/setenv.sh useradd tomcat chown -R tomcat.tomcat /usr/local/jakarta/tomcat-7.0.68 wget -O /etc/init.d/tomcat7 http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/tomcat7 chmod +x /etc/init.d/tomcat7
Now you should be able restart tomcat with the following lines now.
[root@Shooltz.net [/usr/local/jakarta/tomcat/bin]$ /etc/init.d/tomcat7 Usage: tomcat7 ( commands ... ) commands: run Start Catalina without detaching from console start Start Catalina stop Stop Catalina version What version of commons daemon and Tomcat are you running?
Removal
Do the following to remove all of tomcat from this installation guide.
sed -i -e 's#export CATALINA_HOME=/usr/local/jakarta/tomcat##g' /etc/profile rm -rf /usr/local/jakarta/tomcat-7.0.68 unlink /usr/local/jakarta/tomcat rm -rf /usr/local/src/apache-tomcat-7.0.68.tar.gz /usr/local/src/tomcat-7.0.68 rm -rf /etc/init.d/tomcat7
Centos 7
Tomcat 7
Pre-requisites
First we should open the following ports in the firewall
Port: 8080
Now lets get the files we will need:
Install Java 7 as per the Java Wiki.
wget -O /scripts/plbake http://layer3.liquidweb.com/scripts/plBake/plBake chmod 700 /scripts/plbake /scripts/plbake java --installjava7
Installation
Copy pasta for the win.
cd /usr/local/src/ wget http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/apache-tomcat-7.0.68.tar.gz tar -zxvf apache-tomcat-7.0.68.tar.gz mv apache-tomcat-7.0.68 tomcat-7.0.68 mkdir -p /usr/local/jakarta/ cp -R /usr/local/src/tomcat-7.0.68 /usr/local/jakarta/ unlink /usr/local/jakarta/tomcat ln -s /usr/local/jakarta/tomcat-7.0.68 /usr/local/jakarta/tomcat echo "export CATALINA_HOME=/usr/local/jakarta/tomcat" >> /etc/profile source /etc/profile cd /usr/local/jakarta/tomcat/bin/ tar -zxvf commons-daemon-native.tar.gz cd commons-daemon-1.0.15-native-src/unix/ ./configure make cp jsvc ../.. echo "JAVA_OPTS="\$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true "" >> /usr/local/jakarta/tomcat-7.0.68/bin/setenv.sh useradd tomcat chown -R tomcat.tomcat /usr/local/jakarta/tomcat-7.0.68 wget -O /etc/systemd/system/tomcat.service http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/tomcat.service systemctl enable tomcat
Now you should be able to control tomcat via systemctl:
root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl status tomcat ● tomcat.service - Apache Tomcat Web Application Container Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled) Active: inactive (dead) root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl start tomcat root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl status tomcat ● tomcat.service - Apache Tomcat Web Application Container Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2016-04-02 17:50:06 EDT; 3s ago Process: 25742 ExecStart=/usr/local/jakarta/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS) Main PID: 25759 (java) CGroup: /system.slice/tomcat.service └─25759 /usr/bin/java -Djava.util.logging.config.file=/usr/local/jakarta/tomcat/conf/logging.properties -Djava.util.l... Apr 02 17:50:05 cent7.shooltz.net systemd[1]: Starting Apache Tomcat Web Application Container... Apr 02 17:50:05 cent7.shooltz.net startup.sh[25742]: /usr/local/jakarta/tomcat/bin/setenv.sh: line 1: -Djava.net.preferIPv4...found Apr 02 17:50:05 cent7.shooltz.net startup.sh[25742]: /usr/local/jakarta/tomcat/bin/setenv.sh: line 2: -Djava.net.preferIPv4...found Apr 02 17:50:06 cent7.shooltz.net systemd[1]: Started Apache Tomcat Web Application Container. Hint: Some lines were ellipsized, use -l to show in full.
Enjoy!
Removal
Do the following to remove all of tomcat from this installation guide.
sed -i -e 's#export CATALINA_HOME=/usr/local/jakarta/tomcat##g' /etc/profile rm -rf /usr/local/jakarta/tomcat-7.0.68 unlink /usr/local/jakarta/tomcat rm -rf /usr/local/src/apache-tomcat-7.0.68.tar.gz /usr/local/src/tomcat-7.0.68 systemctl disable tomcat.service rm -rf /etc/systemd/system/tomcat.service
Tomcat 8
Pre-requisites
First we should open the following ports in the firewall
Port: 8080
Now lets get the files we will need:
Install Java 8 as per the Java Wiki.
wget -O /scripts/plbake http://layer3.liquidweb.com/scripts/plBake/plBake chmod 700 /scripts/plbake /scripts/plbake java --installjava8
Installation
Copy pasta for the win.
cd /usr/local/src/ wget http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/apache-tomcat-8.0.33.tar.gz tar -zxvf apache-tomcat-8.0.33.tar.gz mv apache-tomcat-8.0.33 tomcat-8.0.33 mkdir -p /usr/local/jakarta/ cp -R /usr/local/src/tomcat-8.0.33 /usr/local/jakarta/ unlink /usr/local/jakarta/tomcat ln -s /usr/local/jakarta/tomcat-8.0.33 /usr/local/jakarta/tomcat echo "export CATALINA_HOME=/usr/local/jakarta/tomcat" >> /etc/profile source /etc/profile cd /usr/local/jakarta/tomcat/bin/ tar -zxvf commons-daemon-native.tar.gz cd commons-daemon-1.0.15-native-src/unix/ ./configure make cp jsvc ../.. echo "JAVA_OPTS="\$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true "" >> /usr/local/jakarta/tomcat-8.0.33/bin/setenv.sh useradd tomcat chown -R tomcat.tomcat /usr/local/jakarta/tomcat-8.0.33 wget -O /etc/systemd/system/tomcat.service http://layer3.liquidweb.com/scripts/plBake/packages/tomcat/tomcat.service systemctl enable tomcat
Now you should be able to control tomcat via systemctl:
root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl status tomcat ● tomcat.service - Apache Tomcat Web Application Container Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled) Active: inactive (dead) root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl start tomcat root@cent7 [/usr/local/jakarta/tomcat/bin]# systemctl status tomcat ● tomcat.service - Apache Tomcat Web Application Container Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2016-04-29 18:20:51 EDT; 3s ago Process: 15517 ExecStop=/usr/local/jakarta/tomcat/bin/shutdown.sh (code=exited, status=0/SUCCESS) Process: 15613 ExecStart=/usr/local/jakarta/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS) Main PID: 15628 (java) CGroup: /system.slice/tomcat.service └─15628 /usr/bin/java -Djava.util.logging.config.file=/usr/local/jakarta/tomcat/conf/logging.properties -Djava.util.l... Apr 29 18:20:51 cent7.shooltz.net systemd[1]: Starting Apache Tomcat Web Application Container... Apr 29 18:20:51 cent7.shooltz.net startup.sh[15613]: /usr/local/jakarta/tomcat/bin/setenv.sh: line 1: -Djava.net.preferIPv4...found Apr 29 18:20:51 cent7.shooltz.net systemd[1]: Started Apache Tomcat Web Application Container.
Enjoy!
Removal
Do the following to remove all of tomcat from this installation guide.
sed -i -e 's#export CATALINA_HOME=/usr/local/jakarta/tomcat##g' /etc/profile rm -rf /usr/local/jakarta/tomcat-8.0.33 unlink /usr/local/jakarta/tomcat rm -rf /usr/local/src/apache-tomcat-8.0.33.tar.gz /usr/local/src/tomcat-8.0.33 systemctl disable tomcat.service rm -rf /etc/systemd/system/tomcat.service
Core-Managed SSL Installation
You should have the certificate and CA bundle downloaded to the server. If not, place them in /etc/pki/tls/certs/. From here we are going to create a keystore that can be used in the Tomcat config:
openssl pkcs12 -export -in $nameofcertificate.crt -inkey $nameofkey.key -out $newkeystorename.pfx -name tomcat -CAfile $cabundlename.crt -caname root -chain
Enter in a password for the keystore when prompted. Remember this password (or copy it into a note) as we need to update the server.xml file with it.
Edit $TOMCAT/server.xml and add the following, changing the file name and password to what was just specified:
<Connector port="443" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true" acceptCount="100" scheme="https" secure="true" SSLEngine="on" keystoreType="PKCS12" keystoreFile="/etc/pki/tls/certs/newkeystorename.pfx" keystorePass="changeit"/>
Restart Tomcat and verify your work.
Troubleshooting
Syntax error on line 1 of /usr/local/apache/conf/jk.conf
Now in the event that you get this error copy that file I mentioned earlier from the cpanel tomcat install I said to run before hand if it wasnt already installed.
[root@Shooltz.net [/home/shooltz/public_html]$ /etc/init.d/httpd restart Syntax error on line 1 of /usr/local/apache/conf/jk.conf: JkWorkersFile: Can't find the workers file specified httpd not running, trying to start
Do the following.
cp /usr/local/jakarta/apache-tomcat-5.5.30.bak/conf/workers.properties /usr/local/jakarta/tomcat/conf/workers.properties
This should resolve that issue if not check and make sure that the paths in the commands above are correct.
Cannot find any VM in Java Home
[guy@bat]# /etc/init.d/tomcat7 version Cannot find any VM in Java Home /usr/java/jdk1.6.0_06 Cannot find any VM in Java Home /usr/java/jdk1.6.0_06 Cannot locate JVM library file
The system /etc/profile was not edited correctly. Find the correct path:
[guy@bat]# /usr/local/jakarta]# find / -type d -name 'jdk1.6.0_*' /usr/local/jdk1.6.0_29 /usr/local/jdk1.6.0_29/jdk1.6.0_06
Edit and retry as necessary.
Memory Problems
Having out of memory problems with tomcat?... or perhaps an application won't start? You can actually add a line to the catalina.sh file to add some java options to tomcat when tomcat is started.
Locate this file running on the tomcat server...
/usr/local/jakarta/tomcat/bin/catalina.sh
Then you could add something like this to the file...
JAVA_OPTS= "-server -Xms256m -Xmx768m -XX:MaxPermSize=96m -XX:+UseParallelGC"
After this stop tomcat and then start tomcat to verify that the new options will be loaded.
Remove Tomcat from server
Check to see if it was installed VIA EasyApache First. NOTE: This will remove customer data in some cases.
Uninstall / Remove Tomcat from Linux server rm -Rf /usr/local/jakarta service chkservd stop cd /etc/chkserv.d rm -Rf tomcat cd /var/run/chkservd rm -Rf Tomcat_JSP service chkservd start rm -f /usr/sbin/starttomcat rm -f /usr/sbin/stoptomcat echo “You must now remove the following lines (if they exist) form httpd.conf and restart apache” echo “## LoadModule jk_module libexec/mod_jk.so ##” echo “## AddModule mod_jk.c ##” echo “## Include=”/usr/local/jakarta/tomcat/conf/mod_jk.conf” ##” echo “## Now exexute restart apache ##” echo “## DONE! ##”