statement
This article was founded on March 10, 2017. Successful installation is also the day.
The links given in this paper may fail in the future.
About Tomcat self-startup, Tomcat official website prompts one mode.
But this article uses other ways.
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/
Installation directories: / usr/local/java (JDK), / usr/local/tomcat (Tomcat) are not created in a hurry. There are instructions in the installation process below.
install
Install JDK first (see Linux Ubuntu Installation JDK 1.8 ) Avoid jumping around and moving logically, as follows:
1. Create the / usr/local/java directory. Note that the current user is root.
mkdir /usr/local/java
2. Unzip the JDK compressed file into the newly created / usr/local/java.
tar -zxvf /root/jdk-8u121-linux-x64.tar.gz -C /usr/local/java
3. Set up environment variables and add environment variables.
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
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 to see if it is successful, if successful, 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)
Install Tomcat again (see https://wolfpaulus.com/java/t...).
Still move logic here.
1. Create a dedicated user Tomcat for Tomcat. Note that the following command is one line, no line breaks, and 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. Unzip the Tomcat compressed file into / usr/local / directory.
tar -zxvf /root/apache-tomcat-9.0.0.M17.tar.gz -C /usr/local/
3. Create folder soft links.
Note: Before creating, you need to see if it already exists and if so, you need to execute rm-f/usr/local/tomcat
ln -s /usr/local/apache-tomcat-9.0.0.M17 /usr/local/tomcat
4. Modify permissions.
chown -R tomcat:tomcat /usr/local/tomcat/* chmod +x /usr/local/tomcat/bin/*.sh
5. Start Tomcat. Access 192.168.189.129:8080 in the browser (where IP address and port number have to 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. Tomcat runs when the system starts. That is Tomcat auto-start.
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. Reboot the system and check whether Tomcat is self-booting. Of course, browser access is also possible.
reboot
ps -ef|grep tomcat
Reference document
Install JDK: Linux Ubuntu Installation JDK 1.8
Install Tomcat: Installing Java 8 and Tomcat 8 on Debian Jessie or Raspbian or RedHat