Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does docker deploy kafka

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to deploy docker kafka, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1. Set up docker

I am directly using docker-compose deployment here, so I need to install compose in advance.

Since you want to use compose, then yml files are indispensable.

First, create a new directory and create a new yml file in the directory

The contents of the document are as follows:

Version: '2'services: zookeeper: image: wurstmeister/zookeeper volumes: -. / data:/data ports:-"2181" kafka: image: wurstmeister/kafka ports:-"9092" environment: KAFKA_ADVERTISED_HOST_NAME:127.0.0.1 KAFKA_MESSAGE_MAX_BYTES: 2000000 KAFKA_CREATE_TOPICS: "Topic1:1:3 Topic2:1:1:compact "KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 volumes: -. / kafka-logs:/kafka-/ var/run/docker.sock:/var/run/docker.sock kafka-manager: image: sheepkiller/kafka-manager ports:-9020 kafka-logs:/kafka 9000 environment: ZK_HOSTS: zookeeper:2181

Then use this yml file to start our project.

$docker-compose up-d

You can see that three new containers have been created

two。 Enter the container

We enter the interactive mode of the kafka container with the following command

$docker exec-it kafkademo01_kafka_1 / bin/bash

Because the higher version of kafka has built-in zookeeper, we don't need to enter the zookeeper container. So the deployment of zookeeper in the yml file can be omitted.

Then go to the root directory of kafka

$cd / opt/kafka3. Modify the configuration file $cd / config

The first thing to modify is the configuration file of zookeeper: zookeeper.properties

(comments deleted)

DataDir=/opt/kafka/zooLogsclientPort=2182maxClientCnxns=0admin.enableServer=false

Then modify the configuration file of kafka: server.porperties

(comments deleted)

# # Server Basics # # Broker.id=0 # # Socket Server Settings # # Listeners=PLAINTEXT://127.0.0.1:9093## Socket Server Settings # # listeners=PLAINTEXT://127. 0.0.1:9093 num.network.threads=3 Num.io.threads=8 socket.send.buffer.bytes=102400 Socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 # # Log Basics # # log.dirs=/opt / kafka/kafkaLogs num.partitions=1 Num.recovery.threads.per.data.dir=1 # # Internal Topic Settings # # # offsets.topic.replication.factor=1 Transaction.state.log.replication.factor=1 transaction.state.log.min.isr=1 # # Log Retention Policy # # Log.retention.hours=168 Log.segment.bytes=1073741824 log.retention.check.interval.ms=300000 # # Zookeeper # # Zookeeper.connect=127.0.0.1:2182 zookeeper.connection.timeout.ms=18000 # # Group Coordinator Settings # # group.initial.rebalance.delay.ms=0 Port=9093 Advertised.host.name=127.0.0.1 message.max.bytes=2000000 Advertised.port=90934. Test kafka

Here are some basic commands

Start zookeeper

Zookeeper-server-start.sh.. / config/zookeeper.properties

Start kafka

Kafka-server-start.sh.. / config/server.properties

Create a theme

Kafka-topics.sh-- create-- zookeeper 127.0.0.1 replication-factor 2182-- partitions 1-- topic test

View the theme created

Kafka-topics.sh-- list-- zookeeper 127.0.0.1

Producer

Kafka-console-producer.sh-- broker-list 127.0.0.1-- topic test

Consumer

Kafka-console-consumer.sh-bootstrap-server 127.0.0.1 topic test 9093-topic test-from-beginning are all the contents of this article "how to deploy kafka in docker". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report