如何在作为 Windows 服务运行的 tomcat7 上启用 JMX?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15136327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:18:51  来源:igfitidea点击:

How to enable JMX on tomcat7 running as Windows service?

windowstomcat

提问by user1175135

I have googled this extensively before posting it here. I've been trying to find out a way to enable JMX Access on a Tomcat instance installed as Windows service. Its quite straightforward when Tomcat is invoked via the startup.bat script, one just needs to set the CATALINA_OPTS environment variable to something like "-Dcom.sun.management.jmxremote.port=1234 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

在将其发布到此处之前,我已经广泛地搜索了此内容。我一直在尝试找出一种在安装为 Windows 服务的 Tomcat 实例上启用 JMX 访问的方法。通过 startup.bat 脚本调用 Tomcat 时非常简单,只需要将 CATALINA_OPTS 环境变量设置为“-Dcom.sun.management.jmxremote.port=1234 -Dcom.sun.management.jmxremote.authenticate=” false -Dcom.sun.management.jmxremote.ssl=false"

But how do i get the Tomcat Windows serviceto read these options? I tried this:

但是如何让 Tomcat Windows 服务读取这些选项?我试过这个:

C:>tomcat\server\bin> service.bat install#install the Tomcat7 windows service

C:>tomcat\server\bin> service.bat install #安装Tomcat7 windows服务

C:>tomcat\server\bin> tomcat7.exe //US//Tomcat7 ++JvmOptions "-Djava.io.tmpdir=$INSTDIR\server\temp;-XX:MaxPermSize =256m;-Dcom.sun.management.jmxremote.port=8090;-Dcom.sun.management.jmxremote.au thenticate=false;-Dcom.sun.management.jmxremote.ssl=false" --JvmMs 256 --JvmMx 1 024#update the installed service using the //US switch; set tmpdir, JMX access and heap size

C:>tomcat\server\bin> tomcat7.exe //US//Tomcat7 ++JvmOptions "-Djava.io.tmpdir=$INSTDIR\server\temp;-XX:MaxPermSize =256m;-Dcom.sun.management. jmxremote.port=8090;-Dcom.sun.management.jmxremote.au thenticate=false;-Dcom.sun.management.jmxremote.ssl=false" --JvmMs 256 --JvmMx 1 024 #使用/更新已安装的服务/US 开关;设置 tmpdir、JMX 访问和堆大小

When i start the service from Services panel, the service fails to start and i get the following error on the logs\tomcat7-stderr-yyyy-mm-dd.log file:

当我从“服务”面板启动该服务时,该服务无法启动,并且在 logs\tomcat7-stderr-yyyy-mm-dd.log 文件中出现以下错误:

yyyy-mm-dd hh:mm:ss Commons Daemon procrun stderr initialized Error: Invalid com.sun.management.jmxremote.port number: 8090 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

yyyy-mm-dd hh:mm:ss Commons Daemon procrun stderr 初始化错误:无效的 com.sun.management.jmxremote.port 号:8090 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote .ssl=假

I don't have a Java background, am i trying to achieve something outlandish here? Please advise.

我没有 Java 背景,我想在这里实现一些古怪的东西吗?请指教。

回答by user1175135

Answering my own question; turned out to be easier than i thought.

回答我自己的问题;结果比我想象的要容易。

Following needs to be done, for enabling JMX access for Tomcat installed as a Windows service, that has a name "ApacheTomcatWindowsServer" for example:

需要执行以下操作,以便为安装为 Windows 服务的 Tomcat 启用 JMX 访问,例如,名称为“ApacheTomcatWindowsServer”:

  • Install Tomcat as Windows service, either using the command (first cd into \bin\ )
  • 将 Tomcat 安装为 Windows 服务,或者使用命令(首先 cd 到 \bin\ )

service.bat install

service.bat install

or your custom scripts.

或您的自定义脚本。

  • Enable Apache Service Manager for the installed service using the following command:
  • 使用以下命令为已安装的服务启用 Apache 服务管理器:

tomcat7w.exe //MS//ApacheTomcatWindowsServer

tomcat7w.exe //MS//ApacheTomcatWindowsServer

This should start Apache Service Monitor program on your system tray. Click on its icon. select 'Configure', click on the 'Java' tab and append the following on the 'Java Options' text box, one option per line:

这应该会在您的系统托盘上启动 Apache Service Monitor 程序。单击其图标。选择“配置”,单击“Java”选项卡,然后在“Java 选项”文本框中附加以下内容,每行一个选项:

-Dcom.sun.management.jmxremote.port=8090

-Dcom.sun.management.jmxremote.authenticate=false

-Dcom.sun.management.jmxremote.ssl=false

-Dcom.sun.management.jmxremote.port=8090

-Dcom.sun.management.jmxremote.authenticate=false

-Dcom.sun.management.jmxremote.ssl=false

Save and exit and restart the service.

保存并退出并重新启动服务。

  • To connect to the JMX console, fire jconsolefrom your JDK installation, click 'New Connection', specify 'Remote Process' and enter hostname:8090.
  • 要连接到 JMX 控制台,请jconsole从 JDK 安装启动,单击“新建连接”,指定“远程进程”并输入hostname:8090.

回答by gigz

you can also uninstall the service by

您也可以通过以下方式卸载该服务

service.bat remove

then edit the service.bat and add the parameters in your StartPathand add the options

然后编辑 service.bat 并在StartPath 中添加参数并添加选项

-Djavax.management.builder.initial=;-Dcom.sun.management.jmxremote.port=8090;-Dcom.sun.management.jmxremote.authenticate=false;-Dcom.sun.management.jmxremote.ssl=false

-Djavax.management.builder.initial=;-Dcom.sun.management.jmxremote.port=8090;-Dcom.sun.management.jmxremote.authenticate=false;-Dcom.sun.management.jmxremote.ssl=false

here is the sample StartPath in my file

这是我文件中的示例 StartPath

--StartPath "C:\tomcat7\" --Startup auto --JvmOptions "-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;-Djava.rmi.server.hostname=;-Djavax.management.builder.initial=;-Dcom.sun.management.jmxremote.port=8090;-Dcom.sun.management.jmxremote.authenticate=false;-Dcom.sun.management.jmxremote.ssl=false" %JAVA_OPTS% ^

--StartPath "C:\tomcat7\" --Startup auto --JvmOptions "-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed;- Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties; -Djava.rmi.server.hostname=;-Djavax.management.builder.initial=;-Dcom.sun.management.jmxremote.port=8090;-Dcom.sun.management.jmxremote.authenticate=false;-Dcom.sun .management.jmxremote.ssl=false" %JAVA_OPTS% ^

re-install the service by

通过重新安装服务

service.bat install

then start Tomcat to apply changes

然后启动Tomcat以应用更改