Install tomcat9 under Ubuntu 16.10

Time:2020-6-13

statement

This article was founded on March 10, 2017. It’s the same day that the installation was successful.
The links given in this paper may fail in the future.
About Tomcat self startup, Tomcat official website prompts a way.
But in this paper, other methods are used.

Environmental Science

System: ubuntu-16.10-server-amd64
User: root

get ready

File: JDK (jdk-8u121-linux-x64 tar.gz )、Tomcat(apache-tomcat-9.0.0.M17. tar.gz )
File storage directory / root/
The installation directory / usr / local / Java (JDK), / usr / local / Tomcat (Tomcat) should not be created in a hurry. There are instructions in the installation process below.

install

Install JDK first (refer to the installation of JDK 1.8 in Linux Ubuntu) to avoid jumping around and logic moving, as follows:

1. Create / usr / local / Java directory,Note: the current operation user is root

mkdir  /usr/local/java

2. Extract the JDK compressed file to / usr / local / Java just created.

tar -zxvf /root/jdk-8u121-linux-x64.tar.gz -C /usr/local/java

3. Set environment variables, add the contents of environment variables, and make them effective.

nano /etc/profile
#set java environment
export JAVA_HOME=/usr/local/java/jdk1.8.0_121
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
. /etc/profile

4. Set the default JDK.

update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_121/bin/java 300
update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.8.0_121/bin/javac 300

5. Check whether it is successful. If it is successful, it is as follows.

java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Then install Tomcat (refer to https://wolfpaulus.com/java/t… )。
Here we still move the logic.

1. Create a dedicated user Tomcat for Tomcat,Note: the following command is one line, no newline, the success is shown below.

adduser \--system \--shell /bin/bash \--gecos 'Tomcat Java Servlet and JSP engine' \--group \--disabled-password \--home /home/tomcat \tomcat
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' ...

2. Extract the Tomcat compressed file to the directory / usr / local /.

tar -zxvf /root/apache-tomcat-9.0.0.M17.tar.gz -C /usr/local/

3. Create a folder soft link.
Note: before creating, you need to check whether it already exists, and if so, you need to executerm -f /usr/local/tomcat

ln -s /usr/local/apache-tomcat-9.0.0.M17 /usr/local/tomcat

4. Modify authority.

chown -R tomcat:tomcat /usr/local/tomcat/*
chmod +x /usr/local/tomcat/bin/*.sh

5. Start Tomcat. Visit 192.168.189.129:8080 in the browser (the IP address and port number here must be changed to their own).

/bin/su - tomcat -c /usr/local/tomcat/bin/startup.sh

6. Stop Tomcat.

/bin/su - tomcat -c /usr/local/tomcat/bin/shutdown.sh

7. When the system starts, Tomcat runs. That is, Tomcat starts automatically.

nano /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/local/tomcat/bin/startup.sh
}
 
stop() {
 /bin/su - tomcat -c /usr/local/tomcat/bin/shutdown.sh 
}
 
case $1 in
  start|stop) $1;;
  restart) stop; start;;
  *) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac

8. Modify permissions and update system startup items.

chmod 755 /etc/init.d/tomcat
update-rc.d tomcat defaults

9. Restart the system and check whether Tomcat has started automatically. Of course, you can access it in the browser.

reboot
ps -ef|grep tomcat

Reference documents

Install JDK: Linux Ubuntu install JDK 1.8
Install Tomcat: installing Java 8 and Tomcat 8 on Debian Jessie or raspbian or RedHat