Monitoring and Management Using JMX
The Java virtual machine (JVM) has built-in instrumentation that enables you to monitor and manage it using JMX. You can also monitor instrumented applications with JMX.
- Setting System Properties for JMX
- Enabling the JMX Agent
- Connecting to the JMX Agent Programmatically
- Using Password and Access Files
- JMX Management and Monitoring Properties
Setting System Properties
To enable the JMX agent and configure its operation, you must set certain system properties when you start the Java virtual machine (JVM). You set a system property on the command-line as follows:
java -Dproperty=value ...
You can set any number of system properties in this way. If you do not specify a value, then the property is set with its default value. The full set of JMX management properties is described in Table 1. You may also set system properties in a configuration file, as described in JMX Management and Monitoring Properties.
Note: To run java
(the Java VM) from the command line, you must add JRE_HOME/bin
to your path, where JRE_HOME
is the directory containing the Java Runtime Environment (JRE). Alternatively, you can enter the full path when you type the command.
The following documents describe the syntax and full set of command-line options supported by the Java HotSpot VMs:
- Java application launcher for Microsoft Windows
- Java application launcher for Solaris Operating Environment
- Java application launcher for Linux
Enabling the JMX Agent
To monitor a Java platform with JMX:
- Enable the JMX agent (the MBean server) when you start the JVM. You can enable the JMX agent for:
- Local monitoring, for a client management application running on the local system.
- Remote monitoring, for a client management application running on a remote system.
- Monitor the JVM with a JMX-compliant tool such as
jconsole
. See Using jconsole for more information.
Local Monitoring and Management
To enable the JMX agent for local access, set this system property when you start the JVM or Java application:
com.sun.management.jmxremote
Setting this property registers the JVM instrumentation MBeans and publishes the RMI connector via a private interface to allow JMX client applications to monitor a local Java platform, that is, a JVM running on the same machine.
For example, to enable the JMX agent for the J2SE sample application Notepad:
cd JDK_HOME/demo/jfc/Notepad java -Dcom.sun.management.jmxremote -jar Notepad.jar
where JDK_HOME is the directory where the JDK is installed.
Limitation: On Windows, for security reasons, local monitoring and management is only supported if your default Windows temporary directory is on a file system that supports setting permissions on files and directories (for example, on an NTFS file system). It is not supported on a FAT file system that provide insufficient access controls.
Using jconsole
Local monitoring with jconsole
is useful for development and prototyping. Using jconsole
locally is not recommended for production environments, because jconsole
itself consumes significant system resources. Rather, use jconsole on a remote system to isolate it from the platform being monitored.
Start jconsole by typing jconsole
in a command shell. When you start jconsole withouth any arguments, it will automatically detect all local Java applications, and display a dialog box that enables you to select the application you want to monitor. Both jconsole
and the application must by executed by the same user name, since the monitoring and monitoring system uses the operating system's file permissions.
Note: To run jconsole
from the command line, you must add JAVA_HOME/bin
to your path, where JAVA_HOME
is the directory containing the JDK. Alternatively, you can enter the full path when you type the command.
For more information on using jconsole, see Using jconsole.
Remote Monitoring and Management
To enable monitoring and management from remote systems, set this system property when you start the JVM:
com.sun.management.jmxremote.port=portNum
where portNum is the port number through which you want to enable JMX/RMI connections. Be sure to specify an unused port number. In addition to publishing a RMI connector for local access, setting this property publishes an additional RMI connector in a private read-only registry at the specified port using a well known name, "jmxrmi".
Note: You must set the above system property in addition to any properties you set for security, described below.
Remote monitoring and management requires security, to ensure that unauthorized persons cannot control or monitor your application. Password authentication over SSL (secure sockets layer) is enabled by default. You may separately disable password authentication and SSL, as described in the following sections:
- Using password authentication
- Disabling password authentication
- Using SSL
- Using client SSL authentication
- Disabling SSL
- Disabling security
After you have enabled the JMX agent for remote use, you can monitor your application using jconsole, as described in Remote Monitoring with jconsole.
Using Password Authentication
By default, when you enable the JMX agent for remote monitoring, it uses password authentication. However, the way you set it up depends on whether you are in a single-user environment or a multi-user environment.
Since passwords are stored in clear-text in the password file, it is not advisable to use your regular user name and password for monitoring. Instead, use the user names specified in the password file such as monitorRole
and controlRole
. For more information, see Using Password and Access Files.
Single User Environment: set up the password file in the JRE_HOME/lib/management
directory as follows:
- Copy the password template file,
jmxremote.password.template
, tomanagement.jmxremote.password
. - Set file permissions so that only the owner can read and write the password file.
- Add passwords for roles such as
monitorRole
andcontrolRole
.
Multi-user Environment: set up the password file in the JRE_HOME/lib/
management
directory as follows:
- Copy the password template file,
jmxremote.password.template
, to your home directory. - Set file permissions so that only you can read and write the password file.
- Add passwords for the roles such as
monitorRole
andcontrolRole
. - Set this system property when you start the JVM:
com.sun.management.jmxremote.password.file=pwFilePath
where pwFilePath is the path to the password file.
WARNING: A potential security issue has been identified with password authentication for JMX remote connectors when the client obtains the remote connector from an insecure RMI registry (the default). If an attacker starts a bogus RMI registry on the target server before the legitmate one is started, then the attacker can steal clients' passwords. This scenario includes the case where you launch a JVM with remote management enabled, using the system property com.sun.management.jmxremote.port=portNum , even when SSL is enabled. Although such attacks are likely to be noticed, it is nevertheless a vulnerability. To avoid this problem, use SSL client certificates for authentication instead of passwords, or ensure that the client obtains the remote connector object securely, for example through a secure LDAP server or a file in a shared secure filesystem. A future release will fix this problem. |
Disabling password authentication
Password authentication for remote monitoring is enabled by default. To disable it, set the following system property when you start the JVM:
com.sun.management.jmxremote.authenticate=false
where portNum is the port number to use. Be sure to specify an unused port number.
When you disable password authentication, you can also disable SSL, as described in Disabling Security. You may also want to disable passwords, but use SSL client authentication, as described in Enabling Client SSL Authentication.
Warning: This configuration is insecure: any remote user who knows (or guesses) your JMX port number and host name will be able monitor and control your Java application and platform. While it may be acceptable for development, it is not recommended for production systems.
Using SSL
Secure sockets layer (SSL) is enabled by default when you enable remote monitoring and management. To use SSL, you need to set up a digital certificate on the system where the JMX agent (MBean server) is running and then configure SSL properly. You use the command-line utility keytool
to work with certificates. The general procedure is:
- If you don't already have a keypair and certificate set up on the server:
- Generate a key pair with the
keytool -genkey
command. - Request a signed certificate from a certificate authority (CA) with the
keytool -certreq
command. - Import the certificate into your keystore with the
keytool -import
command. See Importing Certificates
For more information and examples, see keytool - Key and Certificate Management Tool (Solaris and Linux) (Windows).
- Generate a key pair with the
- Configure SSL on the server system. A full explanation of configuring and customizing SSL is beyond the scope of this document, but you generally need to set the system properties described in the following table. For more information, see Customizing the Default Key and Trust Stores, Store Types, and Store Passwords in the JSSE Guide.
javax.net.ssl.keyStore |
Keystore location. |
javax.net.ssl.trustStore |
Truststore location. |
javax.net.ssl.keyStoreType |
Default keystore type. |
javax.net.ssl.keyStorePassword |
Default keystore password. |
javax.net.ssl.trustStoreType |
Default truststore type. |
javax.net.ssl.trustStorePassword |
Default truststore password. |
For more information, see keytool - Key and Certificate Management Tool (Solaris and Linux) (Windows), and the JSSE Guide.
Enabling Client SSL Authentication
To enable client SSL authentication, set this system property when you start the JVM:
com.sun.management.jmxremote.ssl.need.client.auth=true
SSL must be enabled (the default), to use client SSL authentication.
This configuration requires the client system to have a valid digital certificate. You must install a certificate and configure SSL on the client system, as described inUsing SSL.
Disabling SSL
To disable SSL for remote monitoring, set this system property when you start the JVM:
com.sun.management.jmxremote.ssl=false
Password authentication will still be required unless you disable it, as specified in Disabling password authentication.
Disabling Security
To disable both password authentication and SSL (no security), set these system properties when you start the JVM:
com.sun.management.jmxremote.authenticate=false com.sun.management.jmxremote.ssl=false
Warning: This configuration is insecure: any remote user who knows (or guesses) your JMX port number and host name will be able to monitor and control your Java application and platform. While it may be acceptable for development, it is not recommended for production systems.
Remote Monitoring with jconsole
- To monitor a remote application with SSL disabled, start
jconsole
as follows:jconsole hostName:portNum
where hostName is the name of the system running the application and portNum is the port number you specified when you started the JVM. You can also omit the host name and port number, and enter them in the dialog box that
jconsole
provides. - To monitor a remote application with SSL enabled, you need to set up the truststore on the system where JConsole is running and configure SSL properly.
For example, if you create a keystore as described in the JSSE Guide and start your application (Server) as follows:
% java -Djavax.net.ssl.keyStore=keystore \ -Djavax.net.ssl.keyStorePassword=password Server
You need to start jconsole as follows:
% jconsole -J-Djavax.net.ssl.trustStore=truststore \ -J-Djavax.net.ssl.trustStorePassword=trustword
Note: To run jconsole
from the command line, you must add JAVA_HOME/bin
to your path, where JAVA_HOME
is the directory containing the JDK. Alternatively, you can enter the full path when you type the command.
For more information on using jconsole, see Using jconsole.
Connecting to the JMX Agent Programmatically
Once you have enabled the JMX agent, a client can use the following URL to access the service:
service:jmx:rmi:///jndi/rmi://hostName:portNum/jmxrmi
where hostName is the host name and portNum is the port number specified when the JMX agent was enabled.
A client can create a connector to the agent by instantiating an javax.management.remote.JMXServiceURL
object using the URL, and then creating a connection using theJMXConnectorFactory.connect
method as follows:
JMXServiceURL u = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi:// “ + hostName + ":" + portNum + "/jmxrmi"); JMXConnector c = JMXConnectorFactory.connect(u);
Using Password and Access Files
The password and access files control security for remote monitoring and management. These files are located by default in JRE_HOME/lib/management
and are in the standard Java properties file format. For more information on the format, see the API reference for java.util.properties
.
Password File
The password file defines the different roles and their passwords. The access control file (jmxremote.access by default) defines the allowed access for each role. To be functional, a role must have an entry in both the password and the access files.
The JRE contains a password file template named jmxremote.password.template
. Copy this file to JRE_HOME/lib/management/jmxremote.password
or to your home directory, and add the passwords for the roles defined in the access file.
Ensure that only the owner has read and write permissions on this file, since it contains the passwords in clear text. For security reasons, the system checks that the file is only readable or writeable by the owner and exits with an error if not. Thus in a multi-user environment, store the password file in private location such as your home directory.
Property names are roles, and the associated value is the role's password.
For example, the following are sample entries in the password file:
# The "monitorRole" role has password "QED". # The "controlRole" role has password "R&D". monitorRole QED controlRole R&D
Tips: On Solaris and Linux systems, you can set the file permissions for the password file by running:
chmod 600 jmxremote.password
On Windows, see How to Secure Password File on Windows Systems
Access File
By default, the access file is named jmxremote.access
. Property names are identities from the same space as the password file. The associated value must be either "readonly" or "readwrite".
The access file defines roles and their access levels. By default, the access file defines two primary roles:
-
monitorRole
, which grants read-only access for monitoring -
controlRole
, which grants read-write access for monitoring and management.
An access control entry consists of a role name and an associated access level. The role name cannot contain spaces or tabs and must correspond to an entry in the password file. The access level is either:
- readonly: grants access to read attributes of MBeans. For monitoring, this means that a remote client in this role can read measurements but cannot perform any action that changes the environment of the running program.
- readwrite: grants access to read and write attributes of MBeans, to invoke operations on them, and to create or remove them. This access should be granted to only trusted clients, since they can potentially interfere with the operation of an application.
A role should have only one entry in the access file. If a role has no entry, it has no access. If a role has multiple entries, then the last entry takes precedence.
Typical pre-defined roles in the access file:
# The "monitorRole" role has readonly access. # The "controlRole" role has readwrite access. monitorRole readonly controlRole readwrite
JMX Management and Monitoring Properties
You can set management and monitoring properties in a configuration file or on the command line. Properties specified on the command line override properties in a configuration file. The default location for the configuration file is JRE_HOME/lib/management/management.properties
, where JRE_HOME is the directory where the Java runtime environment is installed. The JVM reads this file if either of the command-line properties com.sun.management.jmxremote
or com.sun.management.jmxremote.port
are set. SNMP management uses the same configuration file; for more information, see SNMP Monitoring and Management.
You can specify a different location for the configuration file with the command-line option:
com.sun.management.config.file=ConfigFilePath
where ConfigFilePath is the path to the configuration file.
The following table describes all the JMX monitoring and management properties.
com.sun.management.jmxremote |
Enables the JMX remote agent and local monitoring via JMX connector published on a private interface used by jconsole . The jconsole tool can use this connector if it is executed by the same user ID as the user ID that started the agent. No password or access files are checked for requests coming via this connector. |
true / false. Default is true. |
com.sun.management.jmxremote. port |
Enables the JMX remote agent and creates a remote JMX connector to listen through the specified port. By default, SSL, password, and access files properties are used for this connector. Also enables local monitoring as described for the com.sun.management.jmxremote property. |
Port number. No default. |
com.sun.management.jmxremote. |
Enables secure monitoring via SSL. If false, then SSL is not used. | true / false. Default is true. |
com.sun.management.jmxremote. |
Comma-delimited list of SSL/TLS protocol versions to enable. Used in conjunction with com.sun.management.jmxremote.ssl
|
Default SSL/TLS protocol version. |
com.sun.management.jmxremote. |
A comma-delimited list of SSL/TLS cipher suites to enable. Used in conjunction with com.sun.management.jmxremote.ssl . |
Default SSL/TLS cipher suites. |
com.sun.management.jmxremote. |
If this property is true and the property com.sun.management.jmxremote.ssl is true, then client authentication will be performed. |
true / false. Default is false |
com.sun.management.jmxremote. |
If this property is false then JMX does not use passwords or access files: all users are allowed all access. | true / false. Default is true. |
com.sun.management.jmxremote. |
Specifies location for password file. If com.sun.management.jmxremote.password is false, then this property and the password and access files are ignored. Otherwise, the password file must exist and be in valid format. If the password file is empty or non-existent, then no access is allowed. |
JRE_HOME/lib/management/ |
com.sun.management.jmxremote. |
Specifies location for the access file. If com.sun.management.jmxremote.password is false, then this property and the password and access files are ignored. Otherwise, the access file must exist and be in the valid format. If the access file is empty or non-existent, then no access is allowed. |
JRE_HOME/lib/management/ |
com.sun.management.jmxremote. |
Specifies the name of a JAAS login configuration entry to use when authenticating users of RMI monitoring. When using this property to override the default login configuration, the named configuration entry must be in a file that gets loaded by JAAS. In addition, the login modules specified in the configuration should use the name and password callbacks to acquire the user's credentials. For more information, seejavax.security.auth.callback.NameCallback and javax.security.auth.callback.PasswordCallback . If com.sun.management.jmxremote.authenticate is false, then this property and the password and access files are ignored. |
Default login configuration is a file-based password authentication. |
Configuration Errors
If any errors occur during start up of the MBean server, the RMI registry, or the connector, the JVM will throw an exception and exit. Configuration errors include:
- Failure to bind to the port number
- Invalid password file
- Invalid access file
- Password file is readable by anyone other than the owner.
If your application runs a security manager, then additional permissions are required in the security permissions file.
发表评论
文章已被作者锁定,不允许评论。
-
将 JBoss封装为Windows 服务
2012-03-16 16:21 494Download javaService form objec ... -
java ee specifications
2012-03-15 16:29 666java ee specifications -
JEE - Memory Status Jsp Using JMX
2012-02-03 10:42 891<!-- jsp file content --& ... -
转载:负载均衡会话保持技术、原理、产品(以F5为例)
2011-12-29 14:26 646___________________ ... -
转载:Session详解[郎云鹏]
2011-12-28 10:08 5转载文章,原文发表于 @ 2004年12月08日 bea ... -
temporay
2011-12-08 17:30 822http://community.jboss.org/wiki ... -
Why Are Thread.stop, Thread.suspend, Thread.resume and Runtime.runFinalizersOnE
2011-11-11 14:15 790from http://download.oracle.co ... -
[REF] Java EE Version History
2011-07-12 14:01 688simply copied from : http://en ... -
保持原始存入顺序的Map实现类
2011-07-11 16:20 885LinkedHashMap
相关推荐
### JMX API for Monitoring and Management #### 引言:JMX API概述 Java Management Extensions (JMX) 是一种用于管理应用程序、开发工具和运行时环境的框架。它为监控和管理Java应用程序提供了一套标准的方法。...
"Monitoring Apache Tomcat with JMX" 是一种利用Java管理扩展(Java Management Extensions, 简称JMX)来实现这一目标的方法。JMX是一种标准的API,允许我们管理和监控Java应用程序,包括Tomcat,获取各种运行时...
《JDK9-JSE-Monitoring and Management Guide》是一份针对Java Platform, Standard Edition (Java SE) 9的监控和管理指南,旨在帮助开发者和系统管理员有效地管理和优化Java应用程序的性能。以下是对其中主要知识点...
这些工具通常包括JConsole、VisualVM和JMX(Java Management Extensions)等。 1. JMX:JMX是一种标准的管理框架,允许开发人员创建、管理和部署管理系统,用于监视和管理Java应用程序。在JDK10中,JMX提供了一种...
Java SE Monitoring and Management Guide Java Platform, Standard Edition Monitoring and Management Guide, Release 14是 Oracle 公司发布的一份关于 Java SE 平台监控和管理的指南。该指南于 2020 年 3 月...
这些 API 包括 Java Management Extensions(JMX)、Java Monitoring and Management API(JMMA)等。 6. 安全性和权限控制 Java SE 17 中的监控和管理工具和 API 都提供了安全性和权限控制机制,确保只有授权的...
Java Management Extensions(JMX)是Java平台中用于管理和监控应用程序、操作系统、网络设备等资源的一种标准框架。通过JMX,开发者可以创建管理代理(MBeans),这些代理暴露了各种管理特性,使得系统管理员可以...
You will find this book to be useful long after new versions of JMX become available because the concepts introduced here are classic applications of management concepts and technologies to the Java ...
jmx(Java Management Extensions)是一种Java技术,为Java应用程序提供了管理和监控的功能。ActiveMQ是Apache软件基金会下的一个开源消息队列系统,提供了高效、可靠的消息传递服务。在生产环境中, ActiveMQ的监控...
Java Management Extensions (JMX) 是Java平台提供的一种用于管理和监控应用程序、系统和服务的标准框架。`jmxri-1.2.1.jar`是这个框架的一部分,主要包含了JMX的运行时实现(Runtime Implementation)。在Maven项目...
1. Java Management Extensions (JMX):JMX 是 Java SE 平台提供的一种监控机制,允许开发者创建、配置和管理 Java 应用程序的监控信息。 2. Java Virtual Machine (JVM) Monitoring:JVM 监控是指对 JVM 的性能和...
Java™ and JMX: Building Manageable Systems By Heather Kreger, Ward Harold, Leigh Williamson Publisher : Addison Wesley Pub Date : December 30, 2002 ISBN : 0-672-32408-3 Pages : 592
Java Management Extensions(JMX)是Java平台上的一个标准,它提供了一种管理和监控应用程序、操作系统、网络设备和其他Java应用程序的方式。这个"jmx-1.2.1(jmxri+jmxtools) jar"包含了JMX的两个核心组件:JMX ...
Java Management Extensions (JMX) 是Java平台的一项标准技术,它提供了一种管理和监视Java应用程序的方法。通过JMX,开发者可以创建管理接口,暴露应用程序的内部状态,如性能指标、资源使用情况等,以便于系统管理...
Java Management Extensions(JMX)是Java平台上的一个标准API,用于管理和监控应用程序、服务和设备。JMX允许开发者创建管理接口,这些接口可以被本地或远程的管理工具使用,以便监控和配置应用的状态。在本实例中...
JMX实战 书中不仅有对于基础知识的介绍,还有对于JMX开发中重大的体系架构问题的深入探讨,总结了大量JMX开发中的设计模式,并讨论了框架、安全性与性能等等。书中提供了几个典型的例子,兼顾各种开发平台,这些...
JMX(Java Management Extensions)是一个用于在Java应用程序中添加管理和监控功能的框架。它提供了一套标准的接口和服务,使得开发者能够轻松地在Java应用中集成管理和监控的能力。JMX的核心概念包括MBeans...
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.port=JMX_PORT set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.ssl=false set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun....
* Java Management Extensions(JMX):一个基于Java的管理协议,提供了应用程序管理和监控功能。 * Java API for Management(JAM):一个基于Java的管理API,提供了应用程序管理和监控功能。 安全性 Java ...