Sunday, September 8, 2024
HometomcatInstall tomcat on linux and register tomcat as a service

Install tomcat on linux and register tomcat as a service

Reference: https://www.cnblogs.com/DevinZhang1990/p/12795565.html

  1. Download a tomcat server, upload it to the server, and extract it to a path
    For example, the path is: /server/apache-tomcat-8.0.52
    That is $Tomcat_HOME = /server/apache-tomcat-8.0.52

  2. Add tomcat to the linux service
    2.1. Copy Catalina.sh in the $Tomcat_HOME/bin directory to the directory /etc/init.d and rename it to tomcat

cp $Tomcat_HOME/bin/Catalina.sh /etc/init.d/tomcat 

2.2. Edit /etc/init.d/tomcat

vi /etc/init.d/tomcat 

Add the following two lines after the starting line of the file [#!/bin/sh]:

# chkconfig: 2345 10 90
# description:Tomcat8 service 

Remark:
2345 indicates that the runlevels of this service are 2, 3, 4 and 5;

The second number is the start priority, with values ​​from 0 to 99; the third number is the stop priority, with values ​​from 0 to 99.

Add the following two variables CATALINA_HOME and JAVA_HOME after the above two lines

CATALINA_HOME=$installation path/apache-tomcat-8.0.35

JAVA_HOME=$installation path/jdk1.8.0_131

The added completed configuration is as follows:

# chkconfig: 2345 10 90
# description:Tomcat8 service
CATALINA_HOME=/server/apache-tomcat-8.0.52
JAVA_HOME=/usr/java/jdk1.8.0_191 
  1. Set tomcat execution permissions
chmod 755 /etc/init.d/tomcat 
  1. Set up the service to run
chkconfig --add tomcat 
  1. Add the tomcat service to the boot process
chkconfig tomcat on 
  1. Start and stop the tomcat command
service tomcat start/stop 
  1. Optimize tomcat

Edit /etc/init.d/tomcat
Add the following command to the first line (the memory allocation size depends on the machine) as shown in the figure
CATALINA_OPTS="$CATALINA_OPTS -server -Xms1G -Xmx6G -XX:+UseG1GC -Dfile.encoding=UTF-8"

as follows:

#!/bin/sh
# chkconfig: 2345 10 90
# description:Tomcat8 service
CATALINA_HOME=/home/tomcat8
JAVA_HOME=/home/jdk8
CATALINA_OPTS="$CATALINA_OPTS -server -Xms1G -Xmx6G -XX:+UseG1GC -Dfile.encoding=UTF-8" 
RELATED ARTICLES

Most Popular

Recent Comments