一、下載
下載地址:https://github.com/yahoo/CMAK/releases
shell> wget https://codeload.github.com/yahoo/CMAK/tar.gz/2.0.0.2
說明:之前叫Kafka Manager,現(xiàn)在改名叫CMAK(Cluster Manager for Apache Kafka)了,網頁下載之后的壓縮包名字是CMAK-2.0.0.2.tar.gz,wget下載后的壓縮包名字是2.0.0.2.tar.gz(如果是2.0.0.0或更老版本,wget下載后的壓縮包名字只有版本號,沒有后綴名,但是也可以直接解壓)
二、解壓
shell> tar -zxvf CMAK-2.0.0.2.tar.gz -C /usr/local/
解壓后的目錄為CMAK-2.0.0.2
三、sbt編譯
kafka-manager需要sbt編譯,所以如果沒有安裝sbt需要先安裝下
1、yum
shell> curl https://bintray.com/sbt/rpm/rpm | sudo tee /etc/yum.repos.d/bintray-sbt-rpm.repo
shell> sudo yum install sbt
2、手動安裝
下載地址:https://www.scala-sbt.org/download.html
shell> wget https://piccolo.link/sbt-1.3.8.tgz
shell> tar -zxvf sbt-1.3.8.tgz -C /usr/local/
添加環(huán)境變量
shell> vim /etc/profile
export PATH=/usr/local/sbt/bin:$PATH
shell> source /etc/profile
3、修改倉庫地址(sbt默認下載庫很慢,這里添加阿里云倉庫,類似使用maven時添加阿里云倉庫提高速度)
shell> vim ~/.sbt/repositories
添加以下內容
[repositories]
local
aliyun: http://maven.aliyun.com/nexus/content/groups/public/
typesafe: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
sonatype-oss-releases
maven-central
sonatype-oss-snapshots
4、編譯
這個過程會很漫長,因為要下載很多依賴包,甚至開始看起來像是卡住了一樣,耐心等待,再等待...
(如果真的要折騰,建議開個后臺進程,不想等的下面有編譯好的鏈接)
編譯成功后會在target/universal/目錄下生成一個可用于部署的kafka-manager-2.0.0.2.zip
shell> cd
shell> ./sbt clean dist
[info] Loading settings for project cmak-2-0-0-2-build from plugins.sbt ...
[info] Loading project definition from /usr/local/CMAK-2.0.0.2/project
[info] Updating ProjectRef(uri("file:/usr/local/CMAK-2.0.0.2/project/"), "cmak-2-0-0-2-build")...
[info] Done updating.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[info] Loading settings for project root from build.sbt ...
[info] Set current project to kafka-manager (in build file:/usr/local/CMAK-2.0.0.2/)
[success] Total time: 0 s, completed Mar 30, 2020 1:22:04 AM
[info] Packaging /usr/local/CMAK-2.0.0.2/target/scala-2.12/kafka-manager_2.12-2.0.0.2-sources.jar ...
[info] Done packaging.
Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript assets compilation, which in some cases may be orders of magnitude slower than using node.js.
[info] Updating ...
[info] downloading https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.12.8/scala-compiler-2.12.8.jar ...
[info] [SUCCESSFUL ] org.scala-lang#scala-compiler;2.12.8!scala-compiler.jar (1389309ms)
[info] Done updating.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[info] Wrote /usr/local/CMAK-2.0.0.2/target/scala-2.12/kafka-manager_2.12-2.0.0.2.pom
[info] Main Scala API documentation to /usr/local/CMAK-2.0.0.2/target/scala-2.12/api...
[info] Compiling 131 Scala sources and 2 Java sources to /usr/local/CMAK-2.0.0.2/target/scala-2.12/classes ...
[info] Non-compiled module 'compiler-bridge_2.12' for Scala 2.12.8. Compiling...
[info] Compilation completed in 11.025s.
model contains 604 documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /usr/local/CMAK-2.0.0.2/target/scala-2.12/kafka-manager_2.12-2.0.0.2-javadoc.jar ...
[info] Done packaging.
[info] LESS compiling on 1 source(s)
[info] Done compiling.
[info] Packaging /usr/local/CMAK-2.0.0.2/target/scala-2.12/kafka-manager_2.12-2.0.0.2-web-assets.jar ...
[info] Packaging /usr/local/CMAK-2.0.0.2/target/scala-2.12/kafka-manager_2.12-2.0.0.2.jar ...
[info] Done packaging.
[info] Done packaging.
[info] Packaging /usr/local/CMAK-2.0.0.2/target/scala-2.12/kafka-manager_2.12-2.0.0.2-sans-externalized.jar ...
[info] Done packaging.
[success] All package validations passed
[info] Your package is ready in /usr/local/CMAK-2.0.0.2/target/universal/kafka-manager-2.0.0.2.zip
[success] Total time: 1466 s, completed Mar 30, 2020 1:46:30 AM

