2016年2月2日星期二

ActiveMQ_010:配置 JMX

环境:MAC OS X EI Capitan 10.11.3 + ActiveMQ 5.13

1. 不需要输入用户名和口令的配置
(1)修改 activemq.xml 中的 broker 节点,增加  useJmx="true" 属性。
(2)修改 activemq.xml 中的 managementContext 节点,修改 createConnector="true"。
这样修改后,默认的管理通信端口是1099,如果要修改端口,增加 connectorPort 属性,如下:
<managementContext>
      <managementContext createConnector="true" connectorPort="11099" />
</managementContext>  
(3)启动 jconsole,在远程进程中,输入连接URL(不用输入用户名和口令)。
比如:service:jmx:rmi:///jndi/rmi://172.30.13.18:1099/jmxrmi

2. 需要输入用户名和口令的配置
(1)修改 activemq.xml 中的 broker 节点,增加  useJmx="true" 属性。
(2)保持 activemq.xml 中的 managementContext 节点默认配置,即 createConnector="false"。
(3)修改 conf/jmx.access,修改后内容如下:
# The "monitorRole" role has readonly access.
# The "controlRole" role has readwrite access.
monitorRole readonly
controlRole readwrite
(4)修改 conf/jmx.password,修改后内容如下:
# The "monitorRole" role has password "abc123".
# The "controlRole" role has password "abcd1234".
monitorRole abc123
controlRole abcd1234
(5)确认 conf/jmx.password 文件,只有属主有读写权限。
chmod 600  conf/jmx.password
(6)修改 bin/activemq,增加 ACTIVEMQ_SUNJMX_START 变量设置
ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=1616 -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_BASE}/conf/jmx.password \
    -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_BASE}/conf/jmx.access"
(7)启动 activemq:bin/activemq console
(8)启动 jconsole,在远程进程中,输入连接URL(需要输入用户名和口令)。
比如:service:jmx:rmi:///jndi/rmi://172.30.13.18:1616/jmxrmi 用户名/口令:controlRole/abcd1234。

3. 另外一种需要输入用户名和口令的配置
(1)保持 activemq.xml 中的 broker 节点不变,即不增加  useJmx="true" 属性。
(2)修改 activemq.xml 中的 managementContext 节点,修改后内容如下:
 <managementContext>
    <managementContext createConnector="true">
        <property xmlns="http://www.springframework.org/schema/beans" name="environment">
            <map xmlns="http://www.springframework.org/schema/beans">
                <entry xmlns="http://www.springframework.org/schema/beans" key="jmx.remote.x.password.file"
                       value="${activemq.conf}/jmx.password"/>
                <entry xmlns="http://www.springframework.org/schema/beans" key="jmx.remote.x.access.file"
                       value="${activemq.conf}/jmx.access"/>
            </map>
        </property>
    </managementContext>
</managementContext>
(3)启动 activemq:bin/activemq start xbean:conf/activemq-security.xml  
(4)启动jconsole,在远程进程中,输入连接URL(需要输入用户名和口令)。
比如:service:jmx:rmi:///jndi/rmi://172.30.13.18:1099/jmxrmi 用户名/口令:controlRole/abcd1234。

参考文献:
1. http://activemq.apache.org/jmx.html

没有评论: