Note: knowledge comes from ob
One, install jdk and tomcat
#安装jdk
tar -xf jdk-8u45-linux-x64.tar.gz -C /application
ln -s /application/jdk1.8.0_281/ /application/jdk
#配置环境变量
cat >>/etc/profile<<'EOF'
export JAVA_HOME=/application/jdk
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
export TOMCAT_HOME=/application/tomcat
EOF
source /etc/profile
java -version
Explanation of'EOF':
1,你用-eof,真的测试了有效吗
2,确定eof要用单引号还是双引号,单引号,会让变量保留到远程主机上解析;双引号,会让变量在本机解析
#A little special jdk after decompression, their users and user groups are displayed as numbers, you can directly modify the permissions to chown -R root.root /application/jdk
#安装tomcat
tar xf apache-tomcat-8.5.63.tar.gz -C /application/
ln -s /application/apache-tomcat-8.5.63/ /application/tomcat
#查看版本信息
/application/tomcat/bin/version.sh
1.1 tomcat service management
#启动tomcat
/application/tomcat/bin/startup.sh
ss -lntup | grep java
1.2tomcat catalog description
1.3 tomcat management terminal
Modify conf/tomcat-users.xml
<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
</tomcat-users>
#关闭 再启动tomcat
/application/tomcat/bin/shutdown.sh
ps -ef | grep java
/application/tomcat/bin/startup.sh
In tomcat 8.5, the management side is more stringent, and it will continue to be modified :
he currently only allows 127 segments to be accessed, using regular PCRE. Modify the file found below, change 127 to \d+ or specify the network segment number. After the change, find to check again. Restart tomcat
[root@lvs1-138 tomcat]# find -type f -name "*.xml" | xargs grep '127'
./webapps/host-manager/META-INF/context.xml: allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
./webapps/host-manager/WEB-INF/manager.xml: allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
./webapps/manager/META-INF/context.xml: allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
Original:
Modified:
At this time, click the three buttons such as Status Server and enter the account password tomcat / tomcat to access
1.4 tomcat log (catalina.out)
catalina.out和catalina.日期.log
catalina.out在被切割后内容不会被清空|
1.5 tomcat deployment application and method
1. If the war package is developed for you , put the war package into the tomcat webapps for automatic decompression and automatic deployment.
2. If the development for you is a jar package , it is equivalent to putting tomcat into the jar.
Run the jar package instruction: java -jar xxxx.jar
3. The default web path is /application/tomcat/webapps/
Upload a jpress.war
cp /app/tools/jpress.war /application/tomcat/webapps/
#此时会自动解压
Install jpress
Install MariaDB "https://www.cnblogs.com/yhongji/p/9783065.html"
create database jpress charset utf8;
grant all on jpress.* to jpress@'localhost' identified by '123456';
grant all on jpress.* to jpress@'192.168.%.%' identified by '123456';
select user,host from mysql.user;
Windows webpage visit 192.168.26.138:8080/jpress to install
http://192.168.26.138:8080/jpress/admin/index (management side)
http://192.168.26.138:8080/jpress/ (website homepage)
database configuration file : Jboot.properties (generally called db.properties)
END
Two, tomcat configuration file server.xml
/application/tomcat/conf/server.xml
一、
<Server port="8005" shutdown="SHUTDOWN">
tomcat关闭端口 ,当telnet 127.0.0.1 8005 ,输入SHUTDOWN后,tomcat就被关闭了(生产环境需改变端口,以及shutdown=""的值, 如shutdown="OBSHUTDOWN")
二、
用户管理端 认证模式 用户名密码模式
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" /> 用户管理配置文件
</GlobalNamingResources>
三、
web端口
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
指定的web站点目录。
appBase:这个目录下面的子目录将自动被部署为应用,且war文件将被自动解压缩并部署为应用,默认为tomcat下webapps目录,如果不想访问默认ROOT目录,修改这里,同理如果想访问配置目录下应用为默认应用,在此目录下新增ROOT目录文件夹。
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
Configure the <host> content of the tomcat virtual host (equivalent to the nginx server{} module).
When accessing 192.168.26.138:8080, the jsp page he will access is as follows:
https://www.cnblogs.com/wei-lai/p/6249595.html "The relationship between tomcat-ROOT and webapps, some questions about deployment"
Three, server.xml optimization parameters
original:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Modified:
<Connector port="8080" protocol="HTTP/1.1"
maxThreads="500" #最大线程数量 200~400之间 ,但不是越大越好,比如有次设置了3000,但一般是2000出头,单次请求的响应时间会急剧增加。
acceptCount="500" #一般与maxThreads一直
minSpareThreads="10" #空闲时候 最小的线程数量
enableLookups="false" #禁止DNS逆向查询 route -n , arp -n
compression="on" #开启压缩,静态资源html js css
compressionMinSize="2048" #压缩文件 最小2048字节
#压缩哪些类型的文件
compressableMimeType="text/html,text/plain,text/css,application/javascript,application/json,application/x-font-ttf,application/x-font-otf"
disableUploadTimeout="true" #关闭上传时间超时
acceptorThreadCount="2" #用于接收连接的线程的数量,默认值是1。如果是多核 CPU 一般配置为 2.
connectionTimeout="20000"
redirectPort="8443" />
About the explanation of compressionMinSize="2048" above
Four, JVM optimization parameters
4.1 java startup parameters (catalina.sh)
/application/tomcat/bin/catalina.sh, insert approximately at line 112
JAVA_OPTS='-Xms1024m -Xmx1024m -Xloggc:/var/log/tomcat_gc.log'
Optimized: There is also annotated AJP port 8009
4.2 Optimization for jar package startup
For the jar package:
java -jar xxx.jar -Xms1024m -Xmx1024, -Xloggc:/var/log/tomcat_gc.log
5. Security optimization (abbreviated)
split line
END