一.删除zookeeper/lib 目录下相关JAR包.
1.删除内容
rm -rf log4j-1.2.16.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar ;
二.加入以下的2.16版本的JAR包
slf4j-api-1.7.30.jar
log4j-slf4j-impl-2.16.0.jar
log4j-core-2.16.0.jar
log4j-api-2.16.0.jar
log4j-1.2-api-2.16.0.jar
三.重启,观察zookeeper.out 报错
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/jmx/HierarchyDynamicMBean
at org.apache.zookeeper.jmx.ManagedUtil.registerLog4jMBeans(ManagedUtil.java:50)
at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:75)
at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:53)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:116)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.jmx.HierarchyDynamicMBean
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 5 more
四.根据ManagedUtil.java,设置zookeeper.jmx.log4j.disable为true;
五.命令行修改:
将zkServer.sh变量修改为,log4j.configuration指定配置文件,zookeeper.jmx.log4j.disable设置.
ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY -Dlog4j.configuration=${ZOOBINDIR}/../conf/log4j.properties -Dzookeeper.jmx.log4j.disable=true org.apache.zookeeper.server.quorum.QuorumPeerMain"
六.重启完成:
2021-12-23T15:05:46,933 [myid:] - INFO [main:ZooKeeperServer@815] - tickTime set to 2000
2021-12-23T15:05:46,934 [myid:] - INFO [main:ZooKeeperServer@824] - minSessionTimeout set to -1
2021-12-23T15:05:46,934 [myid:] - INFO [main:ZooKeeperServer@833] - maxSessionTimeout set to -1
2021-12-23T15:05:46,944 [myid:] - INFO [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2181