欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 手游 > Zookeeper占的那些端口 - 从Eclipse Jetty安全漏洞说起

Zookeeper占的那些端口 - 从Eclipse Jetty安全漏洞说起

2025/4/3 0:40:50 来源:https://blog.csdn.net/goldenfish1919/article/details/142852506  浏览:    关键词:Zookeeper占的那些端口 - 从Eclipse Jetty安全漏洞说起

起因

系统扫描报Jetty漏洞,很奇怪,系统中明明没有使用Jetty! 后来发现是Zookeeper中会使用Jetty,因为有使用Kafka,所以也使用了Zookeeper。

Zookeeper使用Jetty主要干2个事情:
1)提供给Prometheus用来输出监控指标用,占用端口7000
2)提供给AdminServer用来查询系统配置项,占用端口8080
也就是说,只要禁用这两个功能就可以了。

1)禁用7000端口

看下官方文档的描述:

Since 3.6.0 ZooKeeper binary package bundles an integration with Prometheus.io
metricsProvider.className : Set to “org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider” to enable Prometheus.io exporter.

metricsProvider.httpHost : New in 3.8.0: Prometheus.io exporter will start a Jetty server and listen this address, default is “0.0.0.0”

metricsProvider.httpPort : Prometheus.io exporter will start a Jetty server and bind to this port, it defaults to 7000. Prometheus end point will be http://hostname:httPort/metrics.

metricsProvider.exportJvmInfo : If this property is set to true Prometheus.io will export useful metrics about the JVM. The default is true.

metricsProvider.numWorkerThreads : New in 3.7.1: Number of worker threads for reporting Prometheus summary metrics. Default value is 1. If the number is less than 1, the main thread will be used.

metricsProvider.maxQueueSize : New in 3.7.1: The max queue size for Prometheus summary metrics reporting task. Default value is 1000000.

metricsProvider.workerShutdownTimeoutMs : New in 3.7.1: The timeout in ms for Prometheus worker threads shutdown. Default value is 1000ms.

在3.8.1版本中,7000端口默认就没打开,所以啥也不用动

#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

也就是说,只要注释掉metricsProvider相关配置即可。

2)禁用8080

还是看下官方文档:

New in 3.5.0: The following options are used to configure the AdminServer.

admin.enableServer : (Java system property: zookeeper.admin.enableServer) Set to “false” to disable the AdminServer. By default the AdminServer is enabled.

admin.serverAddress : (Java system property: zookeeper.admin.serverAddress) The address the embedded Jetty server listens on. Defaults to 0.0.0.0.

admin.serverPort : (Java system property: zookeeper.admin.serverPort) The port the embedded Jetty server listens on. Defaults to 8080.

admin.idleTimeout : (Java system property: zookeeper.admin.idleTimeout) Set the maximum idle time in milliseconds that a connection can wait before sending or receiving data. Defaults to 30000 ms.

admin.commandURL : (Java system property: zookeeper.admin.commandURL) The URL for listing and issuing commands relative to the root URL. Defaults to “/commands”.

默认AdminServer是打开的,我们可以打开访问http://192.168.200.128:8080/commands这个url看下这个界面:
在这里插入图片描述
点击比如“configuration”:
在这里插入图片描述
这个功能是可以禁用的,只需要在配置文件中设置admin.enableServer=false或者在zkServer.sh中设置java系统变量-Dzookeeper.admin.enableServer=fasle就可以了。

3)禁用JMX端口

禁用了7000和8080以后,发现Zookeeper除了占用2181之外,还占用了一个随机的端口,这个又是干啥的,如下:

[root@localhost apache-zookeeper-3.8.1-bin]# netstat -nap | grep 15216
tcp6       0      0 :::2181                 :::*                    LISTEN      15216/java          
tcp6       0      0 :::41897                :::*                    LISTEN      15216/java 

原来是JMX占用的,而且默认也是打开的,可以修改zkServer.sh禁用掉JMX:

# 在最开始添加上这一行即可
export JMXDISABLE=true

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词