摘 要
centos 6.5环境中Tomcat配置JMX及相关说明
不管是Windows版还是Linux的版本的Tomcat的个性化参数配置(包括JMX),Tomcat官方推荐的方式是在Tomcat安装目录/bin新建setenv.sh(Linux)或setenv.bat(Windows)脚本来配置,而不是在tomcat自有的脚本中配置。
vi setenv.sh
#!/bin/sh
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access"
参数说明:
#!/bin/sh
#Author by itunic
#
#启用Tomcat JMX连接。
CATALINA_OPTS=-Dcom.sun.management.jmxremote
#
# 设置JMX URL主机名或IP地址。
-Djava.rmi.server.hostname=172.16.8.62
#
# 设置JMX 监听端口
-Dcom.sun.management.jmxremote.port=8849
#
# 设置SSL授权,值为 true 或 false;
-Dcom.sun.management.jmxremote.ssl=false
#
# 设置密码登陆,值为 true 或 false;如果需要授权,将一下配置进行添加
# -Dcom.sun.management.jmxremote.authenticate=false
#
#编辑在$CATALINA_BASE / conf / jmxremote.access访问权限:
-Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password
#
# 编辑密码文件$ CATALINA_BASE / conf / jmxremote.password:
-Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access
然后在Tomcat安装/conf下新建jmxremote.password和jmxremote.access文件,文件名必须这样命名。
vi jmxremote.access
#设置用户名及权限
#readonly只读权限
#readwrite 读写权限
#注意:只有这两种权限,其他不生效
monitorRole readonly
controlRole readwrite
vi jmxremote.password
#设置用户名及密码,用户名密码必须与access文件一致
monitorRole tomcat
controlRole tomcat
设置jmxremote.password文件的权限
设置操作系统hosts映射,将需要访问的ip加上机器名的对应关系。
#查看操作系统名称
hostname
#查看操作系统ip
ifconfig
#设置hosts对应关系
vi /etc/hosts
192.168.1.2 hostname
测试
利用jdk自带的jmx监控工具 jConsole测试配置是否正确
连接方式: