Detail installation of Tomcat to services under CentOS 7
- 2020-06-07 05:54:19
- OfStack
Environment:
CentOS Linux release 7.3.1611 (Core) 3.10.0-514.16.1.el7.x86_64Install the Java environment
Jre differs from ServerJre and Jre. The specific difference between the two is that when ServerJre is launched, Jvm by default is Server mode and includes a number of monitoring tools, as shown in the Oracle site. A common problem is that most JAVA programs are based on JAVA7, but Oracle has long since been updated to Java8, and the default download for Jre8 is available on the site. However, whatever version of JRE you want to download, you can find it here. Select Accept License Agreement to activate the download link before downloading ServerJre. Here's the choice
server-jre-7u80-linux-x64.tar.gz
. Download finished, unzip to
/usr/local/
And the thing to notice here is that after decompression
server-jre-7u80-linux-x64.tar.gz
The name is
jdk1.7.0_79
But I have tested it and it is different from the real JDK file. After unzipping, edit
/etc/profile
Set environment variables 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 is installed.
2. Install tomcat
Direct download
apache-tomcat-7.0.72.tar.gz
And unzip, rename the unzip directory to
tomcat7
And moved
/opt
Next, then create the run environment file:
vim /opt/tomcat7/bin/setenv.sh
Content and /etc/profile tail remain 1 to:
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 installation and setup of tomcat.
3. Create tomcat run user and assign weights to the corresponding file.
groupadd tomcat
useradd -M -s /bin/nologin -g tomcat -d /opt/tomcat tomcat # Assume here that tomcat If it is a production server, it is recommended to use the environment deployment account to run it tomcat.
cd /opt/tomcat7
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 complete.
4. Edit service files
vim /etc/systemd/system/tomcat.service
The Settings are as follows, but you may need to adjust them according to your memory capacity
CATALINA_OPTS
To set the -ES64en and -ES65en options to the same, while -ES66en is 1/4 of the -ES67en value, it is recommended that the maximum heap be set 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 service unit under 1:
systemctl daemon-reload
This completes the setup.
5. Test
systemctl start tomcat
[root@localhost ~]# 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
To complete.