简体   繁体   English

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

[英]How to enable JMX on tomcat7 running as Windows service?

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. 我一直在尝试找到一种在安装为Windows服务的Tomcat实例上启用JMX Access的方法。 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" 通过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 service to read these options? 但是如何让Tomcat Windows服务读取这些选项呢? I tried this: 我试过这个:

C:>tomcat\\server\\bin> service.bat install #install the Tomcat7 windows service C:> tomcat \\ server \\ bin> service.bat install #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; 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“--JDmMs 256 -JvmMx 1 024 #update已安装的服务使用/ /美国开关; set tmpdir, JMX access and heap size 设置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 initialized错误:com.sun.management.jmxremote.port号无效:8090 -Dcom.sun.management.jmxremote.authenticate = false -Dcom.sun.management.jmxremote .ssl = FALSE

I don't have a Java background, am i trying to achieve something outlandish here? 我没有Java背景,我想在这里尝试一些古怪的东西吗? Please advise. 请指教。

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服务(首先进入\\ bin \\)

service.bat install

or your custom scripts. 或您的自定义脚本。

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

tomcat7w.exe //MS//ApacheTomcatWindowsServer

This should start Apache Service Monitor program on your system tray. 这应该在您的系统托盘上启动Apache Service Monitor程序。 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: 选择'Configure',单击'Java'选项卡并在'Java Options'文本框中附加以下内容,每行一个选项:

-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 jconsole from your JDK installation, click 'New Connection', specify 'Remote Process' and enter hostname:8090 . 要连接到JMX控制台,请从JDK安装中触发jconsole ,单击“新建连接”,指定“远程进程”并输入hostname:8090

you can also uninstall the service by 你也可以通过卸载服务

service.bat remove

then edit the service.bat and add the parameters in your StartPath and 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 =假

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 \\” - 启动auto --JvmOptions“-Dcatalina.home =%CATALINA_HOME%; - Dcatalina.base =%CATALINA_BASE%; - Djava.endorsed.dirs =%CATALINA_HOME%\\ endorsed; - Djava.io.tmpdir =%CATALINA_BASE%\\温度; -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以应用更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM