使用jmx端口选项时无法停止tomcat6

我们有tomcat6在两个不同的环境中运行,都运行CentOS 6.6和OpenJDK 1.7。 在一个环境中,发布时我无法阻止tomcat6

service tomcat6 stop 

在这个失败的环境中,唯一的区别是有一些额外的select:

 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=**8081** -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote=true -Djava.rmi.server.hostname=172.19.13.211 

停止时,catalina.outlogging下列错误:

 OpenJDK 64-Bit Server VM warning: Failed to reserve shared memory (errno = 1). OpenJDK 64-Bit Server VM warning: Failed to reserve shared memory (errno = 1). OpenJDK 64-Bit Server VM warning: Failed to reserve shared memory (errno = 1). Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: **8081**; nested exception is: java.net.BindException: Address already in use 

它看起来像jmx端口是什么原因造成这个问题,但没有完全删除,有没有办法让tomcat6优雅地停止?

更新1

在我的评论中提到的链接,导致我到一个博客文章 ,我跟着。 我创build了/usr/share/tomcat6/bin/setenv.sh文件,并使其可读性与以下内容:

 export CATALINA_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8081 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote=true -Djava.rmi.server.hostname=172.19.13.211" 

但是,当启动tomcat6时,jmx选项没有被包括在内。 有什么build议么?

以下是对我有用的东西:

使用这个页面的一些信息,我把下面的代码添加到tomcat6的启动脚本(在我的例子中是/usr/sbin/tomcat6 ):

 if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then . "$CATALINA_BASE/bin/setenv.sh" elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then . "$CATALINA_HOME/bin/setenv.sh" fi 

我的/usr/share/tomcat6/bin/setenv.sh文件的最终内容:

 #!/bin/sh export CATALINA_OPTS="-Dcom.sun.management.jmxremote.authenticate=false \ -Dcom.sun.management.jmxremote.port=8081 \ -Dcom.sun.management.jmxremote.ssl=false \ -Dcom.sun.management.jmxremote=true \ -Djava.rmi.server.hostname=172.19.13.211" 

现在我可以使用jmx选项成功启动tomcat6:

 [root@hrndvsoi-dev1-ucsync01 tomcat6]# service tomcat6 start Starting tomcat6: [ OK ] [root@hrndvsoi-dev1-ucsync01 tomcat6]# ps -ef | grep tomc | grep -v grep | sed -e 's/ /\n/g' | grep -e jmx -e rmi -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8081 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote=true -Djava.rmi.server.hostname=172.19.13.211 

我可以阻止tomcat6没有任何错误:

 [root@hrndvsoi-dev1-ucsync01 tomcat6]# service tomcat6 stop Stopping tomcat6: [ OK ] 

希望这可以帮助别人。