在Linux环境下监控管理Kafka的利器:Kafka UI

官网

https://github.com/provectus/kafka-ui https://docs.docker.com/compose/install/other/

实战

Docker

启动Docker

[xuej@localhost ~]$ sudo systemctl start docker

查看Docker状态

[xuej@localhost ~]$ sudo systemctl status docker
 docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2023-04-25 12:12:38 CST; 6s ago
     Docs: https://docs.docker.com
 Main PID: 16002 (dockerd)
    Tasks: 14
   Memory: 148.9M
   CGroup: /system.slice/docker.service
           └─16002 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Apr 25 12:12:37 localhost dockerd[16002]: time="2023-04-25T12:12:37.354302326+08:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/co...module=grpc
Apr 25 12:12:37 localhost dockerd[16002]: time="2023-04-25T12:12:37.354312374+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Apr 25 12:12:37 localhost dockerd[16002]: time="2023-04-25T12:12:37.368045938+08:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
Apr 25 12:12:37 localhost dockerd[16002]: time="2023-04-25T12:12:37.391791960+08:00" level=info msg="Loading containers: start."
Apr 25 12:12:38 localhost dockerd[16002]: time="2023-04-25T12:12:38.225965074+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 17...IP address"
Apr 25 12:12:38 localhost dockerd[16002]: time="2023-04-25T12:12:38.450446739+08:00" level=info msg="Loading containers: done."
Apr 25 12:12:38 localhost dockerd[16002]: time="2023-04-25T12:12:38.485490275+08:00" level=info msg="Docker daemon" commit=633a0ea graphdriver(s)=overlay2 version=19.03.5
Apr 25 12:12:38 localhost dockerd[16002]: time="2023-04-25T12:12:38.485631264+08:00" level=info msg="Daemon has completed initialization"
Apr 25 12:12:38 localhost dockerd[16002]: time="2023-04-25T12:12:38.515322836+08:00" level=info msg="API listen on /var/run/docker.sock"
Apr 25 12:12:38 localhost systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

Kafka UI服务

(体验版)运行方式1:直接启动客户端,然后手动配置Kafka连接

该启动方式,每次登陆Kafka UI后,需要重新手动配置Kafka连接信息。简单玩玩快速体验一下该工具是可以的,日常使用,不推荐此法。

[xuej@localhost ~]$ sudo docker run -it -p 8080:8080  provectuslabs/kafka-ui

(推荐版)运行方式2:本地配置好Kafka连接,运行命令带上本地配置文件

配置文件,案例如下所示:

[xuej@localhost ~]$ vi kui/config.yml
services:
  kafka-ui:
    container_name: kafka-ui
    image: provectuslabs/kafka-ui:latest
    ports:
      - 8080:8080
    environment:
      DYNAMIC_CONFIG_ENABLED: true
      KAFKA_CLUSTERS_0_NAME: Cluster1
      KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: 10.***.***.170:9092,10.***.***.172:9092,10.***.***.171:9092

开启方式1:后台静默运行Kafka UI服务

[xuej@localhost ~]$ sudo docker-compose -f ~/kui/config.yml up -d

开启方式2:后台非静默运行Kafka UI服务

[xuej@localhost ~]$ sudo docker-compose -f ~/kui/config.yml up
[+] Running 1/1
 Container kafka-ui  Started                                                                                                                                          0.4s
Attaching to kafka-ui
kafka-ui  |  _   _ ___    __             _                _          _  __      __ _
kafka-ui  | | | | |_ _|  / _|___ _ _    /_\  _ __ __ _ __| |_  ___  | |/ /__ _ / _| |_____
kafka-ui  | | |_| || |  |  _/ _ | '_|  / _ \| '_ / _` / _| ' \/ -_) | ' </ _` |  _| / / _`|
kafka-ui  |  \___/|___| |_| \___|_|   /_/ \_| .__\__,_\__|_||_\___| |_|\_\__,_|_| |_\_\__,|
kafka-ui  |                                  |_|                                             
kafka-ui  | 
kafka-ui  | 2023-04-25 04:15:24,518 INFO  [background-preinit] o.h.v.i.u.Version: HV000001: Hibernate Validator 6.2.5.Final
kafka-ui  | 2023-04-25 04:15:24,582 INFO  [main] c.p.k.u.u.DynamicConfigOperations: Dynamic config loaded from /etc/kafkaui/dynamic_config.yaml
kafka-ui  | 2023-04-25 04:15:24,598 INFO  [main] c.p.k.u.KafkaUiApplication: Starting KafkaUiApplication using Java 17.0.6 on 6f6a2f6ec915 with PID 1 (/kafka-ui-api.jar started by kafkaui in /)
kafka-ui  | 2023-04-25 04:15:24,604 DEBUG [main] c.p.k.u.KafkaUiApplication: Running with Spring Boot v2.7.5, Spring v5.3.23
kafka-ui  | 2023-04-25 04:15:24,609 INFO  [main] c.p.k.u.KafkaUiApplication: No active profile set, falling back to 1 default profile: "default"
kafka-ui  | 2023-04-25 04:15:28,675 DEBUG [main] c.p.k.u.s.SerdesInitializer: Configuring serdes for cluster Cluster1
kafka-ui  | 2023-04-25 04:15:29,487 INFO  [main] o.s.b.a.s.r.ReactiveUserDetailsServiceAutoConfiguration: 
kafka-ui  | 
kafka-ui  | Using generated security password: b39bbf07-2e28-471d-8106-01d2207e7093
kafka-ui  | 
kafka-ui  | 2023-04-25 04:15:29,637 WARN  [main] c.p.k.u.c.a.DisabledAuthSecurityConfig: Authentication is disabled. Access will be unrestricted.
kafka-ui  | 2023-04-25 04:15:29,969 INFO  [main] o.s.b.a.e.w.EndpointLinksResolver: Exposing 2 endpoint(s) beneath base path '/actuator'
kafka-ui  | 2023-04-25 04:15:30,746 INFO  [main] o.s.b.w.e.n.NettyWebServer: Netty started on port 8080
kafka-ui  | 2023-04-25 04:15:30,782 INFO  [main] c.p.k.u.KafkaUiApplication: Started KafkaUiApplication in 7.556 seconds (JVM running for 8.832)

查看网页

输入localhost:8080进入管理界面

关闭方式1:下线Kafka UI服务

[xuej@localhost ~]$ sudo docker-compose -f ~/kui/config.yml down
[+] Running 2/2
 Container kafka-ui   Removed                                                                                                                                         2.6s
 Network kui_default  Removed                                                                                                                                         0.2s

关闭方式2:停止Kafka UI服务

[xuej@localhost ~]$ sudo docker-compose -f kui/config.yml stop
[+] Running 1/1
 Container kafka-ui  Stopped

结束

Kafka UI是目前开源免费版最好的Kafka工具。