在linux下安装zookeeper时,出现了如下的错误:
[[email protected] bin]$ ./zkServer.sh start
JMX disabled by user request
Using config: /opt/zookeeper-3.3.3/bin/../conf/zoo.cfg
Starting zookeeper ...
STARTED
[[email protected] bin]$ 2011-07-05 10:33:57,587 - INFO [main:[email protected]] - Reading configuration from: /opt/zookeeper-3.3.3/bin/../conf/zoo.cfg
2011-07-05 10:33:57,596 - WARN [main:[email protected]] - Either no config or no quorum defined in config, running in standalone mode
Exception in thread "main" java.lang.NoSuchMethodError: method java.lang.management.ManagementFactory.getPlatformMBeanServer with signature ()Ljavax.management.MBeanServer; was not found.
at org.apache.zookeeper.jmx.ManagedUtil.registerLog4jMBeans(ManagedUtil.java:48)
at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:73)
at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:51)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:108)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:76)
发现没有找到java.lang.management下的一个方法。如果使用的是标准的JDK的话,不应该出现这样的错误的。于是查看zkServer.sh的脚本。发现启动java程序的脚本如下:
java "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
-cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" &
在linux下直接执行java命令,发现输出如下:
[[email protected] bin]$ java
Usage: gij [OPTION] ... CLASS [ARGS] ...
to invoke CLASS.main, or
gij -jar [OPTION] ... JARFILE [ARGS] ...
to execute a jar file
Try `gij --help' for more information.
显然,zkServer.sh使用的java不正确。使用的gij的java。解决这个问题就简单了,把脚本改成:
$JAVA_HOME/bin/java "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
-cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" &
这样修改之后,就能正常运行了。