Apache Tomcat is a Servlet/JSP container and version 8.0 implements
the Servlet 3.1 and JavaServer Pages 2.3 specifications. Please note
that Apache Tomcat 8.0 requires a Java Standard Edition Runtime
Environment (JRE) version 7 or later. So we start with installing a
recent version of Oracle’s JRE.
BTW, Java got installed into this location: /usr/lib/jvm/java-8-oracle
edit /usr/share/tomcat/conf/server.xml and replace 8080 with 8000
Install Oracle JRE 8 on Debian Linux
To install Oracle’s Java Runtime with apt-get, we first need to entend the list of apt-get’s sources. Once that is done, an java-installer will actually install the Java SE Runtime Environment. Here are the steps to follow:$ su root # echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" > /etc/apt/sources.list.d/webupd8team-java.list # echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" >> /etc/apt/sources.list.d/webupd8team-java.list # apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886 # apt-get update # apt-get install oracle-java8-installer # java -version # exitAs I’m writing this, the newly installed Java Runtime reports its version as 1.8.0_45:
java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)With Java now installed we move on, installing Tomcat. However, it may be beneficial to have an dedicated user for Tomcat.
BTW, Java got installed into this location: /usr/lib/jvm/java-8-oracle
sudo adduser \ --system \ --shell /bin/bash \ --gecos 'Tomcat Java Servlet and JSP engine' \ --group \ --disabled-password \ --home /home/tomcat \ tomcat.. which should result in something like this:
Adding system user 'tomcat' (UID 108) ... Adding new group 'tomcat' (GID 113) ... Adding new user 'tomcat' (UID 108) with group 'tomcat' ... Creating home directory '/home/tomcat' ...
Installing Tomcat8
$ mkdir -p ~/tmp $ cd ~/tmp $ wget http://www.us.apache.org/dist/tomcat/tomcat-8/v8.0.24/bin/apache-tomcat-8.0.24.tar.gz $ tar xvzf ./apache-tomcat-8.0.24.tar.gz $ rm ./apache-tomcat-8.0.24.tar.gz
$ sudo mkdir -p /usr/share/tomcat8 $ sudo mv ~/tmp/apache-tomcat-8.0.24 /usr/share/tomcat8To make it easy to replace this release with future releases, we are going to create a symbolic link that we are going to use when referring to Tomcat (after removing the old link, you might have from installing a previous version):
$ sudo rm -f /usr/share/tomcat $ sudo ln -s /usr/share/tomcat8/apache-tomcat-8.0.24 /usr/share/tomcatSince we created a tomcat user, he should also own all these files in
$ sudo chown -R tomcat:tomcat /usr/share/tomcat8 $ sudo chmod +x /usr/share/tomcat/bin/*.shIf Tomcat’s default HTTP port (8080) is already in use, you need to edit the server.xml configuration file, e.g.
edit /usr/share/tomcat/conf/server.xml and replace 8080 with 8000
Starting Tomcat
$ sudo /bin/su - tomcat -c /usr/share/tomcat/bin/startup.sh Using CATALINA_BASE: /usr/share/tomcat Using CATALINA_HOME: /usr/share/tomcat Using CATALINA_TMPDIR: /usr/share/tomcat/temp Using JRE_HOME: /usr Using CLASSPATH: /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar
Stopping Tomcat
$sudo /bin/su - tomcat -c /usr/share/tomcat/bin/shutdown.sh Using CATALINA_BASE: /usr/share/tomcat Using CATALINA_HOME: /usr/share/tomcat Using CATALINA_TMPDIR: /usr/share/tomcat/temp Using JRE_HOME: /usr Using CLASSPATH: /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar
Staring Tomcat when the server boots
To start Tomcat automatically, every time the server re-boots, save this script in /etc/init.d/tomcat#!/bin/bash ### BEGIN INIT INFO # Provides: tomcat # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/Stop Tomcat server ### END INIT INFO PATH=/sbin:/bin:/usr/sbin:/usr/bin start() { /bin/su - tomcat -c /usr/share/tomcat/bin/startup.sh } stop() { /bin/su - tomcat -c /usr/share/tomcat/bin/shutdown.sh } case $1 in start|stop) $1;; restart) stop; start;; *) echo "Run as $0 <start|stop|restart>"; exit 1;; esacNow change the permissions of the newly created file and add the correct symlinks automatically:
chmod 755 /etc/init.d/tomcat update-rc.d tomcat defaults
Long Startup Time
Tomcat relies heavily relies on the SecureRandom class to provide random values, for instance to generate session ids. During startup, if entropy source that is used to initialize SecureRandom is short of entropy, this can lead to very long delays, which can be confirmed in the logs/catalina.out log file.
Adding
JAVA_OPTS="-Djava.security.egd=file:/dev/urandom"at the beginning of the bin/cataline.sh file, will significatinly speedup the startup time.
Комментариев нет:
Отправить комментарий