通过用 relaod4j 替换 log4j 来解决 Zookeeper 的 NoClassDefFoundError
由于最近曝光了 log4j 漏洞,我们的客户对此表示严重担忧。他们要求我们删除所有 log4j ver.1
或将其替换为 ver.2
,但不幸的是,我们不可能做出如此大的改变。我们做了一个解决方法并用 reload4j
替换了 log4j ver.1
,并且大多数组件在更改后都可以正常工作。
不幸的是,我们的产品中有一些二进制文件,例如 (elastic-search/logstash/zookeeper)
,它们使用旧版本的 log4j ver.2
(log4j- core-2.11.x <2.17.1) 或仍然使用 log4j ver.1
(log4j-1.2.16)。 对于这些,我们在 /lib/ 目录中进行了直接更改,并用最新的 jar 替换了旧的 jar,这对于 elastic-search/logstash
来说效果很好。但是,当我们通过将 log4j 替换为 reload4j 对 zookeeper
执行相同操作时,我们在启动组件时面临以下异常。
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:74)
at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:52)
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:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 mor
- Zookeeper 当前版本:2.4.6
- 最新稳定版本:3.7.0
最新稳定版本仍然使用 log4j-1.2.17。
有人可以指导解决方法吗?提前致谢
Due to the recent exposure of log4j vulnerabilities our client has serious concerns about it. They asked us to remove or replace all the log4j ver.1
with ver.2
but unfortunately this is not possible for us to make such a big change.We did a workaround and replaced the log4j ver.1
with reload4j
and majority of components are working fine this with change.
Unfortunately we have some binaries in our product like (elastic-search/logstash/zookeeper)
which are using either the older version of log4j ver.2
(log4j-core-2.11.x < 2.17.1) or still using the log4j ver.1
(log4j-1.2.16).
For these we made the direct change in /lib/ directory and replaced the old jars with latests, this works fine for elastic-search/logstash
. But when we did the same with zookeeper
by replacing log4j with reload4j we're now facing the following exception when starting the component.
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:74)
at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:52)
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:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 mor
- zookeeper current version : 2.4.6
- latest stable release : 3.7.0
Latest stable release is still using log4j-1.2.17.
Can someone please guide the workaround. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
向该图书馆的所有者询问了同样的问题。 这里是这个问题的进一步细节和答案。谢谢
Asked the same question to the owner of this library. Here is the further detail and answer of this problem. Thanks
设置系统属性zookeeper.jmx.log4j.disable=true将解决该问题。另请参阅 文档。
Setting the system property zookeeper.jmx.log4j.disable=true will fix the issue. See also the documentation.