发表于: 2020-05-18 21:05:09
1 1409
今天完成的事情:
1.tomcat 设置 accesslog
tomcat 的 accessLog 一直都在记录,只需要修改一下增加响应请求时间
修改 server.xml 文件:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u [%{yyyy-MM-dd HH:mm:ss}t] %{X-Real_IP}i "%r" %s %b %D %F" />
%D - 官方解释:Time taken to process the request, in millis,处理请求的时间,以毫秒为单位
%T - 官方解释:Time taken to process the request, in seconds,处理请求的时间,以秒为单位
%F - 官方解释:Time taken to commit the response, in millis,提交响应的时间,以毫秒为单位
详细说明:http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access_Logging
记录如下(最后一列为响应时间,可以看到刚启动后第一次请求响应较慢):
183.13.189.69 - - [2020-05-18 17:20:07] - "GET /disciple/44 HTTP/1.1" 200 372 1047 1044
183.13.189.69 - - [2020-05-18 17:21:31] - "GET /disciple/45 HTTP/1.1" 200 371 17 15
183.13.189.69 - - [2020-05-18 17:21:33] - "GET /disciple/45 HTTP/1.1" 200 371 9 9
183.13.189.69 - - [2020-05-18 17:21:34] - "GET /disciple/45 HTTP/1.1" 200 371 15 14
183.13.189.69 - - [2020-05-18 17:24:38] - "POST /disciple HTTP/1.1" 200 33 129 129
183.13.189.69 - - [2020-05-18 17:27:08] - "DELETE /disciple/62 HTTP/1.1" 200 22 13 13
183.13.189.69 - - [2020-05-18 17:28:54] - "PUT /disciple HTTP/1.1" 200 22 12 11
183.13.189.69 - - [2020-05-18 17:29:11] - "GET /disciple/45 HTTP/1.1" 200 374 12 12
2.jetty 记录 accesslog
jetty 的比较麻烦,我折腾了很久,因为它默认是没有任何日志文件的,中文资料又不齐全,最后我是参考了官方文档:https://www.eclipse.org/jetty/documentation/current/configuring-jetty-request-logs.html
(a)开启日志模块
java -jar start.jar --add-to-start=requestlog
(b)修改 start.ini 文件选取需要的记录项目(上面命令会把日志记录模块配置文件添加到 start.ini 文件末尾)
# ---------------------------------------
# Module: requestlog
# Enables a NCSA style request log.
# ---------------------------------------
--module=requestlog
## Logging directory (relative to $jetty.base)
jetty.requestlog.dir=logs
## File path
jetty.requestlog.filePath=${jetty.requestlog.dir}/yyyy_mm_dd.request.log
## Date format for rollovered files (uses SimpleDateFormat syntax)
jetty.requestlog.filenameDateFormat=yyyy_MM_dd
## How many days to retain old log files
jetty.requestlog.retainDays=90
## Whether to append to existing file
jetty.requestlog.append=true
## Whether to use the extended log output
# jetty.requestlog.extended=true
## Whether to log http cookie information
# jetty.requestlog.cookies=true
## Timezone of the log entries
jetty.requestlog.timezone=Asia/Shanghai
## Whether to log LogLatency
jetty.requestlog.loglatency=true
日志记录如下(为了方便比较,发送顺序与次数和 tomcat 日志一样,最后一列为响应时间,可以看出刚启动的第一次响应比较慢,但是比 tomcat 要好(不严谨,但是单次比较结果就是这样)):
183.13.189.69 - - [18/May/2020:20:39:46 +0800] "GET /disciple/45 HTTP/1.1" 200 362 810
183.13.189.69 - - [18/May/2020:20:39:54 +0800] "GET /disciple/45 HTTP/1.1" 200 362 31
183.13.189.69 - - [18/May/2020:20:40:09 +0800] "GET /disciple/45 HTTP/1.1" 200 362 12
183.13.189.69 - - [18/May/2020:20:40:10 +0800] "GET /disciple/45 HTTP/1.1" 200 362 8
183.13.189.69 - - [18/May/2020:20:40:19 +0800] "POST /disciple HTTP/1.1" 200 22 75
183.13.189.69 - - [18/May/2020:20:40:41 +0800] "DELETE /disciple/45 HTTP/1.1" 200 12 19
183.13.189.69 - - [18/May/2020:20:40:58 +0800] "PUT /disciple HTTP/1.1" 200 12 12
183.13.189.69 - - [18/May/2020:20:41:12 +0800] "GET /disciple/63 HTTP/1.1" 200 362 11
遇到的问题:
1. tomcat 在服务器上启动很慢(需要6分钟)
解决方法:修改 jdk 的随机数发生器
- 修改$JAVA_HOME/jre/lib/security/java.security
- 将securerandom.source=file:/dev/random修改为securerandom.source=file:/dev/./urandom
- 大概的原因就是urandom的安全性没random高,但是random需要花费时间去生成随机数。
修改后改善明显,启动只需要 8 秒。
2. resin 还是无法正常运行
昨天忘记上传一个截图,放好 war 包之后 resin 一直不正常,连续刷新 webapps 目录结果如下:
明天的计划:
1. 编写 jetty tomcat 部署脚本
2. 尝试解决 resin 部署的问题
评论