CentOS Linux release 7.3.1611 (Core) 3.10.0-514.16.1.el7.x86_64
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 is
server-jre-7u80-linux-x64.tar.gz。 Download completed, unzip to
/usr/local/, it should be noted that after decompression
server-jre-7u80-linux-x64.tar.gzThe name is
jdk1.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 JAVA_HOME=/usr/local/jdk1.7.0_80 PATH=$JAVA_HOME/bin:$PATH CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME export PATH export CLASSPATH EOF 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
apache-tomcat-7.0.72.tar.gzAnd unzip, rename the unzipped directory to
tomcat7, and move to
/optThen create the run environment file:
JAVA_HOME=/usr/local/jdk1.7.0_80 PATH=$JAVA_HOME/bin:$PATH CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME export PATH export CLASSPATH
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
The settings are as follows, but you may need to adjust it according to your memory capacity
CATALINA_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 [Unit] Description=Apache Tomcat Web Application Container After=syslog.target network.target [Service] Type=forking Environment=CATALINA_PID=/opt/tomcat7/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat7 Environment=CATALINA_BASE=/opt/tomcat7 Environment='CATALINA_OPTS=-Xms128M -Xmx512M -server -XX:+UseParallelGC' Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom' ExecStart=/opt/tomcat7/bin/startup.sh ExecStop=/bin/kill -15 $MAINPID User=tomcat Group=tomcat UMask=0007 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
Then reload the following service units:
All settings are now complete.
systemctl start tomcat [[email protected] ~]# curl -I 127.0.0.1:8080 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 127.0.0.1:8080 curl: (7) Failed connect to 127.0.0.1:8080; Connection refused