zoukankan      html  css  js  c++  java
  • Linux Tomcat 使用相关命令 Tomcat启动 查看tomcat运行日志 查看Tomcat进程 杀死Tomcat进程 查看Tomcat占据的端口,统计时间设置

    1、Tomcat启动、停止

    首先进入tomcat 所在bin目录cd /usr/local/apache-tomcat-9.0.35/bin (需根据个人tomcat目录进入)
    关闭tomcat服务: ./shutdown.sh 或则 sh shutdown.sh  
     启动tomcat:
    (1)给bin文件夹可执行权限:chmod -R 777 文件目录

    (2)执行./startup.sh 看不见日志的启动方式 或则 sh startup.sh

    (3)执行./catalina.sh 可以看见启动日志的启动方式

    2、查看正在运行的Tomcat进程

    (1)ps aux | grep tomcat
    (2)ps -ef | grep tomcat

    3、杀死Tomcat进程

      通过查看运行的Tomcat进程后 可对 进程进行kill
      kill -9 1234 (kill -9 进程ID)

    4、查看Tomcat占据的端口  

      netstat -nat 或则 netstat -apn (查看所有的端口)
      netstat -anlp | grep 12345 或则 netstat -anop | grep 12345 (根据进程号查看端口号)
      lsof -i:80 (通过端口号,查看其所属的进程号相关信息)

    5、查看tomcat运行日志

      先切换到:cd /home/server/Tomcat/logs (需根据个人tomcat目录进入)
      tail -f catalina.out (实时查看运行日志)
      Ctrl+c 是退出tail命令。

    6、防火墙设置端口

    cat /proc/version Linux 查看当前操作系统版本信息

    iptables -L -n 查看当前iptables(防火墙)规则
    添加指定端口到防火墙中
    iptables -I INPUT -p 协议 --dport 端口号 -j ACCEPT
    #iptables -I INPUT -p udp --dport 161 -j ACCEPT

    一、Nginx通过$upstream_response_time $request_time统计请求和后台服务响应时间


    nginx.conf使用配置方式:

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"'
    '$connection $upstream_addr '
    'upstream_response_time $upstream_response_time request_time $request_time ';


    $request_time和$upstream_response_time之间差别:

    $request_time包含了用户数据接收时间,而真正程序的响应时间应该用$upstream_response_time
    所以如果用户网络较差,或者传递数据较大时,$request_time会比$upstream_response_time大很多
    详细参考:http://wuzhangshu927.blog.163.com/blog/static/114224687201310674652147/


    二、Tomcat通过%D或%T统计请求响应时间

    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 &quot;%r&quot; %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

     

    三、通过awk命令辅助统计access.log

    1.简单统计nginx访问日志access log每分钟请求数

    awk -F: '{count[$2":"$3]++} END {for (minute in count) print minute, count[minute]}' /usr/local/nginx/logs/access.log | sort > count.log

    结果如下所示(count.log)
    18:30 2086
    18:31 2184
    18:32 2176
    18:33 2122
    18:34 2128
    18:35 2179
    ...

    参考:http://huoding.com/2013/01/26/215

     

    2.统计请求响应时间超过10s的记录

    awk '($NF > 10){print $0}' /usr/local/tengine/logs/cut-log/access_2015-01-12.log >t10_0112.log

    更多awk命令统计访问日志参考:http://www.ibm.com/developerworks/cn/linux/l-cn-awk-httplog/


    #iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

  • 相关阅读:
    golang并发
    golang接口
    golang方法
    golang函数
    微信小程序请求封装
    使用vue实现打印功能时出现多余空白页的问题
    mybatis 基本配置
    sql调优
    触发器 索引
    收藏 故事形式讲解javaScript中创建对象和Java创建对象的区别
  • 原文地址:https://www.cnblogs.com/dipak/p/13055445.html
Copyright © 2011-2022 走看看