1) 正常安装JDK和Tomcat 配置环境变量(此步略过)
2) 配置JMX访问文件
# cd $CATALINA_HOME/conf/
# cp $JAVA_HOME/jre/lib/management/jmxremote.password.template jmxremote.password
# chmod 700 jmxremote.password (必定注意这个文件默认是不可写的)
# vi $CATALINA_HOME/conf/jmxremote.password
在最下面添加一个用户(第一个是用户名 第二个是密码)
fox 123456
# chmod 400 jmxremote.password (要求该文件是任何用户均不可写的)
# cp $JAVA_HOME/jre/lib/management/jmxremote.access jmxremote.access
# vi jmxremote.access (该文件是对jmx用户的受权)
到最后一行 将
monitorRole readonly
controlRole readwrite
注释 更改成
# monitorRole readonly
# controlRole readwrite
而后在最后添加一行
fox readwrite
# chmod 400 jmxremote.access
3) 配置Tomcat启动参数
# cd $CATALINA_HOME/bin
# vi catalina.sh
找到如下一行
# ----- Execute The Requested Command -----------------------------------------
在其上方添加一段脚本 加在最后的目的是要沿用以前的JAVA_OPTS和CATALINA_HOME变量设置(特别是堆内存参数设置) 网上文章说法有直接设置JAVA_OPTS的 不过这样设置在stop的时候会有异常抛出 虽然不影响使用
(参数意义依次是:
-Dcom.sun.management.jmxremote 启用JMX远程监控
-Dcom.sun.management.jmxremote.port=9004 使用端口9004(可随意指定只要不冲突)
-Dcom.sun.management.jmxremote.authenticate=true 远程链接须要密码认证
-Dcom.sun.management.jmxremote.ssl=false 不使用SSL(SSL我试了屡次都没有配置成功:P 暂时不开启)
-Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access 使用指定的JMX账号受权文件
-Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password 使用指定的JMX账号文件)
# ----- JMX Config Start -----
if [ "$1" = "run" ]; then
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10207 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access -Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password"
elif [ "$1" = "start" ]; then
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10207 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access -Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password"
fijava
# ----- JMX Config End -----shell
也就是说须要在tomcat的bin下须要在catalina.sh下加入以下代码便可。tomcat
# ----- JMX Config Start -----
if [ "$1" = "run" ]; then
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10207 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.access.file=/usr/java/jdk1.6.0_32/jre/lib/management/jmxremote.access -Dcom.sun.management.jmxremote.password.file=/usr/java/jdk1.6.0_32/jre/lib/management/jmxremote.password"
elif [ "$1" = "start" ]; then
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10207 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.access.file=/usr/java/jdk1.6.0_32/jre/lib/management/jmxremote.access -Dcom.sun.management.jmxremote.password.file=/usr/java/jdk1.6.0_32/jre/lib/management/jmxremote.password"
fi
# ----- JMX Config End -----
export JAVA_OPTS (重要)服务器
而后咱们要作的就是进入的/usr/java/jdk1.6.0_32/jre/lib/management下.net
有个模板,拷贝一份做为jmxremote.password,切记,这个文件权限比较特殊,我用的时候用的400blog
记得jmsremote.password最后内存
monitorRole QED
controlRole R&Dssl
前的注释去掉(系统自带的帐号和密码,建议本身新增一个,新增的时候记得去jmxremote.access中付给帐号读写权限) rem
而后就能够了。get
再就是注意一下hostname那部分,应该就直接能够在客户端输入jconsole而后输入IP地址,端口,帐号,密码,你就能够监控tomcat了
再次感谢@逝水fox大神
vi /etc/hosts 修改主机名为外网IP地址,这个很重要,要否则链接不上...