cd /usr/local/jdk/jre/lib/management <1>访问规则:
cp jmxremote.access jmx_acl_gouqs.txt 其内容如下:
#gouqs readonly gouqs readwrite \\
create javax.management.monitor.*,javax.management.timer.* \\ unregister
gouqs用户是可以读写的。如果是readonly是只读。 <2>密码文件:
Cp jmxremote.password.template jmx_gouqs_password.txt 器内容如下: gouqs gou*
2> 在tomcat启动脚本里添加如下内容:
Vi /usr/local/tomcat6/bin/catalina.sh
CATALINA_OPTS=\-XX:PermSize=64M -XX:MaxPermSize=128m \\
-Djava.rmi.server.hostname=192.168.0.11 \\ -Dcom.sun.management.jmxremote \\
-Dcom.sun.management.jmxremote.port=9015 \\ -Dcom.sun.management.jmxremote.ssl=false \\
-Dcom.sun.management.jmxremote.authenticate=true \\ -Dcom.sun.management.jmxremote.password=true \\
-Dcom.sun.management.jmxremote.password.file=/usr/local/jdk/jre/lib/management/jmx_gouqs_password.txt \\
-Dcom.sun.management.jmxremote.access.file=/usr/local/jdk/jre/lib/management/jmx_acl_gouqs.txt\说明:
com.sun.management.jmxremote.authenticate 如果需要认证则为true
com.sun.management.jmxremote.password 如下需要用户名和密码进行认证则为true com.sun.management.jmxremote.ssl 如果不想要ssl方式进行安全访问则为:false com.sun.management.jmxremote.password.file:指定存放用户和密码的文件的位置 com.sun.management.jmxremote.access.file:指定范围规则设置的文件的位置。 以上配置在tomcat6,tomcat5 ,jdk1.5 jdk1.6下测试均无问题。
3> 启动tomcat服务后,可以看到9015端口 8.3.3 客户端连接Jconsole
客户端的远程连接Jconsole
我在win7 64位系统的命令行上执行:
C:\\Users\\Administrator>F:\\javainstall\\jdk\\bin\\jconsole.exe -interval=2 192.168.0
.11:9015
说明:Interval:搜集信息的时间间隔。单位为秒,默认是4秒
由于没有指定用户名和密码,连接失败,直接取消,就会出现如下窗口,然后在远程进程的地方输入: Ip:port 用户名和密码 然后确认即可。
登录成功后显示如下界面:
8.4 对java应用程序的监控: 8.4.1 说明
如果我们要监控我们自己开发的java应用项目,只需在java命令后面加上上面的参数,没有什么不同。 8.4.2 例子
例如监控我们的游戏服务监控服务,它的包名是:monitorGame.jar,现在其启动脚本里添加如下参数: JMX_ARGS=\
-Djava.rmi.server.hostname=192.168.0.11 \\ -Dcom.sun.management.jmxremote -jar \\ -Dcom.sun.management.jmxremote.port=9015 \\ -Dcom.sun.management.jmxremote.ssl=false \\
-Dcom.sun.management.jmxremote.authenticate=true \\ -Dcom.sun.management.jmxremote.password=true \\
-Dcom.sun.management.jmxremote.password.file=/usr/local/jdk/jre/lib/management/jmx_gouqs_password.txt \\
-Dcom.sun.management.jmxremote.access.file=/usr/local/jdk/jre/lib/management/jmx_acl_gouqs.txt\
启动脚本如下:
#!/bin/bash
ip=\
JVM_ARGS=\JMX_ARGS=\
-Djava.rmi.server.hostname=192.168.0.11 \\ -Dcom.sun.management.jmxremote -jar \\ -Dcom.sun.management.jmxremote.port=9015 \\ -Dcom.sun.management.jmxremote.ssl=false \\
-Dcom.sun.management.jmxremote.authenticate=true \\ -Dcom.sun.management.jmxremote.password=true \\
-Dcom.sun.management.jmxremote.password.file=/usr/local/jdk/jre/lib/management/jmx_gouqs_password.txt \\
-Dcom.sun.management.jmxremote.access.file=/usr/local/jdk/jre/lib/management/jmx_acl_gouqs.txt\
JAVA_HOME=\cd ${JAVA_HOME}/bin start(){
netstat -nlp|grep 8011|grep java >/dev/null if [ $? == 0 ] then
echo \ exit 0 fi
${JAVA_HOME}/bin/java ${JVM_ARGS} ${JMX_ARGS} -jar /etc/shell/monitorGame.jar $ip & } stop(){
netstat -nlp|grep 8011|grep java >/dev/null if [ $? == 0 ] then
pid=`ps -ef|grep java|grep 8011|awk '{print $2}'` kill -9 $pid fi }
case $1 in start) start ;; stop) stop ;;
相关推荐: