So installieren Sie Apache Tomcat 8 unter Debian

So installieren Sie Apache Tomcat 8 unter Debian

tomcat-debian

In diesem Tutorial zeigen wir Ihnen, wie Sie Apache Tomcat 8 On Debian manuell installieren.

Umgebung :

  1. Debian 7

  2. JDK 1.8

  3. Apache Tomcat 8

P.S Assume the JDK 1.8 is installed in `/opt/jdk` Ordner. Siehe diese Anleitung zuinstall Oracle JDK 8 on Debian.

Note
Unter Debian 7 ist Tomcat 8 nicht im Standard-Apt-Get-Repository enthalten.

Note
Dieses Handbuch sollte in anderen Debian-Derivaten wie Ubuntu oder Mint funktionieren.

1. Holen Sie sich Tomcat 8

1.1 Visit Tomcat 8 page and download the tar.gz file.

1.2 In this example, we get the version 8.0.30 via wget command.

$ cd /opt
$ sudo wget http://www.eu.apache.org/dist/tomcat/tomcat-8/v8.0.30/bin/apache-tomcat-8.0.30.tar.gz

2. Auszüge aus / opt / tomcat8

2.1 Extracts it to path /opt/tomcat8

$ pwd
/opt
$ sudo tar -xvzf apache-tomcat-8.0.30.tar.gz
$ mv apache-tomcat-8.0.30 tomcat8

$ ls -lsh
4.0K drwxr-xr-x  6 root   root   4.0K Dec 27 09:16 .
4.0K drwxr-xr-x 23 root   root   4.0K Feb 26  2014 ..
8.8M -rw-r--r--  1 root   root   8.8M Dec  1 17:56 apache-tomcat-8.0.30.tar.gz
4.0K drwxr-xr-x  3 root   root   4.0K Dec 27 09:06 jdk
4.0K drwxr-xr-x  9 root   root   4.0K Dec 27 09:16 tomcat8

3. Erstellen Sie einen Tomcat-Benutzer

3.1 Review the extracted tomcat8 folder, which is belonging to “root” user. Für eine gute Praxis sollten wir einen neuen Benutzer erstellen, um den Tomcat auszuführen. In diesem Beispiel erstellen wir einen nicht angemeldeten Benutzer "tomcat" und setzen sein Zuhause auf/opt/tomcat/temp (wo immer Sie wollen).

#Usage : useradd -s  -d  

$ sudo useradd -s /sbin/nologin -d /opt/tomcat/temp tomcat

3.2 Change permissions of the /opt/tomcat8 folder, so that the new “tomcat” user can run the Tomcat.

$ sudo chown -R tomcat:tomcat /opt/tomcat8

$ pwd
/opt
$ls -lsh
8.8M -rw-r--r--  1 root   root   8.8M Dec  1 17:56 apache-tomcat-8.0.30.tar.gz
4.0K drwxr-xr-x  3 root   root   4.0K Dec 27 09:06 jdk
4.0K drwxr-xr-x  9 tomcat tomcat 4.0K Dec 27 09:16 tomcat8

4. /etc/init.d/tomcat8

Um Tomcat als Init-Dienst auszuführen, erstellen Sie ein benutzerdefiniertes Skript und legen Sie es im Ordner/etc/init.dab.

4.1 Create a script and save it as /etc/init.d/tomcat8

$ sudo vim /etc/init.d/tomcat8

/etc/init.d/tomcat8

#!/bin/bash
#
#https://wiki.debian.org/LSBInitScripts
### BEGIN INIT INFO
# Provides:          tomcat8
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Should-Start:      $named
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Tomcat.
# Description:       Start the Tomcat servlet engine.
### END INIT INFO

export CATALINA_HOME=/opt/tomcat8
export JAVA_HOME=/opt/jdk/jdk1.8.0_66
export PATH=$JAVA_HOME/bin:$PATH

start() {
 echo "Starting Tomcat 8..."
 /bin/su -s /bin/bash tomcat -c $CATALINA_HOME/bin/startup.sh
}
stop() {
 echo "Stopping Tomcat 8..."
 /bin/su -s /bin/bash tomcat -c $CATALINA_HOME/bin/shutdown.sh
}
case $1 in
  start|stop) $1;;
  restart) stop; start;;
  *) echo "Usage : $0 "; exit 1;;
esac

exit 0

Note
Dieses einfache Tomcat-Init-Skript wird auf einem meiner Server ausgeführt, und ich glaube, es reicht aus, um den Tomcat zu steuern. Wenn Sie nach erweiterten Funktionen suchen, besuchen Sie dieseTomcat init script

4.2 Assign “execute” permission.

$ sudo chmod 755 /etc/init.d/tomcat8

#Review permission
$ ls -lsh /etc/init.d/tomcat8
4.0K -rwxr-xr-x 1 root root 859 Dec 27 22:07 /etc/init.d/tomcat8

4.3 Install the script.

$ sudo update-rc.d tomcat8 defaults

4.4 Test it

$ sudo service tomcat8
Usage : /etc/init.d/tomcat8 

#Start Tomcat...
$ sudo service tomcat8 start
Starting Tomcat 8...
Using CATALINA_BASE:   /opt/tomcat8
Using CATALINA_HOME:   /opt/tomcat8
Using CATALINA_TMPDIR: /opt/tomcat8/temp
Using JRE_HOME:        /opt/jdk/jdk1.8.0_66
Using CLASSPATH:       /opt/tomcat8/bin/bootstrap.jar:/opt/tomcat8/bin/tomcat-juli.jar
Tomcat started.

#Stop Tomcat...
$ sudo service tomcat8 stop
Stopping Tomcat 8...
Using CATALINA_BASE:   /opt/tomcat8
Using CATALINA_HOME:   /opt/tomcat8
Using CATALINA_TMPDIR: /opt/tomcat8/temp
Using JRE_HOME:        /opt/jdk/jdk1.8.0_66
Using CLASSPATH:       /opt/tomcat8/bin/bootstrap.jar:/opt/tomcat8/bin/tomcat-juli.jar

Besuchen Sie die Tomcat-Standard-URL:http://localhost:8080

Erledigt.

6. Extras…

6.1 To deploy a WAR file, just copy the WAR file in the /opt/tomcat8/webapps/ folder. Starten Sie Tomcat neu. Die Kriegsdatei wird extrahiert und automatisch bereitgestellt.

  1. Beispiel -/opt/tomcat8/webapps/lovejava.war

  2. Bereitgestellte URL -http://localhost:8080/lovejava

6.2 To change the default port (8080), just update the connector port to another port number and restart Tomcat.

/opt/tomcat8/conf/server.xml

6.3 Make the web app as the default path.

/opt/tomcat8/conf/server.xml



      
      
            
                WEB-INF/web.xml
      

Jetzt können wir über diese URLhttp://localhost:8080/ auf die Web-App von/lovejavazugreifen