tomcat jmx配置
windows和linux tomcat jmx配置,监控tomcat
官方tomcat jmx文档连接(9.x版本)https://tomcat.apache.org/tomcat-9.0-doc/monitoring.html#Enabling_JMX_Remote
一.windows下安装版
二.windows免安装版
三.linux下
写在前面:很多教程配置缺少rmi.port配置,这样在有端口访问控制,安全策略的环境中,会因为只放行了1099而导致连接失败,因为rmi.port通信端口如果不配置,则会在连接请求时候被监控服务器随机一个通信端口,随机端口未在安全策略中放行,因此会导致连接无法成功,因此建议该项配置,在访问控制对1099 1098都添加允许访问源,即可正常连接成功。如果网络环境没有限制策略,可不配置条目。这里的1099 1098端口都可以自己随意定义,只要目标服务器未使用端口即可。
另外在8.5以后版本配置要写在一行,否则会导致启动异常
windows下安装版方法
1.点击“开始> 所有程序> Apache Tomcat x.0 Tomcatx > Configure Tomcat”菜单项 或者找到安装路径下的bin文件夹,在找到tomcat7w.exe这里的7是版本号,如果是tomcat5安装版,那么就是tomcat5w.exe双击tomcat7w.exe
2.在 Tomcat 配置台中点击“Java”选项卡
3.在 Java Options 文本框的最后,增加以下选项(不包含注释)
#启用JMX 远程访问
-Dcom.sun.management.jmxremote
#设置JMX 远程访问的本地监听端口为1099
-Dcom.sun.management.jmxremote.port=1099
#设置jmx远程通信端口为1098,如果不配置,则每次连接会随机一个端口(如果有ACL或者限制策略,建议配置,配置好后添加允许访问源,否则会因为1099请求连接时候随机通信端口而被安全策略拦截,无法正常连接)
-Dcom.sun.management.jmxremote.rmi.port=1098
#与JMX 建立远程连接时不使用SSL
-Dcom.sun.management.jmxremote.ssl=false
#与JMX 建立远程连接时需要进行身份认证,也可以设置为false 不进行身份认证
-Dcom.sun.management.jmxremote.authenticate=true
#与JMX 建立远程连接时的身份认证文件,不进行身份认证时不用配置
-Dcom.sun.management.jmxremote.password.file=C:\Program Files\Apache Software
Foundation\Tomcat 7.0\conf\jmxremote.password
#与JMX 建立远程连接时的权限控制文件,不进行身份认证时不用配置
-Dcom.sun.management.jmxremote.access.file=C:\Program Files\Apache Software
Foundation\Tomcat 7.0\conf\jmxremote.access
#JMX 响应U-Center 请求时使用的IP 地址
-Djava.rmi.server.hostname=10.xxx.xxx.xx
4.如果启用了身份认证,拷贝java安装路径\jre\lib\management目录下的模板文件
jmxremote.access 和jmxremote.password.template 到目录tomcat路径下conf下。
5.修改文件后缀:将jmxremote.password.template 文件修改为jmxremote.password。
6. jmxremote.password 和jmxremote.access 文件的内容修改如图所示。
7.如果启用了身份认证,则还需要将jmxremote.password 文件的访问权限设置为所有者完全控制。打 开jmxremote.password 文件的属性对话框
8.点击“安全”选项卡,查看当前可以对文件进行控制的用户,如图8 所示,并单击<高级>按钮,弹出 高级安全设置对话框.
9.点击“更改”链接,修改文件的所有者为Administrators。
10.单击<禁用继承>按钮,弹出阻止继承对话框, 选择“将已继承的权限转换为此对象的显示权限”选项
11.将除Administrators 外的其它用户/用户组全部删除。单击<确定>按钮,完成具体权限设置,确定后,完成文件属性设置。;启动或重启Tomcat。
Tomcat 启动完成后,打开Windows 命令行窗口,输入命令netstat –ano |findstr 1099 netstat –ano |findstr 1098。可以看到端口1099、1098已处于监听状态。
windows下解压版tomcat jmx配置方法
解压版配置方法
1、在bin目录下找到catalina.bat(windows)
2、找到rem ---------Execute The Requested Command --------------
配置参数,如下图
已验证,需要注意jmxremote.password文件一定要去掉文件继承,所有者为administrators,安全里删除除开administrators以外的所有账户
已在9.x版本使用set JAVA_OPTS=%JAVA_OPTS%=-Dcom……… set JAVA_OPTS=-Dcom……… set CATALINA_OPTS=-Dcom………都是可以的。
注:tomcat8.5版本以后需要写在一行,否者启动不了
set JAVA_OPTS=-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.rmi.port=1098
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.password.file=D:\apache-tomcat-9.0.39\conf\jmxremote.password
-Dcom.sun.management.jmxremote.access.file=D:\apache-tomcat-9.0.39\conf\jmxremote.access
-Djava.rmi.server.hostname=172.30.30.11
或者注:tomcat8.5版本以后需要写在一行,否者启动不了
set CATALINA_OPTS=-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.rmi.port=1098
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.password.file=D:\apache-tomcat-9.0.39\conf\jmxremote.password
-Dcom.sun.management.jmxremote.access.file=D:\apache-tomcat-9.0.39\conf\jmxremote.access -Djava.rmi.server.hostname=172.30.30.11
这里的
Dcom.sun.management.jmxremote.password.file=D:\apache-tomcat-9.0.39\conf\jmxremote.password -Dcom.sun.management.jmxremote.access.file=D:\apache-tomcat-9.0.39\conf\jmxremote.access
路径加引号和不加引号都可以,比如如下:
Dcom.sun.management.jmxremote.password.file="D:\apache-tomcat-9.0.39\conf\jmxremote.password" -Dcom.sun.management.jmxremote.access.file="D:\apache-tomcat-9.0.39\conf\jmxremote.access"
如下已验证(20201020已验证可用)
set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=172.30.30.11
注:tomcat8.5版本以后需要写在一行,否者启动不了
验证是否可用,windows使用jconsole.exe来查看(jconsole.exe在jdk安装目录bin下)
(1)在开始输入jconsole.exe
(2)连接tomcat
(3)在远程连接里输入ip地址加端口号,比如1.1.11.1:1099如果开了认证,输入相应用户名密码,点击连接后即可看到监控图形。
linux下:
Linux 环境下解压版Tomcat 配置:
(1) 远程登录Linux 操作系统,输入root 用户的用户名和密码。
(2) 进入 Tomcat 启动脚本catalina.sh 所在目录,编辑启动脚本
#在CATALINA_OPTS 参数后面附加Java 选项
CATALINA_OPTS=
#启用JMX 远程访问
-Dcom.sun.management.jmxremote
#设置JMX 远程访问的本地监听端口为1099
-Dcom.sun.management.jmxremote.port=1099
#通信端口,如果不配置则在请求通信时候会自动随机一个端口。
-Dcom.sun.management.jmxremote.rmi.port=1098
#与JMX 建立远程连接时不使用SSL
-Dcom.sun.management.jmxremote.ssl=false
#与JMX 建立远程连接时进行身份认证,也可以设置为false
-Dcom.sun.management.jmxremote.authenticate=true
#与JMX 建立远程连接时的身份认证文件,不进行身份认证时不用配置
-Dcom.sun.management.jmxremote.password.file=tomcat所在路径/conf/jmxremote.password
#与JMX 建立远程连接时的权限控制文件,不进行身份认证时不用配置
-Dcom.sun.management.jmxremote.access.file=tomcat所在路径/conf/jmxremote.access
#JMX 响应U-Center 请求时使用的IP 地址,配置为本机与监控服务器路由可达的一个ip地址
-Djava.rmi.server.hostname=x.x.x.x"
完整配置如下,要在一行
CATALINA_OPTS=-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.rmi.port=1098
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.password.file=tomcat路径/conf/jmxremote.password 这里路径改为自己对应路径
-Dcom.sun.management.jmxremote.access.file=tomcat路径/conf/jmxremote.access 这里路径改为自己对应路径
-Djava.rmi.server.hostname=172.30.30.11
注:tomcat8.5版本以后需要写在一行,否者启动不了
如果启用了身份认证,则根据Java 选项中的配置,在相应目录中(tomcat路径/conf/)
增加jmxremote.password 和jmxremote.access 文件,文件内容和格式如图所示。
(5) 如果启用了身份认证,则还需要为jmxremote.password 文件设置访问权限。如图所示,
将jmxremote.password 文件权限设置为所有者读写权限,即600。
(6) 启动或重启Tomcat。
Tomcat 启动完成后,输入命令netstat –ano | grep 1099 netstat –ano | grep 1098
已经处于监听状态。