How do i enable remote jmx with port in zookeeper

2020-07-18 08:10发布

问题:

Here my zkServer.cmd file :

@echo off


setlocal
call "%~dp0zkEnv.cmd"

set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain

echo on

call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*

endlocal

回答1:

First obtain the hostname (or reachable IP eg. lan/public/NAT address):

hostname -i
# or find ip
ip a

next add following options to ZOOMAIN (assumed hostname my.remoteconsole.org and desired port 8989)

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.port=8989
-Djava.rmi.server.hostname=my.remoteconsole.org

More details about available options in java docs (http://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html).



回答2:

The skServer.sh script will run the zkEnv.sh script which in-turn will look for a script '../conf/zookeeper-env.sh'

create a file on the conf folder called zookeeper-env.sh

Paste this into the file and restart Zookeeper:

JMXLOCALONLY=false
JMXDISABLE=false
JMXPORT=4048
JMXAUTH=false
JMXSSL=false


回答3:

ADD org.apache.zookeeper.server.quorum.QuorumPeerMain in server-start.

The class org.apache.zookeeper.server.quorum.QuorumPeerMain will start a JMX manageable ZooKeeper server. This class registers the proper MBeans during initalization to support JMX monitoring and management of the instance.