JAVA企业级应用TOMCAT实战
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA企业级应用TOMCAT实战相关的知识,希望对你有一定的参考价值。
使用普通用户运行
使用普通用户来部署服务是比较安全的做法
[[email protected] application]# useradd -u 1001 tomcat [[email protected] application]# passwd tomcat Changing password for user tomcat. New password: Retype new password: passwd: all authentication tokens updated successfully.
切换到tomcat来执行 [[email protected] application]# chown -R tomcat:tomcat /application/jdk [[email protected] application]# chown -R tomcat:tomcat /application/tomcat/ [[email protected] application]# su - tomcat [[email protected]-node1 ~]$ cd /application/tomcat/bin/ [[email protected]-node1 bin]$ sh startup.sh #启动脚本 Using CATALINA_BASE: /application/tomcat Using CATALINA_HOME: /application/tomcat Using CATALINA_TMPDIR: /application/tomcat/temp Using JRE_HOME: /application/jdk Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar Tomcat started.
[[email protected]node1 tomcat]$ pwd /application/tomcat [[email protected]-node1 tomcat]$ ls -l total 100 drwxr-xr-x 5 tomcat tomcat 4096 Apr 9 18:53 bin drwxr-xr-x 6 tomcat tomcat 4096 Apr 8 10:49 conf drwxr-xr-x 2 tomcat tomcat 4096 Apr 8 05:49 lib -rw-r--r-- 1 tomcat tomcat 57011 Sep 28 2015 LICENSE drwxr-xr-x 2 tomcat tomcat 4096 Apr 9 18:39 logs -rw-r--r-- 1 tomcat tomcat 1444 Sep 28 2015 NOTICE -rw-r--r-- 1 tomcat tomcat 6741 Sep 28 2015 RELEASE-NOTES -rw-r--r-- 1 tomcat tomcat 16204 Sep 28 2015 RUNNING.txt drwxr-xr-x 2 tomcat tomcat 29 Apr 8 05:49 temp drwxr-xr-x 8 tomcat tomcat 108 Apr 8 09:14 webapps drwxr-xr-x 3 tomcat tomcat 21 Apr 8 05:53 work
启动的时候会把临时文件和工作文件放在temp和work,在生产用的时候、建议每次启动将这两个目录清空
tomcat使用自带的脚本有时候是杀不死进程的 、自己写一个脚本
#!/bin/sh JAVA_HOME=/application/jdk CATALINA_HOME=/application/tomcat usage(){ echo "$0 {start|stop|restart}" exit 1 } [ $# -ne 1 ]&& usage start_tomcat(){ $CATALINA_HOME/bin/startup.sh } stop_tomcat(){ TPID=$(ps -aux|grep java|grep tomcat|awk ‘{print $2}‘) kill -9 $TPID sleep 5; TSTAT=$(ps -aux|grep java|grep tomcat|awk ‘{print $2}‘) if [ -z $TSTAT ];then echo "tomcat stop" else kill -9 $TSTAT fi } case $1 in start) start_tomcat ;; stop) stop_tomcat ;; restart) stop_tomcat sleep 5 start_tomcat ;; *) usage ;; esac
[[email protected] ~]$ sh tomcat.sh tomcat.sh {start|stop|restart} [[email protected]-node1 ~]$ sh tomcat.sh start Using CATALINA_BASE: /application/tomcat Using CATALINA_HOME: /application/tomcat Using CATALINA_TMPDIR: /application/tomcat/temp Using JRE_HOME: /application/jdk Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar Tomcat started.
默认监听的是8080端口
[[email protected] ~]$ netstat -ntpl|grep java (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp6 0 0 :::8009 :::* LISTEN 4220/java tcp6 0 0 :::8080 :::* LISTEN 4220/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 4220/java
以上是关于JAVA企业级应用TOMCAT实战的主要内容,如果未能解决你的问题,请参考以下文章