docker 安装 kafka | ksqlDB

拉取镜像

更多版本请参见 https://hub.docker.com/r/wurstmeister/kafka/tags

docker pull wurstmeister/kafka:1.1.0

启动

docker run -d --restart=always --network host --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kafka -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=10.45.18.235:2181/kafka -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://10.45.18.235:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -v /etc/localtime:/etc/localtime wurstmeister/kafka:1.1.0

参数说明:
-e KAFKA_BROKER_ID=0 在kafka集群中,每个kafka都有一个BROKER_ID来区分自己

-e KAFKA_ZOOKEEPER_CONNECT=192.168.124.28:2181/kafka 配置zookeeper管理kafka的路径10.45.18.235:2181/kafka

-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://10.45.18.235:9092 把kafka的地址端口注册给zookeeper,如果是远程访问要改成外网IP,类如Java程序访问出现无法连接。

-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 配置kafka的监听端口

-v /etc/localtime:/etc/localtime 容器时间同步虚拟机的时间

演示

发送消息

--broker-list 当前 kafka 服务

--topic kafka 主题

docker exec -it kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

发送消息

>1
>2
>3
>4
>5
>6
>7
>8
>9

接收消息

--bootstrap-server 当前 kafka 服务

--topic kafka 主题

--from-beginning 从开始记录

docker exec -it kafka /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server  localhost:9092 --topic test --from-beginning
1
2
3
4
5
6
7
8
9

参考

作者:欧阳俊
链接:https://juejin.cn/post/6960820341631352868
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

安装 ksqlDB

see https://ksqldb.io/quickstart.html#quickstart-content

拉取镜像

docker pull confluentinc/ksqldb-server:0.27.1
docker pull confluentinc/ksqldb-cli:0.27.1

启动 ksqldb-server

docker run -d --restart=always --network host --name ksqldb-server -e KSQL_LISTENERS=http://0.0.0.0:8088  -e KSQL_BOOTSTRAP_SERVERS=10.45.18.235:9092 -e KSQL_KSQL_LOGGING_PROCESSING_STREAM_AUTO_CREATE=true  -e KSQL_KSQL_LOGGING_PROCESSING_TOPIC_AUTO_CREATE=true confluentinc/ksqldb-server:0.27.1

启动 ksqldb-cli

docker run --restart=always --network host --name ksqldb-cli -d  confluentinc/ksqldb-cli:0.27.1 /bin/sh -c "while true; do echo 1; sleep 100000; done;"

使用 ksqldb-cli

docker exec -it ksqldb-cli ksql http://10.45.18.235:8088 
➜  ~ docker exec -it ksqldb-cli ksql http://10.45.18.235:8088                                                                                    
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
                  
                  ===========================================
                  =       _              _ ____  ____       =
                  =      | | _____  __ _| |  _ \| __ )      =
                  =      | |/ / __|/ _` | | | | |  _ \      =
                  =      |   <\__ \ (_| | | |_| | |_) |     =
                  =      |_|\_\___/\__, |_|____/|____/      =
                  =                   |_|                   =
                  =        The Database purpose-built       =
                  =        for stream processing apps       =
                  ===========================================

Copyright 2017-2022 Confluent Inc.

CLI v0.27.1, Server v0.27.1 located at http://10.45.18.235:8088
Server Status: RUNNING

Having trouble? Type 'help' (case-insensitive) for a rundown of how things work!

ksql> 

评论栏