自学内容网 自学内容网

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

原文地址:https://blog.csdn.net/goldenfish1919/article/details/142852506

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!