Linux下Tomcat的启动、关闭、杀死进程,解决tomcat端口被占用

昨天晚上服务器莫名其妙的挂掉了,今天早上来了后,紧紧张张的改,第一次弄这个东西,又去网上找资料,很多人说的方法都差不多,但模棱两可,而且没有具体的解决步骤,真是坑坑坑。领导又一次催促了,我也很着急啊。最终我终于顺利解决这个问题。现在将问题解决步骤详细记录下来。
如果有看到我文章的,请关注我的博客,并给我写的每篇博客点个赞。哈哈。

问题描述:
启动Linux服务器上的tomcat,出现以下问题:

java.net.BindException: Address already in use <null>:8092

不难理解,意思是8092端口已经被占用了。

解决办法:
打开终端

[root@gft ~]# cd /sda/home/tomcat-6.0-saltCtredit

看是否已经有tomcat在运行了

[root@gft tomcat-6.0-saltCtredit]# ps -ef |grep tomcat
//发现共有3个进程在运行tomcat,其中一个1850进程号是其它的项目,不用管它。
//而2254和4130端口,运行的都是我们出错误的项目。需要杀掉这两个进程,然后重新启动tomcat。

彻底杀死运行tomcat的进程号

[root@gft tomcat-6.0-saltCtredit]# kill -9 2254
[root@gft tomcat-6.0-saltCtredit]# kill -9 4130

再次查看运行tomcat的进程,发现多余的两个进程成功杀死。

[root@gft tomcat-6.0-saltCtredit]# ps -ef|grep tomcat

重新启动tomcat,成功解决问题。

[root@gft tomcat-6.0-saltCtredit]# bin/startup.sh 

附:
启动tomcat,在tomcat的根目录下执行命令,如:/sda/home/tomcat-6.0-saltCtredit

bin/startup.sh

停止tomcat

bin/shutdown.sh

查看tomcat的控制台输出

tail -f logs/catalina.out

解决问题的详细控制台信息:

Last login: Wed Oct 19 09:42:42 2016 from 211.88.72.75
[root@gft ~]# cd /sda/home/tomcat-6.0-saltCtredit
[root@gft tomcat-6.0-saltCtredit]# 
[root@gft tomcat-6.0-saltCtredit]# ps -ef |grep tomcat
root      1850     1  0 Oct18 ?        00:03:03 /sda/java/jdk1.6.0_07/jre/bin/java -Djava.util.logging.config.file=/sda/home/tomcat-zbpt/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/sda/home/tomcat-zbpt/endorsed -classpath /sda/home/tomcat-zbpt/bin/bootstrap.jar -Dcatalina.base=/sda/home/tomcat-zbpt -Dcatalina.home=/sda/home/tomcat-zbpt -Djava.io.tmpdir=/sda/home/tomcat-zbpt/temp org.apache.catalina.startup.Bootstrap start
root      2254     1  6 Oct18 ?        01:40:23 /sda/java/jdk1.6.0_07/jre/bin/java -Djava.util.logging.config.file=/sda/home/tomcat-6.0-saltCtredit/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/sda/home/tomcat-6.0-saltCtredit/endorsed -classpath /sda/home/tomcat-6.0-saltCtredit/bin/bootstrap.jar -Dcatalina.base=/sda/home/tomcat-6.0-saltCtredit -Dcatalina.home=/sda/home/tomcat-6.0-saltCtredit -Djava.io.tmpdir=/sda/home/tomcat-6.0-saltCtredit/temp org.apache.catalina.startup.Bootstrap start
root      4130     1 20 09:44 ?        00:00:41 /sda/java/jdk1.6.0_07/jre/bin/java -Djava.util.logging.config.file=/sda/home/tomcat-6.0-saltCtredit/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/sda/home/tomcat-6.0-saltCtredit/endorsed -classpath /sda/home/tomcat-6.0-saltCtredit/bin/bootstrap.jar -Dcatalina.base=/sda/home/tomcat-6.0-saltCtredit -Dcatalina.home=/sda/home/tomcat-6.0-saltCtredit -Djava.io.tmpdir=/sda/home/tomcat-6.0-saltCtredit/temp org.apache.catalina.startup.Bootstrap start
root      4196  4176  0 09:48 pts/0    00:00:00 grep tomcat
[root@gft tomcat-6.0-saltCtredit]# kill -9 pid 2254
-bash: kill: pid: arguments must be process or job IDs
[root@gft tomcat-6.0-saltCtredit]# kill -9 2254
-bash: kill: (2254) - No such process
[root@gft tomcat-6.0-saltCtredit]# kill -9 4130
[root@gft tomcat-6.0-saltCtredit]# ps -ef|grep tomcat
root      1850     1  0 Oct18 ?        00:03:03 /sda/java/jdk1.6.0_07/jre/bin/java -Djava.util.logging.config.file=/sda/home/tomcat-zbpt/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/sda/home/tomcat-zbpt/endorsed -classpath /sda/home/tomcat-zbpt/bin/bootstrap.jar -Dcatalina.base=/sda/home/tomcat-zbpt -Dcatalina.home=/sda/home/tomcat-zbpt -Djava.io.tmpdir=/sda/home/tomcat-zbpt/temp org.apache.catalina.startup.Bootstrap start
root      4202  4176  0 09:51 pts/0    00:00:00 grep tomcat
[root@gft tomcat-6.0-saltCtredit]# bin/startup.sh 
Using CATALINA_BASE:   /sda/home/tomcat-6.0-saltCtredit
Using CATALINA_HOME:   /sda/home/tomcat-6.0-saltCtredit
Using CATALINA_TMPDIR: /sda/home/tomcat-6.0-saltCtredit/temp
Using JRE_HOME:        /sda/java/jdk1.6.0_07/jre
Using CLASSPATH:       /sda/home/tomcat-6.0-saltCtredit/bin/bootstrap.jar
[root@gft tomcat-6.0-saltCtredit]# 

附:
我现在工作项目的部署方案
Linux下Tomcat的启动、关闭、杀死进程,解决tomcat端口被占用_第1张图片

Last login: Thu Oct 20 09:40:56 2016 from 211.88.72.75
//跳转到tomcat的bin路径下
[root@gft ~]# cd /sda/home/tomcat-6.0-saltCtredit/bin
//停掉tomcat
[root@gft bin]# ./catalina.sh stop
Using CATALINA_BASE:   /sda/home/tomcat-6.0-saltCtredit
Using CATALINA_HOME:   /sda/home/tomcat-6.0-saltCtredit
Using CATALINA_TMPDIR: /sda/home/tomcat-6.0-saltCtredit/temp
Using JRE_HOME:        /sda/java/jdk1.6.0_07/jre
Using CLASSPATH:       /sda/home/tomcat-6.0-saltCtredit/bin/bootstrap.jar
//清掉tomcat缓存
[root@gft bin]# rm -rf /sda/home/tomcat-6.0-saltCtredit/work/Catalina
//重新启动tomcat
[root@gft bin]# ./catalina.sh start
Using CATALINA_BASE:   /sda/home/tomcat-6.0-saltCtredit
Using CATALINA_HOME:   /sda/home/tomcat-6.0-saltCtredit
Using CATALINA_TMPDIR: /sda/home/tomcat-6.0-saltCtredit/temp
Using JRE_HOME:        /sda/java/jdk1.6.0_07/jre
Using CLASSPATH:       /sda/home/tomcat-6.0-saltCtredit/bin/bootstrap.jar
[root@gft bin]# 

你可能感兴趣的:(Linux)