Linux下配置Tomcat服务器

一、配置Tomcat服务器

1.根据教程在Centos 7上配置tomcat8服务器

启动、关闭tomcat命令:
/usr/local/myTomcat/tomcat/bin/startup.sh
/usr/local/myTomcat/tomcat/bin/shutdown.sh

2.Tomcat的开机启动、关闭

  1. cd /etc/init.d

  2. chmod 755 /etc/rc.d/init.d/tomcat 文件提权

  3. vim tomcat 进入vim编辑界面

  4. 写入启动shell脚本

         #!/bin/bash  
         # This is the init script for starting up the  
         #  Jakarta Tomcat server  
         #  
         # chkconfig: 345 91 10  
         # description: Starts and stops the Tomcat daemon.  
         #  
    
         # Source function library.  
         . /etc/rc.d/init.d/functions  
    
         # Get config.  
         . /etc/sysconfig/network  
    
         # Check that networking is up.  
         [ "${NETWORKING}" = "no" ] && exit 0  
    
         export JAVA_HOME=/usr/local/javaweb/jdk1.8.0_192 #自己的jdk安装目录
         tomcat_home=/usr/local/myTomcat/tomcat  #自己的tomcat安装目录
         startup=$tomcat_home/bin/startup.sh  
         shutdown=$tomcat_home/bin/shutdown.sh  
    
         start(){  
            echo -n "Starting Tomcat service:"  
            cd $tomcat_home  
            $startup  
            echo "tomcat is succeessfully started up"  
         }  
    
         stop(){  
            echo -n "Shutting down tomcat: "  
            cd $tomcat_home  
            $shutdown  
            echo "tomcat is succeessfully shut down."  
         }  
    
         status(){  
             numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l`  
             if [ $numproc -gt 0 ]; then  
                echo "Tomcat is running..."  
             else  
                echo "Tomcat is stopped..."  
             fi  
         }  
    
         restart(){  
            stop  
            start  
         }    
         # See how we were called.  
         case "$1" in  
         start)  
            start  
            ;;  
         stop)  
            stop  
            ;;  
         status)  
            status  
            ;;  
         restart)  
            restart  
            ;;  
         *)  
            echo $"Usage: $0 {start|stop|status|restart}"  
            exit 1  
         esac
    
  5. 将文件加入到服务队列中

chkconfig --add tomcat
  1. 查看tomcat 文件是否加入服务列表成功
chkconfig --list
  1. 设置服务开机自启动
    chkconfig tomcat on

3.利用Tomcat部署静态页面

  1. ../tomcat/conf/server.xml
  2. vim 写入
<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false"  xmlNamespaceAware="false">    
	<Context path="" docBase="file" debug="0" reloadable="true" crossContext="true"/>
	<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="tot_log." suffix=".txt" timestamp="true"/>       
</Host>

// docBase= \webapps\file\xxx.html
  1. 浏览器访问localhost:8080/xxx.html
    静态页面

4.查看日志

- cd home/tomcat/logs
//切换到日志目录
 - ls
//查看日志类型
 - tail -f catalina.out
//查看运行日志
 - tail -n xxx -f catalina.out
//查看最近xxx行日志内容
 - Ctrl+c 是退出tail命令
 - cat localhost.yyyy-mm-dd.log l grep 关键词
//通过关键词搜索查看日志
 - cat localhost.yyyy-mm-dd.log l grep 'xxxx-yy-zz'
//查看固定时间日志

5.日志审计

python脚本

#!/usr/bin/env python
# coding=utf-8
import re
 
 
def find_error_log(log_name):
    original_file = open(log_name, encoding='utf-8')
    extract = []
    for line_data in original_file:
        error = re.search('error', line_data, re.IGNORECASE)
        exception = re.search('exception', line_data, re.IGNORECASE)
        java = re.search('at java', line_data, re.IGNORECASE)
        com = re.search('at com', line_data, re.IGNORECASE)
        org = re.search('at org', line_data, re.IGNORECASE)
        sun = re.search('at sun', line_data, re.IGNORECASE)
        if error or exception or java or com or org or sun:
            log_str = line_data
            extract.append(log_str)
    # 生成输出文档位置
    errlog = 'C:\\Users\\xxx\\Desktop\\checkLog\\out\\catalinaError.txt'
    new_file = open(errlog, 'w')
    new_file.writelines(extract)
    new_file.flush()
    new_file.close()
    original_file.close()
    return "返回啥都行"
 
 
 
if __name__ == '__main__':
    # 原日志位置
    returnMSG = find_error_log('C:\\Users\\xxx\\Desktop\\checkLog\\into\\catalina.out-20200424')
    print(returnMSG)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值