JMX配置Tomcat 7.0连接Linux java监控

来源:互联网 发布:淘宝达人如何挣钱 编辑:程序博客网 时间:2024/04/27 18:48
1、配置Tomcat catalina.sh 
找到# OS specific support. $var _must_ be set to either true or false.添加如下变量: 
JAVA_OPTS="-Dcom.sun.management.jmxremote.port=1090 --配置jmx远程监听端口1090,指定任意为被占用端口 
-Dcom.sun.management.jmxremote.authenticate=true --启用用户认证 
-Dcom.sun.management.jmxremote.ssl=false --禁用ssl 
-Djava.rmi.server.hostname=10.111.43.164 --绑定远程主机IP 
-Dcom.sun.management.jmxremote.acccess.file=/opt/apache-tomcat-7.0.2/jconsole/jmxremote.access --配置用户访问权限 
-Dcom.sun.management.jmxremote.password.file=/opt/apache-tomcat-7.0.2/jconsole/jmxremote.password" --配置用户信息,包括用户名和密码 
如果不需要配置访问用户名及密码,配置如下: 
# OS specific support. $var _must_ be set to either true or false. 
JAVA_OPTS="-Dcom.sun.management.jmxremote.port=1090 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-Djava.rmi.server.hostname=10.111.43.164" 
选项配置文件说明:$JAVA_HOME/jre/lib/mamagement/jmxremote.properties 
2、切换用户到root,修改/etc/hosts添加IP地址。添加如下信息: 
10.111.43.164 fmcods.localdomain fmcods localhost.localdomain localhost 
3、创建jmxremote.password、jmxremote.access文件 
#mkdir -p $JAVA_HOME/jconsole 
#cp $JAVA_HOME/jre/lib/management/jmxremote.password.template $JAVA_HOME/jconsole/jmxremote.password 
#cp $JAVA_HOME/jre/lib/management/jmxremote.access $JAVA_HOME/jconsole/jmxremote.access
修改文件权限: 
#chmod -R 775 jconsole 
此时提示错误: 必须限制口令文件读取访问: $JAVA_HOME/jconsole/jmxremote.password。 
解决办法:在$CATALINA_BASE目录下新建jconsole文件夹,访问文件权限必须是600 
#mkdir -p $CATALINA_BASE/jconsole 
复制jmxremote.password、jmxremote.access到$CATALINA_BASE/jconsole,修改文件权限 
#chmod -R 600 jmxremote.password 
#chmod -R 600 jmxremote.access 
4、$CATALINA_BASE/bin/shutdown.sh.出现连接端口被占用提示。 
5、ps -ef | grep 1090 --被占用端口 
6、kill -9 pid 
7、重启Tomcat.$CATALINA_BASE/startup.sh 
8、jconsole 远程连接