tomcat部署
tomcat版本:tomcat-8.5.79
下载地址:https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.79/bin/apache-tomcat-8.5.79.tar.gz
jdk版本:jdk-1.8
解压安装包到目录
tar xf apache-tomcat-8.5.79.tar.gz -C /
tar xf jdk-8u151-linux-x64.gz -C /usr/local
建立tomcat用户
useradd tomcat
设置环境变量
vim /etc/profile
JAVA_HOME=/usr/local/jdk-1.8 PATH=$JAVA_HOME/bin:$PATH export JAVA_HOME PATH
source /etc/profile
env |grep JAVA
JAVA_HOME=/usr/local/jdk-1.8
测试java环境
java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
也可将java、tomcat的环境变量配置在catalina.sh中
vim /tomcat/bin/catalina.sh
JAVA_HOME=/tomcat/tomcat-10/jdk-17.0.1/
配置tomcat环境变量(全局变量)
vim /etc/profile
CATALINA_HOME=/etc/tomcat7 export CATALINA_HOME
在多实例中,可以配置在catalina.sh中,只对该tomcat实例生效,防止各实例间的变量影响
vim /tomcat/bin/catalina.sh
JAVA_HOME=/tomcat/jdk1.8 PATH=$JAVA_HOME/bin:$PATH CATALINA_HOME=/tomcat/tomcat-10
配置session超时时间
vim /tomcat/conf/web.xml
将30替换成10:
<session-config> <session-timeout>10</session-timeout> </session-config>
配置Xms、Xmx,两边数值要相同
vim /tomcat/bin/catalina.sh
将JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS"替换成以下内容:
JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -Djava.net.preferIPv4Stack=true -Xms2048m -Xmx2048m"
配置端口
vim /tomcat/conf/server.xml
<Server port="8005" shutdown="SHUTDOWN"> #8005端口,用来关闭tomcat程序 <Connector port="8080" protocol="HTTP/1.1" #8080端口:http连接的端口,用来访问 connectionTimeout="20000" redirectPort="8443" /> #8443端口:https连接的端口 <!--Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /--> #8009端口:tomcat负责和其他的HTTP服务器建立连接,tomcat+apache集群时调用此端口,一般情况下, #如果是nginx+tomcat集群,AJP端口(8009)用不上,注释即可,否则在运行项目包时会报错。 #tomcat8以上的版本默认是注释掉的。 <Host name="localhost" appBase="webapps" #网站主目录 unpackWARs="true" autoDeploy="true">
配置JMX监控
a.新建setenv.sh文件
vim /tomcat/bin/setenv.sh
#本机ip JMX_OPTS_HostName="-Djava.rmi.server.hostname=10.0.16.3" #JMX调用端口 JMX_OPTS_Port="-Dcom.sun.management.jmxremote.port=2000" #JMX返回端口 JMX_OPTS_rmiPort="-Dcom.sun.management.jmxremote.rmi.port=2010" JMX_OPTS_Auth="-Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false" JMX_OPTS_Access = "-Dcom.sun.management.jmxremote.acess.file = /opt/tomcat/18080/bin/jmxremote.access" JMX_OPTS_Passwd = "-Dcom.sun.management.jmxremote.password.file = /opt/tomcat/18080/bin/jmxremote.password" JMX_OPTS = "${JMX_OPTS_Hostname} ${JMX_OPTS_Port } ${JMX_OPTS_rmiPort} ${JMX_OPTS_Auth} ${JMX_OPTS_Acess} ${JMX_OPTS_Passwd}" export CATALINA_OPTS="$CATALINA_OPTS ${JMX_OPTS}"
b.新建jmxremote.access及jmxremote.password文件并写入如下内容
vim /tomcat/bin/jmxremote.access
ZABJMX readonly
vim /tomcat/bin/jmxremote.password
ZABJMX Zab@jmx123
设置相关文件权限
chown -R tomcat:tomcat /tomcat/
chmod 600 /tomcat/18080/bin/jmxremote.access
chmod 600 /tomcat/18080/bin/jmxremote.password
4、启动tomcat
启动脚本
sh /etc/tomcat/bin/startup.sh
Using CATALINA_BASE: /etc/tomcat7 Using CATALINA_HOME: /etc/tomcat7 Using CATALINA_TMPDIR: /etc/tomcat7/temp Using JRE_HOME: /usr/local/jdk Using CLASSPATH: /etc/tomcat7/bin/bootstrap.jar:/etc/tomcat7/bin/tomcat-juli.jar Tomcat started.
查看tomcat端口情况
netstat -lntp | grep "java"
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 21977/java
tcp6 0 0 :::8009 :::* LISTEN 21977/java
tcp6 0 0 :::8080 :::* LISTEN 21977/java
查看tomcat版本
sh /tomcat/tomcat-10/bin/version.sh
If you encounter issues starting up Confluence, please see the Installation guide at http://confluence.atlassian.com/display/DOC/Confluence+Installation+Guide
Server startup logs are located in /opt/wiki/wiki/logs/catalina.out
---------------------------------------------------------------------------
Using Java: /opt/wiki/wiki/jre//bin/java
2022-04-25 19:44:04,853 INFO [main] [atlassian.confluence.bootstrap.SynchronyProxyWatchdog] A Context element for ${confluence.context.path}/synchrony-proxy is found in /opt/wiki/wiki/conf/server.xml. No further action is required
---------------------------------------------------------------------------
Using CATALINA_BASE: /opt/wiki/wiki
Using CATALINA_HOME: /opt/wiki/wiki
Using CATALINA_TMPDIR: /opt/wiki/wiki/temp
Using JRE_HOME: /opt/wiki/wiki/jre/
Using CLASSPATH: /opt/wiki/wiki/bin/bootstrap.jar:/opt/wiki/wiki/bin/tomcat-juli.jar
Using CATALINA_PID: /opt/wiki/wiki/work/catalina.pid
Server version: Apache Tomcat/9.0.22
Server built: Jul 4 2019 14:20:06 UTC
Server number: 9.0.22.0
OS Name: Linux
OS Version: 3.10.0-1160.41.1.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_202-b08
JVM Vendor: Oracle Corporation
配置访问测试页面
vim /etc/tomcat7/webapps/ROOT/index.jsp
<%@ page language="java" %> <%@ page import="java.util.*" %> <html> <head> <title>JSP test page.</title> </head> <body> <% out.println("Hello,world!"); %> </body> </html>