Docker installation Kafka tutorial

Docker installation Kafka tutorial

This tutorial will guide you on how to install and run Kafka using Docker.

app-tier: network name
–driver: network type is bridge

docker network create app-tier --driver bridge

1. Install zookeeper

Kafka依赖zookeeper所以先安装zookeeper
-p:设置映射端口(默认2181)
-d:后台启动

docker run -d --name zookeeper-server  --network app-tier  -e ALLOW_ANONYMOUS_LOGIN=yes bitnami/zookeeper:latest

2. Install Kafka

Install and run Kafka,
–name: container name
-p: set mapped port (default 9092)
-d: background start
ALLOW_PLAINTEXT_LISTENER Anyone can access the current host IP or address
of zookeeper KAFKA_ADVERTISED_HOST_NAME linked by KAFKA_CFG_ZOOKEEPER_CONNECT ( key : if it is a server deployment, configure the server IP or domain name, otherwise the client will report an address error when listening to messages) -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.0.101:9092


docker run -d --name kafka-server --network app-tier -p 9092:9092 -e ALLOW_PLAINTEXT_LISTENER=yes -e KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper-server:2181  -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.0.101:9092  bitnami/kafka:latest

3. Kafka-map graphical management tool (easy to use)

图形化管理工具
访问地址:http://服务器IP:9001/
DEFAULT_USERNAME:默认账号admin
DEFAULT_PASSWORD:默认密码admin

Git 地址:https://github.com/dushixiang/kafka-map/blob/master/README-zh_CN.md

docker run -d --name kafka-map --network app-tier  -p 9001:8080   -v /opt/kafka-map/data:/usr/local/kafka-map/data  -e DEFAULT_USERNAME=admin  -e DEFAULT_PASSWORD=admin  --restart always dushixiang/kafka-map:latest

This will start a Kafka console producer where you can enter some messages.

Finally, you can start a Kafka console consumer to receive sent messages. Run the following command in a terminal:

docker exec -it kafka /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

in conclusion

Congratulations! You have successfully installed and run Kafka using Docker. Now you can start using Kafka for messaging and data stream processing.

Note that this tutorial only provides basic installation and testing steps. In an actual production environment, you may need to make more configurations and adjustments to meet your needs. You can refer to Kafka's official documentation for more details and configuration options.

Guess you like

Origin blog.csdn.net/sinat_35773915/article/details/132201099