Install Tomcat to service under CentOS 7


Environmental Science:

CentOS Linux release 7.3.1611 (Core)

1. Install Java environment

JRE has the difference between serverjre and JRE. The specific difference between the two is that when serverjre is started, the default JVM is server mode, and some monitoring tools are included. For the specific difference, see Oracle site. Now a common problem is that most Java programs are developed based on Java 7, but Oracle has been updated to Java 8 for a long time, and jre8 download is provided by default on the website. However, no matter which version of JRE you want to download, you can find it here. Before downloading serverjre, you need to select accept license agreement to activate the download link. The choice here isserver-jre-7u80-linux-x64.tar.gz。 Download completed, unzip to /usr/local/, it should be noted that after decompressionserver-jre-7u80-linux-x64.tar.gzThe name isjdk1.7.0_79, but I have tested that this is different from the real JDK file. After decompression, edit/etc/profileSet the environment variable and verify that:

cat >>/etc/profile << "EOF"
#set java env
export JAVA_HOME
export PATH

source /etc/profile

java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

At this point, the Java environment installation is complete.

2. Install Tomcat

Direct downloadapache-tomcat-7.0.72.tar.gzAnd unzip, rename the unzipped directory totomcat7, and move to/optThen create the run environment file:

vim /opt/tomcat7/bin/

Content and/etc/profileTail consistent:

export JAVA_HOME
export PATH

This completes the Tomcat installation and setup.

3. Create the Tomcat running user and empower to the corresponding file.

groupadd tomcat
Useradd - M - S / bin / nologin - G Tomcat - D / opt / Tomcat Tomcat ා assume Tomcat here. If it is a production server, it is recommended to use the environment deployment account to run Tomcat
cd /opt/tomcat7
chmod -R 754 bin/
chgrp -R tomcat /opt/tomcat
chmod -R g+r conf
chmod g+x conf
chown -R tomcat webapps/ work/ temp/ logs/

At this point, the relevant empowerment is completed.

4. Edit service file

vim /etc/systemd/system/tomcat.service

The settings are as follows, but you may need to adjust it according to your memory capacityCATALINA_OPTSIn general, to set the – XMS and – Xmx options to the same, and – XMN to the – Xmx value of 1 / 4, it is recommended to set the maximum heap value to 80% of the maximum available memory:

# Systemd unit file for tomcat
Description=Apache Tomcat Web Application Container


Environment='CATALINA_OPTS=-Xms128M -Xmx512M -server -XX:+UseParallelGC'

ExecStop=/bin/kill -15 $MAINPID



Then reload the following service units:

systemctl daemon-reload

All settings are now complete.

5. Testing

systemctl start tomcat

[[email protected] ~]# curl -I
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Transfer-Encoding: chunked
Date: Tue, 06 Jun 2017 02:27:16 GMT
systemctl stop tomcat
curl -I
curl: (7) Failed connect to; Connection refused


Recommended Today

Configure Apache to support PHP in the Apache main configuration file httpd.conf Include custom profile in

In Apache’s main configuration file / conf/ http.conf Add at the bottom Include “D:workspace_phpapache-php.conf” The file path can be any In D: workspace_ Create under PHP file apache- php.conf file Its specific content is [html] view plain copy PHP-Module setup LoadFile “D:/xampp/php/php5ts.dll” LoadModule php5_module “D:/xampp/php/php5apache2_2.dll” <FilesMatch “.php$”> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch “.phps$”> SetHandler application/x-httpd-php-source </FilesMatch> […]