docker怎么部署kafka

发布时间:2021-10-21 13:34:39 作者:小新
来源:亿速云 阅读:205

小编给大家分享一下docker怎么部署kafka,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

1. 搭建docker

这里我直接用的是docker-compose部署,所以需要提前安装好compose。
既然要用compose那么yml文件自然是少不了的。

首先要新建一个目录,并在目录中新建一个yml文件

docker怎么部署kafka

文件的内容如下:

version: '2'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    volumes:
      - ./data:/data
    ports:
      - "2181:2181"
       
  kafka:
    image: wurstmeister/kafka
    ports:
      - "9092: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:9000
    environment:
      ZK_HOSTS: zookeeper:2181

接着利用这个yml文件启动我们的项目

$ docker-compose up -d

可以看到新建了三个容器

docker怎么部署kafka

2.进入容器

我们通过以下命令进入到kafka容器的交互模式

$ docker exec -it kafkademo01_kafka_1 /bin/bash

因为高版本的kafka内置了zookeeper,所以我们无需进入zookeeper容器。所以yml文件中关于zookeeper的部署是可以省略的。

然后进入kafka的根目录

$ cd /opt/kafka

3.修改配置文件

$ cd /config

docker怎么部署kafka

首先要修改的是zookeeper的配置文件:zookeeper.properties
(注释已删除)

dataDir=/opt/kafka/zooLogs
clientPort=2182
maxClientCnxns=0
admin.enableServer=false

然后修改kafka的配置文件:server.porperties
(注释已删除)

############################# 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=9093

4.测试kafka

以下是一些基本的命令

启动zookeeper

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

启动kafka

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

创建一个主题

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

查看创建的主题

kafka-topics.sh --list --zookeeper 127.0.0.1:2182

生产者

kafka-console-producer.sh --broker-list 127.0.0.1:9093 --topic test

消费者

kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9093 --topic test --from-beginning

以上是“docker怎么部署kafka”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. Kafka原理及Kafka群集部署
  2. kafka集群的部署

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

docker kafka

上一篇:怎么用Python K-means实现简单图像聚类

下一篇:java怎么实现登录验证码功能

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》