CentOS安装KafkaManager

1,134 阅读4分钟

一、下载

下载地址:github.com/yahoo/CMAK/…

shell> wget https://codeload.github.com/yahoo/CMAK/tar.gz/2.0.0.2

说明:之前叫Kafka Manager,现在改名叫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、手动安装

下载地址:www.scala-sbt.org/download.ht…

shell> wget https://piccolo.link/sbt-1.3.8.tgz
shell> tar -zxvf sbt-1.3.8.tgz -C /usr/local/

添加环境变量

shell> vim /etc/profile
export PATH=/usr/local/sbt/bin:$PATH
shell> source /etc/profile
3、修改仓库地址(sbt默认下载库很慢,这里添加aliyun仓库,类似使用maven时添加aliyun仓库提高速度)
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:链接:pan.baidu.com/s/1PyRIckLk… 密码:7v8r

2.0.0.0:链接:pan.baidu.com/s/1lYvyrx0e… 密码:7wd9

2.0.0.2:链接:pan.baidu.com/s/1fiQvM1rb… 密码: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

勾选红框部分,前提是 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的安装和基本配置就完成了,更多详细用法可以参考开源项目:github.com/yahoo/CMAK