shell> cd /usr/local/CMAK-2.0.0.2/target/universal
shell> ll
total 94404
-rw-r--r-- 1 root root 96662556 Mar 30 01:46 kafka-manager-2.0.0.2.zip
drwxr-xr-x 3 root root 4096 Mar 30 01:46 scripts
我這里時間看起來沒有那么那么長,主要是因為之前編譯過一次了,為了測試和截圖又重新來了一遍...
如果有時間愿意折騰可以按照以上步驟嘗試一下,如果不想經歷著漫長的等待,推薦大家直接下載編譯好的zip,這里我把自己編譯過的幾個版本分享下:
1.3.3.22:鏈接:https://pan.baidu.com/s/1PyRIckLk8MFlZcdt_gd22g 密碼:7v8r
2.0.0.0:鏈接:https://pan.baidu.com/s/1lYvyrx0ezA3ENa2kjiQG9g 密碼:7wd9
2.0.0.2:鏈接:https://pan.baidu.com/s/1fiQvM1rbt5cwtEtl45vwMA 密碼:hh4w
另外,3.0.0.2之后貌似已經提供了編譯好的版本,不過我沒有試,看大小和目錄結構應該是,只是新版本要求JDK 11+,配置和啟動部分名稱都有所調整,需要稍微注意下(kafka-manager改成了cmak)有興趣的可以嘗試下

四、配置
shell> vim /usr/local/CMAK-2.0.0.2/conf/application.conf
編輯kafka-manager.zkhosts
kafka-manager.zkhosts="my.zookeeper.host.com:2181"
如果是集群:
kafka-manager.zkhosts="my.zookeeper.host.com:2181,other.zookeeper.host.com:2181"
五、運行
kafka-manager默認使用9000端口,使用-Dhttp.port指定端口
shell> cp kafka-manager-2.0.0.2.zip /usr/local/
shell> unzip kafka-manager-2.0.0.2.zip
shell> cd /usr/local/kafka-manager-2.0.0.2
shell> bin/kafka-manager -Dconfig.file=conf/application.conf -Dhttp.port=9002
后臺啟動
shell> nohup bin/kafka-manager -Dconfig.file=conf/application.conf -Dhttp.port=9002 >/dev/null 2>&1 &
六、使用
添加Cluster

Cluster ZooKeeper Hosts:zk1:2181,zk2:2181,zk3:2181/NAMESPACE
[圖片上傳中...(image-20200331003523713.png-fef895-1585671317475-0)]

勾選紅框部分,前提是 kafka 啟動時開啟了 JMX_PORT才會生效
shell> cd /usr/local/kafka_2.12-2.2.0
shell> JMX_PORT=9999 bin/kafka-server-start.sh -daemon config/server.properties
查看topic及Consumer




到目前為止,kafka-manager的安裝和基本配置就完成了,更多詳細用法可以參考開源項目:https://github.com/yahoo/CMAK