---
title: "Tomcat增加jmx监控，且可以设置密码"
author: "pirate4444"
date: "2016-09-05T17:00:48Z"
tags: []
categories: ["编程语言"]
slug: "tomcat-jmx"
draft: false
lastmod: "2016-09-05T17:01:45Z"
id: 2322751
url: "https://pirate4444.iteye.com/blog/2322751"
---

**服务器环境**

虚拟机：Java HotSpot(TM) 64-Bit Server VM版本 24.51-b03

操作系统：Linux 2.6.32-431.el6.x86\_64

 

**1、首先修改tomcat的catalina.sh文件，增加以下参数：**

CATALINA\_OPTS="$CATALINA\_OPTS -Dcom.sun.management.jmxremote"

#19999是jmx监控端口号

CATALINA\_OPTS="$CATALINA\_OPTS -Dcom.sun.management.jmxremote.port=19999"

 

##下面参数分需要输入密码和不需要输入密码两种情况。选择其中一种即可

##jconsole不需要输入密码

CATALINA\_OPTS="$CATALINA\_OPTS -Dcom.sun.management.jmxremote.authenticate=false"

CATALINA\_OPTS="$CATALINA\_OPTS -Dcom.sun.management.jmxremote.ssl=false"

 

##jconsole需要输入密码

\# CATALINA\_OPTS="$CATALINA\_OPTS -Dcom.sun.management.jmxremote.authenticate=true"

#下面access.file为权限文件的绝对路径

\# CATALINA\_OPTS="$CATALINA\_OPTS -Dcom.sun.management.jmxremote.access.file=/xxxx/jmxremote.access"

#下面password.file为密码文件的绝对路径

\# CATALINA\_OPTS="$CATALINA\_OPTS -Dcom.sun.management.jmxremote.password.file=/xxxx/jmxremote.password"  

 

创建文件jmxremote.access，设置账户权限，内容：

monitorRole   readonly

controlRole   readwrite

 

创建文件jmxremote.password，设置账户密码，内容：

monitorRole  444444

controlRole   444444

 

**注意，需要给以上两个文件授权：**

chmod 600 jmxremote.access

chmod 600 jmxremote.password    (must set 600)

 

**2、启动tomcat，启动jconsole连接。**

选择远程进程，输入 服务器ip:jmx端口 （如192.168.1.44:19999）**（若配置密码则需输密码）**

**![](http://dl2.iteye.com/upload/attachment/0119/8384/bf2ad182-4945-3ba8-b709-8492588551bc.png)**  
 

**3、查看c3p0的Mbean**

**![](http://dl2.iteye.com/upload/attachment/0119/8386/7209fce7-34d9-381d-b002-76e9cfb2f418.png)**