首页 > 代码库 > JAVA企业级应用TOMCAT实战(二)
JAVA企业级应用TOMCAT实战(二)
使用普通用户运行
使用普通用户来部署服务是比较安全的做法
[root@tomcat application]# useradd -u 1001 tomcat [root@tomcat application]# passwd tomcat Changing password for user tomcat. New password: Retype new password: passwd: all authentication tokens updated successfully.
切换到tomcat来执行 [root@tomcat application]# chown -R tomcat:tomcat /application/jdk [root@tomcat application]# chown -R tomcat:tomcat /application/tomcat/ [root@tomcat application]# su - tomcat [tomcat@linux-node1 ~]$ cd /application/tomcat/bin/ [tomcat@linux-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.
[tomcat@linux-node1 tomcat]$ pwd /application/tomcat [tomcat@linux-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
[tomcat@linux-node1 ~]$ sh tomcat.sh tomcat.sh {start|stop|restart} [tomcat@linux-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端口
[tomcat@linux-node1 ~]$ 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实战(二)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。