java deployment: CentOS under 7 Tomcat Installation and Configuration Guide (Tomcat boot)

I. Introduction

1, the main content tutorial

  • Tomcat installation and basic configuration
  • Tomcat boot configuration

2, the scope of the tutorial and environment information

  • Scope
software tools Imprint
CentOS CentOS 7
Tomcat Tomcat 7 +
  • This tutorial Environmental Information
software tools Imprint
CentOS CentOS 7
Tomcat Tomcat 8.5
JDK 1.8

3, ready to work?

Two, Tomcat deployment process

1, Tomcat download and configuration directory

  • Download Tomcat
#打开下载目录
cd /home/download

#下载tar包
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz

Tomcat7 official website Download: https://tomcat.apache.org/download-70.cgi
Tomcat8 official website to download address: https://tomcat.apache.org/download-80.cgi

  • Configure tomcat directory
# 创建tomcat目录
sudo mkdir /usr/tomcat

#解压到指定目录
sudo tar -zvxf apache-tomcat-8.5.24.tar.gz -C /usr/tomcat

#改名目录名为tomcat8
mv /usr/tomcat/apache-tomcat-8.5.24 /usr/tomcat/tomcat8

2, Tomcat configuration specified JDK

If the system default JDK version JDK 1.8.x, this step may be omitted
if the system needs to deploy multiple Tomcat, for example: Tomcat 7 + JDK 7, Tomcat 8 + JDK 8 it is required to coexist as follows:

This machine is the default Java version can be viewed by command java -version

  • Modify the file catalina.sh
#修改catalina.sh
vi /usr/tomcat/tomcat8/bin/catalina.sh

#增加如下配置:

export JAVA_HOME=/usr/java/jdk1.8.0_151
  • Modify setclasspath.sh file
#修改setclasspath.sh
vi /usr/tomcat/tomcat8/bin/setclasspath.sh

#增加如下配置:

export JAVA_HOME=/usr/java/jdk1.8.0_151

Which /usr/java/jdk1.8.0_151, because JDK8 in this catalog ken.io test server
, replace the server where the actual deployment to jdk directory

3, Tomcat port and modify firewall configuration

  • Modify the port

Non-essential operations, if need to deploy multiple Tomcat, you need to modify the port

#修改server.xml
vi /usr/tomcat/tomcat8/conf/server.xml

Find the following line, Tomcat default port is 8080, you can modify according to their needs

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> 
  • Open ports
#开放8080端口
firewall-cmd --add-port=8080/tcp --permanent && firewall-cmd --reload

#重新加载防火墙规则
firewall-cmd --reload

4, Tomcat startup and shutdown

  • Enable / Disable
#启动
cd /usr/tomcat/tomcat8/bin && sh startup.sh

#停用
cd /usr/tomcat/tomcat8/bin && sh shutdown.sh

Ip access through the browser: 8080

Third, configure Tomcat boot

Configuring Tomcat boot is very simple to configure Tomcat as a system service and can be configured to boot.

1, the configuration of Tomcat as a system service

#创建Tomcat8服务文件
vi /usr/lib/systemd/system/tomcat8.service

#tomcat8.service文件内容:

[Unit]  
Description=Tomcat8  
After=syslog.target network.target remote-fs.target nss-lookup.target  

[Service]  
Type=forking  

ExecStart=/usr/tomcat/tomcat8/bin/startup.sh
ExecReload=/usr/tomcat/tomcat8/bin/startup.sh
ExecStop=/usr/tomcat/tomcat8/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

2, configure the Tomcat service start-up

#设置Tomcat8开机启动
systemctl enable tomcat8

#启动tomcat8服务
systemctl start tomcat8

原文地址:https://ken.io/note/centos7-tomcat-setup

Guess you like

Origin www.cnblogs.com/soymilk2019/p/11696072.html