Installation and configuration of Tomcat server (tar.gz)

Posted by simonrs on Sat, 02 May 2020 05:36:44 +0200

1, Installation

Install JDK before installing Tomcat. See JDK installation (bin)

1. Download and unzip Tomcat
[root@bogon src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.0.M22/bin/apache-tomcat-9.0.0.M22.tar.gz
[root@bogon src]# tar xvf apache-tomcat-9.0.0.M22.tar.gz
2. Consider the Tomcat cluster later, so rebuild the new directory and move the extracted Tomcat in
[root@bogon src]# mkdir /usr/local/tomcat_cluster
[root@bogon src]# mkdir /usr/local/tomcat_cluster/tomcat1
[root@bogon src]# mv ./apache-tomcat-9.0.0.M22/ /usr/local/tomcat_cluster/tomcat1
[root@bogon src]# ls /usr/local/tomcat_cluster/tomcat1/
bin  conf  lib  LICENSE  logs  NOTICE  RELEASE-NOTES  RUNNING.txt  temp  webapps  work
3. Start Tomcat for testing
[root@bogon bin]# ./startup.sh
Using CATALINA_BASE:   /usr/local/tomcat_cluster/tomcat1
Using CATALINA_HOME:   /usr/local/tomcat_cluster/tomcat1
Using CATALINA_TMPDIR: /usr/local/tomcat_cluster/tomcat1/temp
Using JRE_HOME:        /usr/local/src/jdk1.8.0_131
Using CLASSPATH:       /usr/local/tomcat_cluster/tomcat1/bin/bootstrap.jar:/usr/local/tomcat_cluster/tomcat1/bin/tomcat-juli.jar
Tomcat started.

See if there are processes

[root@bogon bin]# ps aux|grep tomcat
root       2672  0.8 12.1 2304280 121152 pts/0  Sl   09:19   0:16 /usr/local/src/jdk1.8.0_131/bin/java -Djava.util.logging.config.file=/usr/local/tomcat_cluster/tomcat1/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -classpath /usr/local/tomcat_cluster/tomcat1/bin/bootstrap.jar:/usr/local/tomcat_cluster/tomcat1/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat_cluster/tomcat1 -Dcatalina.home=/usr/local/tomcat_cluster/tomcat1 -Djava.io.tmpdir=/usr/local/tomcat_cluster/tomcat1/temp org.apache.catalina.startup.Bootstrap start
root       3393  0.0  0.0 112664   976 pts/0    R+   09:50   0:00 grep --color=auto tomcat

Viewing the process port, you can see that the port number is 8080

[root@bogon bin]# netstat -lnp|grep java
tcp6       0      0 :::8080                 :::*                    LISTEN      2672/java
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      2672/java
tcp6       0      0 :::8009                 :::*                    LISTEN      2672/java

In particular, tomcat calls Java, so the displayed process is a java process.

2, Add as system service

1. Create startup script
[root@bogon bin]# pwd
/usr/local/tomcat_cluster/tomcat1/bin
[root@bogon bin]# cp catalina.sh /etc/init.d/tomcat

Add the following lines under ×! / bin/bash:

#chkconfig:345 23 77

#description:tomcat server

# Source Function Library
. /etc/init.d/functions

JAVA_HOME=/usr/local/src/jdk1.8.0_131
CATALINA_HOME=/usr/local/tomcat_cluster/tomcat1
2. Modify its permissions and start up
[root@bogon bin]# chkconfig --add tomcat
[root@bogon bin]# chmod 755 /etc/init.d/tomcat
[root@bogon bin]# chkconfig tomcat on
3. Start Tomcat
[root@bogon bin]# systemctl start tomcat
[root@bogon bin]# systemctl status tomcat
● tomcat.service - SYSV: tomcat server
   Loaded: loaded (/etc/rc.d/init.d/tomcat; bad; vendor preset: disabled)
   Active: active (running) since One 2017-07-24 10:40:55 CST; 21s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 4070 ExecStop=/etc/rc.d/init.d/tomcat stop (code=exited, status=0/SUCCESS)
  Process: 4092 ExecStart=/etc/rc.d/init.d/tomcat start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/tomcat.service
           ├─3917 /usr/local/src/jdk1.8.0_131/bin/java -Djava.util.logging.config.file=/usr/loca...
           └─4097 /usr/local/src/jdk1.8.0_131/bin/java -Djava.util.logging.config.file=/usr/loca...

7month 24 10:40:55 bogon systemd[1]: Starting SYSV: tomcat server...
7month 24 10:40:55 bogon tomcat[4092]: Using CATALINA_BASE:   /usr/local/tomcat_cluster/tomcat1
7month 24 10:40:55 bogon tomcat[4092]: Using CATALINA_HOME:   /usr/local/tomcat_cluster/tomcat1
7month 24 10:40:55 bogon tomcat[4092]: Using CATALINA_TMPDIR: /usr/local/tomcat_cluster/tomcat1/temp
7month 24 10:40:55 bogon tomcat[4092]: Using JRE_HOME:        /usr/local/src/jdk1.8.0_131
7month 24 10:40:55 bogon tomcat[4092]: Using CLASSPATH:       /usr/local/tomcat_cluster/tomcat....jar
7month 24 10:40:55 bogon tomcat[4092]: Tomcat started.
7month 24 10:40:55 bogon systemd[1]: Started SYSV: tomcat server.
Hint: Some lines were ellipsized, use -l to show in full.

In addition, tomcat does not support restart. If you want to restart, you need to close it first and then start it.

3, Modify tomcat default port

Edit profile: server.xml

[root@bogon conf]# pwd
/usr/local/tomcat_cluster/tomcat1/conf
[root@bogon conf]# ls
Catalina  catalina.policy  catalina.properties  context.xml  jaspic-providers.xml  jaspic-providers.xsd  logging.properties  server.xml  tomcat-users.xml  tomcat-users.xsd  web.xml
[root@bogon conf]# vim server.xml

Locate the following configuration segment:

Change the 8080 to 80, and then restart the tomcat service.

Topics: Tomcat Java Apache xml