前言
最近平台部署了Kafka集群,为了方便管理于是安装了yahoo开源的一款基于web的管理工具。
安装kafka-manager
前提要求
- JDK1.8+
- 编译的主机要能够连接外网
1. 下载编译kafka-manager源码包
$ git clone git@github.com:yahoo/kafka-manager.git $ cd kafka-manager $ sbt clean dist
编译完成:
2. 修改配置文件
配置文件路径:kafka-manager/conf/application.conf 配置文件内容:
# Copyright 2015 Yahoo Inc. Licensed under the Apache License, Version 2.0
# See accompanying LICENSE file.
# This is the main configuration file for the application.
# ~~~~~
# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
play.crypto.secret="^<csmm5Fx4d=r2HEX8pelM3iBkFVv?k[mc;IZE<_Qoq8EkX_/7@Zt6dP05Pzea3U"
play.crypto.secret=${?APPLICATION_SECRET}
# The application languages
# ~~~~~
play.i18n.langs=["en"]
play.http.requestHandler = "play.http.DefaultHttpRequestHandler"
play.http.context = "/"
play.application.loader=loader.KafkaManagerLoader
kafka-manager.zkhosts="10.60.196.222:2181,10.60.196.223:2181,10.60.196.224:2181"
kafka-manager.zkhosts=${?ZK_HOSTS}
pinned-dispatcher.type="PinnedDispatcher"
pinned-dispatcher.executor="thread-pool-executor"
application.features=["KMClusterManagerFeature","KMTopicManagerFeature","KMPreferredReplicaElectionFeature","KMReassignPartitionsFeature"]
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "INFO"
}
basicAuthentication.enabled=true
basicAuthentication.enabled=${?KAFKA_MANAGER_AUTH_ENABLED}
basicAuthentication.username="admin"
basicAuthentication.username=${?KAFKA_MANAGER_USERNAME}
basicAuthentication.password="password"
basicAuthentication.password=${?KAFKA_MANAGER_PASSWORD}
basicAuthentication.realm="Kafka-Manager"
basicAuthentication.excluded=["/api/health"] # ping the health of your instance without authentification
kafka-manager.consumer.properties.file=${?CONSUMER_PROPERTIES_FILE}
__配置部分指令介绍__:
-
kafka-manager.zkhosts="zkhost_ip:zkhost_port,..." 用于指明kafka连接的zookeeper。如果zookeeper有多个用逗号分隔。如果你不想直接写入配置文件,你可以设置环境变量ZK_HOSTS,在配置文件中是用{?ZK_HOSTS}引用即可。 要想kafka-manager可以运行起来修改此配置即可。
-
application.features=["features1","features2",...] 设置kafka-manager对kafka集群具有的功能。有下面这四个功能 KMClusterManagerFeature:容许kafka manager添加,更新,删除kafka集群 KMTopicManagerFeature:容许kafka manager在kafka集群中添加,更新,删除topic KMPreferredReplicaElectionFeature:容许kafka manager在kafka集群中执行优先复制选举 KMReassignPartitionsFeature:容许kafka manager 生成分区设置,或重置分区设置。
-
basicAuthentication.enabled 是否启动basic认证,启用使用true,不启用使用false。当启用是此选项是,用户请求访问资源时,服务器将会返回401,浏览器就会弹出一个认证框让用户认证,这一过程被称为质询。
-
basicAuthentication.username 启用basic认证时,认证的用户名
-
basicAuthentication.password 启用basic认证时,认证的密码
-
basicAuthentication.realm 可以看成是一个解释,认证用于什么。此字符串在弹出认证框上显示出来
-
basicAuthentication.excluded=["/api/health"] 对kafka manager进行健康状态检测,不需要认证
3. 运行kafka manager
~]# cp /root/kafka-manager/kafka-manager-1.3.3.16/target/universal/kafka-manager-1.3.3.16.zip /opt ~]# unzip kafka-manager-1.3.3.16.zip ~]# ln -sv kafka-manager-1.3.3.16/ kafka-manager ~]# cd kafka-manager ~]# bin/kafka-manager -Dconfig.file=/conf/application.conf -Dhttp.port=888 -Dconfig.file:指明kafaka manager的配置文件 -Dhttp.port: 配置kafka manager监听的端口 -java-home: 指明jdk的路径,例如-java-home /usr/local/oracle-java-8
直接bin/kafka-manager此程序,会运行在前台。可以使用nohup bin/kafka-manager -Dconfig.file=/conf/application.conf -Dhttp.port=888 &运行在后台
4. 访问kafak manager
在浏览器中访问此URL: http://196.168.196.235:888 即可。 测试basic认证
健康状态检测
5. 管理集群
添加集群
kafka的版本号要选安装时的版本,填好后点击添加即可。
查看集群
在此页面你可以,操作在配置文件中开放的所有功能。